Skip to content

Commit

Permalink
Merge pull request #16 from 2gis/winium-origins
Browse files Browse the repository at this point in the history
Rename solution to Winium. Major code cleanup
  • Loading branch information
skyline-gleb committed Mar 13, 2015
2 parents 3227015 + 50950ea commit 99f56ce
Show file tree
Hide file tree
Showing 125 changed files with 1,440 additions and 469 deletions.
363 changes: 363 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

107 changes: 64 additions & 43 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,50 +1,71 @@
Windows Universal App Driver
============================
# Winium for Store Apps
[![Inner Server NuGet downloads](https://img.shields.io/nuget/dt/Winium.StoreApps.InnerServer.svg?style=flat-square)](https://www.nuget.org/packages/Winium.StoreApps.InnerServer/)
[![Inner Server NuGet version](https://img.shields.io/nuget/v/Winium.StoreApps.InnerServer.svg?style=flat-square)](https://www.nuget.org/packages/Winium.StoreApps.InnerServer/)

Selenium Driver for automated testing of Windows Universal applications.
Winium.StoreApps is an open source, test automation tool for Windows Store apps, tested on emulators (currently only testing of Windows Phone apps is supported).

This repository hosts the code for the Windows Phone driver. You can use it for testing of native Windows Phone 8.1 applications. Currently it implements only limited subset of [WebDriver JSON Wire Protocol](https://code.google.com/p/selenium/wiki/JsonWireProtocol) and supports testing only via an emulator (Windows Phone 8.1).
## Supported Platforms
- Windows Phone 8.1

Driver consists of two parts: the Driver (selenium based) and InnerServer (for application). To run tests you will need to add `WindowsUniversalAppDriver.InnerServer` to the app you want to test and start `WindowsUniversalAppDriver` (Remote WebDriver to send Json Wire Protocol commands to).
For Windows Phone 8 Silverlight test automation tool see [Windows Phone Driver](https://github.com/2gis/winphonedriver).
For Windows Desktop (WPF, WinForms) test automation tool see [Winium Desktop](https://github.com/2gis/cruciatus).

Requirements to run tests using Windows Phone driver
---------------------------------------------------
## Why Winium?
As said by appium:
> - You can write tests with your favorite dev tools using any WebDriver-compatible language such as Java, Objective-C, JavaScript with Node.js (in promise, callback or generator flavors), PHP, Python, Ruby, C#, Clojure, or Perl with the Selenium WebDriver API and language-specific client libraries.
> - You can use any testing framework.
## Requirements
* Windows 8 or higher
* Visual Studio 2013 with Update 2 or higher
* Windows phone 8.1 SDK
* You will also need Visual Studio 2013 with Update 2 or higher to build driver.

Usage
-----
1. Build solution
2. In tested app project, add reference to `WindowsUniversalAppDriver.InnerServer` (from https://www.nuget.org/packages/WindowsUniversalAppDriver.InnerServer)
3. In your app’s source code locate place where `RootFrame` is set (usually in `PrepareApplication` if you use `Caliburn.Micro` or App.xaml.cs for vanilla app) and add

```cs
AutomationServer.Instance.InitializeAndStart(RootFrame);
```

or (will include driver only for debug build)

```cs
#if DEBUG
AutomationServer.Instance.InitializeAndStart(RootFrame);
#endif // DEBUG
```

where `RootFrame` is visual root of application.

4. Write your tests using you favorite language. In your test use `app` desired capability to set path to tested app's appx file (python example).
```python
...
self.driver = webdriver.Remote(
command_executor = 'http://localhost:9999',
desired_capabilities={
"app": r"C:\testApp.appx"
})
...
# find all Textblock elements
blocks= self.driver.find_elements_by_tag_name("System.Windows.Controls.TextBlock")
```
5. Start WindowsUniversalAppDriver.exe
6. Run your tests

You can get Visual Studio and SDK form Microsoft [here](https://dev.windows.com/en-us/develop/download-phone-sdk).

## Quick Start
**App under test (AUT)** is application that you would like to test.

1. Add reference to `Winium.StoreApps.InnerServer` in AUT project ([install NuGet package](https://www.nuget.org/packages/Winium.StoreApps.InnerServer/) or build project yourself)

2. In your AUT's source code locate place where `Frame` is set (usually in `MainPageOnLoaded` for vanilla app or `PrepareApplication` if you use `Caliburn.Micro`) add

```cs
AutomationServer.Instance.InitializeAndStart(Frame);
```

or (will include driver only for debug build)

```cs
#if DEBUG
AutomationServer.Instance.InitializeAndStart(Frame);
#endif // DEBUG
```

where `Frame` is visual root of application.

3. Write your tests using you favorite language. In your tests use `app` [desired capability](https://github.com/2gis/Winium.StoreApps/wiki/Capabilities) to set path to tested app's appx file. Here is python example:
```python
# put it in setUp
self.driver = webdriver.Remote(command_executor='http://localhost:9999',
desired_capabilities={'app': 'C:\\testApp.appx'})
# ut it in test method body
element = self.driver.find_element_by_id('SetButton')
element.click()
assert 'CARAMBA' == self.driver.find_element_by_id('MyTextBox').text
```

4. Start `Winium.StoreApps.Driver.exe` ([download release from github](https://github.com/2gis/Winium.StoreApps/releases) or build it yourself)

5. Run your tests and watch the magic happening

## Writing tests
Essentially, Winium.StoreApps supports limited subset of [WebDriver JSON Wire Protocol](https://code.google.com/p/selenium/wiki/JsonWireProtocol), which means that you can write tests just like you would write for Selenium or Appium, here are some [docs](http://docs.seleniumhq.org/docs/03_webdriver.jsp).
For test samples look at [our functional tests](https://github.com/2gis/Winium.StoreApps/tree/master/Winium/TestApp.Test/py-functional).


## How it works
Winium.StoreApps consists of two essential parts:

1. **Winium.StoreApps.Driver** implements Selenium Remote WebDriver and listens for JsonWireProtocol commands. It is responsible for launching emulator, deploying AUT, simulating input, forwarding commands to `Winium.StoreApps.InnerServer`, etc.

2. **Winium.StoreApps.InnerServer** (the one that should be embedded into AUT) communicates with `Winium.StoreApps.Driver.exe` and executes different commands, like finding elements, getting or setting text values, properties, etc., inside your application.
5 changes: 0 additions & 5 deletions WindowsUniversalAppDriver/NugetPublish.bat

This file was deleted.

19 changes: 0 additions & 19 deletions WindowsUniversalAppDriver/TestApp.Test/py-functional/README.md

This file was deleted.

This file was deleted.

This file was deleted.

File renamed without changes.
File renamed without changes.
5 changes: 5 additions & 0 deletions Winium/NugetPublish.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
REM delete existing nuget packages
del *.nupkg
set NUGET=.\.nuget\nuget.exe
%NUGET% pack .\Winium.StoreApps.InnerServer\Winium.StoreApps.InnerServer.csproj -IncludeReferencedProjects -Prop Configuration=Release
%NUGET% push *.nupkg
File renamed without changes.
8 changes: 8 additions & 0 deletions Winium/TestApp.Test/py-functional/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Functional tests for Windows Universal App Driver
Functional tests for Windows Universal App Driver written in python.

## Usage

1. Build Windows Universal App Driver solution.
2. Make store package from TestApp.
3. Run tests `run_tests.bat`
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import os

BASE_DIR = os.path.dirname(os.path.dirname(__file__))
APPX_PATH = '..\\TestApp/TestApp.WindowsPhone\\AppPackages\\TestApp.WindowsPhone_1.0.0.0_AnyCPU_Debug_Test\\' \
APPX_PATH = '..\\TestApp\\TestApp.WindowsPhone\\AppPackages\\TestApp.WindowsPhone_1.0.0.0_AnyCPU_Debug_Test\\' \
'TestApp.WindowsPhone_1.0.0.0_AnyCPU_Debug.appx'

DESIRED_CAPABILITIES = {
Expand Down
8 changes: 8 additions & 0 deletions Winium/TestApp.Test/py-functional/run_tests.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
REM Run Winium.StoreApps.Driver.exe
start ..\..\Winium.StoreApps.Driver\bin\Debug\Winium.StoreApps.Driver.exe

REM Run tests
pip install -r requirements.txt
py.test tests --tb=native -s

taskkill /im Winium.StoreApps.Driver.exe /f
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace TestApp
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation;

using WindowsUniversalAppDriver.InnerServer;
using Winium.StoreApps.InnerServer;

/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@
</PropertyGroup>
<ItemGroup>
<!-- A reference to the entire .Net Framework and Windows SDK are automatically included -->
<ProjectReference Include="..\..\WindowsUniversalAppDriver.InnerServer\WindowsUniversalAppDriver.InnerServer.csproj">
<ProjectReference Include="..\..\Winium.StoreApps.InnerServer\Winium.StoreApps.InnerServer.csproj">
<Project>{e8683025-e703-4293-aa7e-3a9a3555bc40}</Project>
<Name>WindowsUniversalAppDriver.InnerServer</Name>
<Name>Winium.StoreApps.InnerServer</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace WindowsUniversalAppDriver.Common
namespace Winium.StoreApps.Common
{
#region

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace WindowsUniversalAppDriver.Common
namespace Winium.StoreApps.Common
{
public class CommandInfo
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace WindowsUniversalAppDriver.Common
namespace Winium.StoreApps.Common
{
#region

Expand All @@ -8,18 +8,26 @@

public class CommandResponse
{
public HttpStatusCode HttpStatusCode { get; set; }
#region Public Properties

public string Content { get; set; }

public HttpStatusCode HttpStatusCode { get; set; }

#endregion

#region Public Methods and Operators

public static CommandResponse Create(HttpStatusCode code, string content)
{
return new CommandResponse { HttpStatusCode = code, Content = content };
}

public override string ToString()
{
return string.Format("{0}: {1}", this.HttpStatusCode, Content);
return string.Format("{0}: {1}", this.HttpStatusCode, this.Content);
}

#endregion
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copied from OpenQA
namespace WindowsUniversalAppDriver.Common
namespace Winium.StoreApps.Common
{
/// <summary>
/// Values describing the list of commands understood by a remote server using the JSON wire protocol.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace WindowsUniversalAppDriver.Common.Exceptions
namespace Winium.StoreApps.Common.Exceptions
{
#region

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
namespace WindowsUniversalAppDriver.Common.Exceptions
namespace Winium.StoreApps.Common.Exceptions
{
#region

using System;
using System.Net;

#endregion

public class InnerDriverRequestException : Exception
{
#region Constructors and Destructors
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
namespace WindowsUniversalAppDriver.Common
namespace Winium.StoreApps.Common
{
#region

using System.Collections.Generic;
using System.Net;
using System.Text;

#endregion

public static class HttpResponseHelper
{
#region Constants
Expand Down Expand Up @@ -42,6 +46,11 @@ public static Dictionary<HttpStatusCode, string> StatusCodeDescriptors

#region Public Methods and Operators

public static bool IsClientError(int code)
{
return code >= 400 && code < 500;
}

public static string ResponseString(HttpStatusCode statusCode, string content)
{
var contentType = IsClientError((int)statusCode) ? PlainTextContentType : JsonContentType;
Expand All @@ -59,11 +68,6 @@ public static string ResponseString(HttpStatusCode statusCode, string content)
return responseString.ToString();
}

public static bool IsClientError(int code)
{
return code >= 400 && code < 500;
}

#endregion
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
// <auto-generated />
namespace WindowsUniversalAppDriver.Common
namespace Winium.StoreApps.Common
{
using System.Collections.Generic;
#region

using Newtonsoft.Json;

#endregion

public class JsonWebElementContent
{
#region Constructors and Destructors
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
using System.Resources;
#region

using System.Reflection;
using System.Resources;

#endregion

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("WindowsUniversalAppDriver.Common")]
[assembly: AssemblyTitle("Winium.StoreApps.Common")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("WindowsUniversalAppDriver.Common")]
[assembly: AssemblyProduct("Winium.StoreApps.Common")]
[assembly: AssemblyCopyright("Copyright © 2015")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: NeutralResourcesLanguage("en")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.1.*")]
[assembly: AssemblyVersion("1.0.*")]
Loading

0 comments on commit 99f56ce

Please sign in to comment.