TestObject , an offering by Sauce Labs provides cloud testing service with real devices.
I recently did a POC with TestObject using C# . The tests were run using NUnit.
Step 1: Sign up
Sign up for a free TestObject account
Step 2: Upload app
Upload the .apk/.ipa file for app under test . I used a free basic notepad Android app
Step 3: Understand which capabilities need to be set
TestObject have a decent amount of documentation on their website.
There is a Java based example here, that I translated to C# . This example calls out a set a typical capabilities required to call an actual device on the TestObject cloud
Here is the my code :
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
capabilities.SetCapability("testobject_api_key", "48702A635B794A6FB8D5B852FE62723A"); | |
capabilities.SetCapability("platformName","Android"); | |
capabilities.SetCapability("platformVersion","6.0"); | |
capabilities.SetCapability("appiumVersion", "1.7.2"); | |
capabilities.SetCapability("deviceName", "Motorola_Moto_E_2nd_gen_free"); | |
capabilities.SetCapability("privateDevicesOnly", "false"); | |
capabilities.SetCapability("testobject_app_id", "1"); | |
capabilities.SetCapability("phoneOnly", "false"); | |
capabilities.SetCapability("tabletOnly", "false"); | |
Uri server = new Uri("https://eu1.appium.testobject.com/wd/hub"); |
You will find the API key and details of the capabilities , by clicking the gears icon (under your TestOBject account) –> selecting Appium —> Set up instructions page
The device details will be in the device list under the “Live Testing”link –
Lastly , the app id can be retrieved from the “Dashboard”link in TestObject
Step 4: Next is to write some NUnit tests to control the app in TestObject
I used this tutorial for guidance ( as I am a novice with NUnit and C# 🙂 )
Wrote couple of simple tests to valid the context of the app and title of the new note window in my sample Notepad application
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using NUnit.Framework; | |
using System; | |
using OpenQA.Selenium.Appium.Android; | |
using OpenQA.Selenium.Remote; | |
using OpenQA.Selenium.Appium; | |
using System.Net; | |
using OpenQA.Selenium; | |
using System.Drawing.Imaging; | |
using System.Threading; | |
namespace AppiumBasicSetup | |
{ | |
[TestFixture()] | |
public class BasicTest | |
{ | |
AndroidDriver<AppiumWebElement> driver; | |
//AndroidDriver<IWebElement> driver; | |
[SetUp()] | |
public void SetUp() | |
{ | |
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls; | |
Console.Write("Setting up the test"); | |
DesiredCapabilities capabilities = new DesiredCapabilities(); | |
capabilities.SetCapability("testobject_api_key", "xxxxxxxxxxxx"); | |
capabilities.SetCapability("platformName","Android"); | |
capabilities.SetCapability("platformVersion","6.0"); | |
capabilities.SetCapability("appiumVersion", "1.7.2"); | |
capabilities.SetCapability("deviceName", "Motorola_Moto_E_2nd_gen_free"); | |
capabilities.SetCapability("privateDevicesOnly", "false"); | |
capabilities.SetCapability("testobject_app_id", "1"); | |
capabilities.SetCapability("phoneOnly", "false"); | |
capabilities.SetCapability("tabletOnly", "false"); | |
Uri server = new Uri("https://eu1.appium.testobject.com/wd/hub"); | |
TimeSpan time_out = TimeSpan.FromMinutes(2); | |
driver = new AndroidDriver<AppiumWebElement>(server, capabilities,time_out); | |
driver.Manage().Timeouts().ImplicitlyWait(time_out); | |
} | |
[Test()] | |
public void App_should_have_context_Test() | |
{ | |
Assert.IsNotNull(driver.Context); | |
} | |
public AppiumWebElement Create_a_NewNote() | |
{ | |
AppiumWebElement new_note = driver.FindElementByAccessibilityId("New note"); | |
new_note.Tap(1,1); | |
AppiumWebElement new_note_screen = driver.FindElementById("android:id/action_bar_title"); | |
return new_note_screen; | |
} | |
[Test()] | |
public void Verify_Title_of_NewNote_Test() | |
{ | |
AppiumWebElement new_note_screen1 = Create_a_NewNote(); | |
String new_note_title = new_note_screen1.Text; | |
driver.GetScreenshot(); | |
Assert.AreEqual(new_note_title, "New note1"); | |
} | |
[TearDown()] | |
public void TearDown() | |
{ | |
driver.Quit(); | |
Console.Write("Tearing down the test"); | |
} | |
} | |
} |
Step 5: Running the tests in Visual Studio and checking results in TestObject
Kick off the NUnit test in Visual studio and then head over to your TestObject account , click on the gears icon and you would see activity under the list of Appium tests ( hopefully) to reflect your test running
Clicking on the test run link , you can view the Appium logs, Device logs, any screen shots taken and a nice video recording .
The usual Sauce Labs stuff , but on an actual device 🙂
Happy testing !
Leave a Reply