Execute Tests in SauceLabs

Learn to use BELLATRIX to execute Android tests in SauceLabs.

Example

[TestFixture]
[AndroidSauceLabs("sauce-storage:ApiDemos.apk",
    "7.1",
    "Android GoogleAPI Emulator",
    Constants.AndroidNativeAppAppExamplePackage,
    ".view.ControlsMaterialDark",
    Lifecycle.RestartEveryTime)]
public class SauceLabsTests : AndroidTest
{
    [Test]
    public void ButtonClicked_When_CallClickMethod()
    {
        var button = App.Components.CreateByIdContaining<Button>("button");

        button.Click();
    }

    [Test]
    [AndroidSauceLabs("sauce-storage:ApiDemos.apk",
        "7.1",
        "Android GoogleAPI Emulator",
        Constants.AndroidNativeAppAppExamplePackage,
        ".view.ControlsMaterialDark",
        Lifecycle.ReuseIfStarted)]
    public void ButtonClicked_When_CallClickMethodSecond()
    {
        var button = App.Components.CreateByIdContaining<Button>("button");

        button.Click();
    }
}

Explanations

[AndroidSauceLabs("sauce-storage:ApiDemos.apk",
    "7.1",
    "Android GoogleAPI Emulator",
    Constants.AndroidNativeAppAppExamplePackage,
    ".view.ControlsMaterialDark",
    Lifecycle.RestartEveryTime)]

To execute BELLATRIX tests in SauceLabs cloud you should use the AndroidSauceLabs attribute instead of Android. SauceLabs has the same parameters as Android but adds to additional ones- device name, recordVideo and recordScreenshots. As with the Android attribute you can override the class behavior on Test level.

[Test]
[AndroidSauceLabs("sauce-storage:ApiDemos.apk",
    "7.1",
    "Android GoogleAPI Emulator",
    Constants.AndroidNativeAppAppExamplePackage,
    ".view.ControlsMaterialDark",
    Lifecycle.ReuseIfStarted)]
[Ignore]
public void ButtonClicked_When_CallClickMethodSecond()
{
    var button = App.Components.CreateByIdContaining<Button>("button");

    button.Click();
}

As mentioned if you use the SauceLabs attribute on method level it overrides the class settings.

Configuration

If you don’t use the attribute, the default information from the configuration will be used placed under the executionSettings section. Also, you can add additional driver arguments under the arguments section array in the configuration file.

"executionSettings": {
  "defaultLifeCycle": "restart everytime",
  "shouldStartLocalService": "false",
  "url": "http://127.0.0.1:4722/wd/hub",
  "arguments": [
    {
      "deviceOrientation": "portrait",
      "deviceName": "Nexus 1",
      "app": "AssemblyFolder\\Demos\\ApiDemos.apk",
      "appWaitActivity": "*",
      "appPackage": "com.example.android.apis",
      "appActivity": ".view.Controls1"
      "name": "{runName}",
      "platform": "Android",
      "version": "7.1",
      "recordVideo": "true",
      "recordScreenshots": "true",
      "username": "yourUserName",
      "accessKey": "accessKey"
    }
  ]
}