1+ import com .saucelabs .common .SauceOnDemandAuthentication ;
2+ import com .saucelabs .common .SauceOnDemandSessionIdProvider ;
3+ import com .saucelabs .junit .SauceOnDemandTestWatcher ;
4+ import io .appium .java_client .MobileElement ;
5+ import io .appium .java_client .ios .IOSDriver ;
6+ import io .appium .java_client .remote .MobileCapabilityType ;
7+ import junit .framework .TestCase ;
8+ import org .junit .After ;
9+ import org .junit .Before ;
10+ import org .junit .Rule ;
11+ import org .junit .Test ;
12+ import org .junit .rules .TestName ;
13+ import org .openqa .selenium .remote .DesiredCapabilities ;
14+
15+ import java .net .MalformedURLException ;
16+ import java .net .URL ;
17+ import java .util .concurrent .TimeUnit ;
18+
19+ import static junit .framework .Assert .assertEquals ;
20+ import static junit .framework .TestCase .assertTrue ;
21+
22+ public class SimpleIOSSauceTests implements SauceOnDemandSessionIdProvider {
23+ final private String USERNAME = System .getenv ("SAUCE_USERNAME" );
24+ final private String ACCESS_KEY = System .getenv ("SAUCE_ACCESS_KEY" );
25+ private SauceOnDemandAuthentication authentication = new SauceOnDemandAuthentication (USERNAME , ACCESS_KEY );
26+
27+ private IOSDriver driver ;
28+ private String sessionId ;
29+
30+ @ Rule
31+ public SauceOnDemandTestWatcher resultReportingTestWatcher = new SauceOnDemandTestWatcher (this , authentication );
32+ @ Override
33+ public String getSessionId () {
34+ return sessionId ;
35+ }
36+
37+ public @ Rule TestName name = new TestName ();
38+
39+ @ Before
40+ public void setUp () throws MalformedURLException {
41+ DesiredCapabilities desiredCapabilities = new DesiredCapabilities ();
42+ desiredCapabilities .setCapability (MobileCapabilityType .PLATFORM_VERSION , "7.1" );
43+ desiredCapabilities .setCapability (MobileCapabilityType .DEVICE_NAME , "iPhone Simulator" );
44+ desiredCapabilities .setCapability (MobileCapabilityType .APP , "http://appium.s3.amazonaws.com/TestApp6.0.app.zip" );
45+ desiredCapabilities .setCapability ("appiumVersion" , "1.3.4" );
46+ desiredCapabilities .setCapability ("name" , name .getMethodName ());
47+
48+ URL sauceUrl = new URL ("http://" + authentication .getUsername () + ":" + authentication .getAccessKey () + "@ondemand.saucelabs.com:80/wd/hub" );
49+
50+ driver = new IOSDriver (sauceUrl , desiredCapabilities );
51+ driver .manage ().timeouts ().implicitlyWait (30 , TimeUnit .SECONDS );
52+ sessionId = driver .getSessionId ().toString ();
53+ }
54+
55+ @ After
56+ public void tearDown () {
57+ System .out .println ("Link to your job: https://saucelabs.com/jobs/" + this .getSessionId ());
58+ driver .quit ();
59+ }
60+
61+ @ Test
62+ public void testUIComputation () {
63+
64+ // populate text fields with values
65+ MobileElement fieldOne = (MobileElement ) driver .findElementByAccessibilityId ("TextField1" );
66+ fieldOne .sendKeys ("12" );
67+
68+ MobileElement fieldTwo = (MobileElement ) driver .findElementsByClassName ("UIATextField" ).get (1 );
69+ fieldTwo .sendKeys ("8" );
70+
71+ // they should be the same size, and the first should be above the second
72+ assertTrue (fieldOne .getLocation ().getY () < fieldTwo .getLocation ().getY ());
73+ assertEquals (fieldOne .getSize (), fieldTwo .getSize ());
74+
75+ // trigger computation by using the button
76+ driver .findElementByAccessibilityId ("ComputeSumButton" ).click ();
77+
78+ // is sum equal?
79+ String sum = driver .findElementsByClassName ("UIAStaticText" ).get (0 ).getText ();
80+ TestCase .assertEquals (Integer .parseInt (sum ), 20 );
81+ }
82+
83+ }
0 commit comments