SHARE
TWEET

Testdroid C# Appium sample with Session id print included

lasseh Oct 7th, 2015 (edited) 209 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using NUnit.Framework;
  2. using System;
  3. using System.Drawing.Imaging;
  4. using OpenQA.Selenium.Appium;
  5. using OpenQA.Selenium.Remote;
  6. using System.Collections.Generic;
  7. using OpenQA.Selenium;
  8. using OpenQA.Selenium.Appium.Android;
  9.  
  10. namespace TestdroidAndroidSample
  11. {
  12.         public class CustomRemoteDriver : RemoteWebDriver  
  13.         {  
  14.                 public CustomRemoteDriver(Uri remoteAddress, ICapabilities desiredCapabilities)  
  15.                         : base(remoteAddress, desiredCapabilities, TimeSpan.FromSeconds(400))  
  16.                 {  
  17.                 }  
  18.  
  19.                 public String getSessionId()  
  20.                 {  
  21.                         return this.SessionId.ToString();  
  22.                 }  
  23.         }
  24.  
  25.         [TestFixture ()]
  26.         public class Tests
  27.         {
  28.                 CustomRemoteDriver driver;
  29.                 //AppiumDriver<AndroidElement> driver;
  30.                 // Make sure that the SCREENSHOT_FOLDER exists already.
  31.                 String SCREENSHOT_FOLDER = "";
  32.  
  33.                 [TestFixtureSetUp]
  34.                 public void BeforeAll()
  35.                 {
  36.  
  37.                         String TESTDROID_USERNAME = "";
  38.                         String TESTDROID_PASSWORD = "";
  39.  
  40.                         DesiredCapabilities capabilities = new DesiredCapabilities();
  41.                         capabilities.SetCapability("device", "Android");
  42.  
  43.                         capabilities.SetCapability("deviceName", "Android");
  44.                         capabilities.SetCapability("platformName", "Android");
  45.  
  46.  
  47.                         capabilities.SetCapability("testdroid_username", TESTDROID_USERNAME);
  48.                         capabilities.SetCapability("testdroid_password", TESTDROID_PASSWORD);
  49.                         capabilities.SetCapability("testdroid_target", "Android");
  50.                         capabilities.SetCapability("testdroid_project", "C# Appium");
  51.                         capabilities.SetCapability("testdroid_testrun", "Android Run 1");
  52.                         capabilities.SetCapability("testdroid_junitWaitTime", 120);
  53.  
  54.                         // See available devices at: https://cloud.testdroid.com/#public/devices
  55.                         capabilities.SetCapability("testdroid_device", "Dell Venue 7 3730"); // Freemium device
  56.                         capabilities.SetCapability("testdroid_app", "sample/BitbarSampleApp.apk"); //to use existing app using "latest" as fileUUID
  57.                         Console.WriteLine ("WebDriver request initiated. Waiting for response, this typically takes 2-3 mins");
  58.                         driver = new CustomRemoteDriver(new Uri("http://appium.testdroid.com/wd/hub"), capabilities);
  59.                         Console.WriteLine ("WebDriver response received.");
  60.  
  61.  
  62.                 }
  63.  
  64.                 [TestFixtureTearDown]
  65.                 public void AfterAll()
  66.                 {
  67.                         driver.Quit();
  68.                 }
  69.  
  70.  
  71.                 [Test ()]
  72.                 public void TestSampleApp()
  73.                 {
  74.                         driver.Manage ().Timeouts ().ImplicitlyWait (TimeSpan.FromSeconds(60));
  75.                         Console.WriteLine (driver.getSessionId());
  76.                         TakeScreenshot ("First");
  77.                         driver.FindElement(By.XPath("//android.widget.RadioButton[@text='Use Testdroid Cloud']")).Click();
  78.                         driver.FindElement(By.XPath("//android.widget.EditText[@resource-id='com.bitbar.testdroid:id/editText1']")).SendKeys("C Sharp");
  79.                         TakeScreenshot ("Second");
  80.                         driver.Navigate().Back ();
  81.                         TakeScreenshot ("Third");
  82.                         driver.FindElement(By.XPath("//android.widget.ScrollView[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout[2]/android.widget.Button[1]")).Click();
  83.                         TakeScreenshot ("Fourth");
  84.                 }
  85.  
  86.                 public void TakeScreenshot(String filename)
  87.                 {
  88.                         Screenshot ss = ((ITakesScreenshot)driver).GetScreenshot();
  89.                         String path = SCREENSHOT_FOLDER + filename + ".png";
  90.                         Console.WriteLine ("Taking screenshot: " + path);
  91.                         ss.SaveAsFile(path, ImageFormat.Png);
  92.                 }
  93.         }
  94. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top