Testura.Android is a lightweight test automation framework for Android built in C#. It contains tools and help classes to test, validate and interact with your Android device or emulator.
- Quick and easy to set up
- Designed to be used with the page object pattern
- Designed to be flexible so you can change the behavior of individual services and/or extend the UI dump functionallity.
- Interact with multiple objects at the same time
- Add custom extensions to handle pop-ups, error dialogs, loading bars, etc without any overhead.
- Help tools to create your page objects (seperate project)
- Android adb.exe (download SDK platform-tools) (also recommended to add adb to environment variables)
https://www.nuget.org/packages/Testura.Android
PM> Install-Package Testura.Android
https://www.nuget.org/packages/Testura.Android.PageObject
PM> Install-Package Testura.Android.PageObject
How to create a test automation project with testura - Youtube
Testura.Android has been designed for the page object pattern. Here is a short example of a login view:
using Testura.Android.Device;
using Testura.Android.Device.Configurations;
using Testura.Android.Device.Ui.Objects;
using Testura.Android.Device.Ui.Search;
namespace Testura.Android.Tests.Device
{
public class ExampleView
{
private IAndroidDevice _androidDevice;
private readonly UiObject _usernameTextbox;
private readonly UiObject _passwordTextbox;
private readonly UiObject _logInButton;
public ExampleView()
{
_androidDevice = new AndroidDevice();
// The device won't look for the node/UI object before we interact with it,
// so it's perfectly safe to set up everything inside the constructor.
_usernameTextbox = _androidDevice.Ui.CreateUiObject(With.ResourceId("usernameTextbox"));
_passwordTextbox = _androidDevice.Ui.CreateUiObject(With.ContentDesc("passwordTextbox"));
_logInButton = _androidDevice.Ui.CreateUiObject(With.Lambda(n => n.Text == "Login"));
}
public void Login(string username, string password)
{
_usernameTextbox.InputText(username);
_passwordTextbox.InputText(password);
_logInButton.Tap();
}
}
}
In the example we can see how we map different nodes on the screen to "UI objects". We can then interact with the nodes through the mapped UI object.
It it also possible to create objects through attributes (required the PageObject package):
using Testura.Android.Device;
using Testura.Android.Device.Ui.Objects;
using Testura.Android.PageObject;
using Testura.Android.PageObject.Attributes;
using Testura.Android.Util;
namespace Testura.Android.Tests.Device
{
public class ExampleView : View
{
[Create(with: AttributeTags.ResourceId, value: "usernameTextbox")]
private readonly UiObject _usernameTextbox;
[Create(with: AttributeTags.ContentDesc, value: "passwordTextbox")]
private readonly UiObject _passwordTextbox;
[Create(with: AttributeTags.Text, value: "Login")]
private readonly UiObject _logInButton;
public ExampleView(IAndroidDevice device)
: base(device)
{
}
public void Login(string username, string password)
{
_usernameTextbox.InputText(username);
_passwordTextbox.InputText(password);
_logInButton.Tap();
}
}
}
If you have used Selenium, Appium or any other big test automation framework I'm sure you are familiar with the By
keyword. Testura.Android has something similiar called With
.
When mapping up a new UI object, you first have to decide how to find it, using one or more With
:
With.Text
- Find nodes that match the exact textWith.ContainsText
- Find nodes that contain just a part of the textWith.ResourceId
- Find nodes that contains the exact resource IDWith.ContentDesc
- Find nodes that contains the exact content descriptionWith.Class
- Find nodes that contains the exact classWith.Index
- Find nodes that have this indexWith.Package
- Find nodes that contains the exact packageWith.Lamba
- Find nodes with a lamba expression
With.Lamba
is a powerful method to find nodes and you can access both the node's parent and children:
With.Lambda(n =>
n.Text == "Some text"
&& n.Parent != null
&& n.Children.First().ContentDesc == "My child");
The Android device class consists of multiple "services" that handle different parts of the device:
- ADB service - Send shell commands, push and pull files, install APKs etc.
- UI service - Look for nodes or map UI objects (handles screen dumping)
- Settings service - Enable/disable different settings, for example wifi and airplane mode
- Activity service - Start activity or get the name of the current one
- Interaction service - Handle interaction with the device, for example swipe and click
All services are accessible from the device class like this:
var device = new AndroidDevice();
device.Adb.Shell("my shell commando");
device.Settings.Wifi(State.Enable);
UiObject
is one of the core components of Testura.Android. It wraps a node with all the necessary functions:
var device = new AndroidDevice();
var uiObject = device.Ui.CreateUiObject(With.ContentDesc(".."));
uiObject.Tap();
uiObject.IsVisible();
uiObject.IsHidden();
uiObject.InputText("..");
uiObject.WaitForValue(n => n.Enabled);
var node = uiObject.Values();
For more information about page object helpers, visit the wiki: https://github.com/Testura/Testura.Android/wiki/Page-Object
We also have a help tool to generate page objects: https://github.com/Testura/Testura.Android.PageObjectCreator
- Wiki - https://github.com/Testura/Testura.Android/wiki
- API https://testura.github.io/Android/api/index.html
This project is licensed under the MIT License. See the LICENSE.md file for details.
Visit www.testura.net, twitter at @testuranet or email at mille.bostrom@testura.net