forked from saucelabs-training/demo-java
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIOSWebAppExample.java
72 lines (61 loc) · 2.35 KB
/
IOSWebAppExample.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package com.emusim;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestName;
import org.openqa.selenium.By;
import org.openqa.selenium.MutableCapabilities;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.RemoteWebDriver;
import java.net.MalformedURLException;
import java.net.URL;
import static org.junit.Assert.assertTrue;
public class IOSWebAppExample {
@Rule
public TestName name = new TestName() {
public String getMethodName() {
return String.format("%s", super.getMethodName());
}
};
private WebDriver driver;
public WebDriver getDriver() {
return driver;
}
@Before
public void setUp() throws MalformedURLException {
MutableCapabilities capabilities = new MutableCapabilities();
capabilities.setCapability("appiumVersion", "1.17.1");
capabilities.setCapability("platformName", "iOS");
capabilities.setCapability("platformVersion", "13.2");
capabilities.setCapability("deviceName", "iPhone XS Max Simulator");
capabilities.setCapability("browserName", "Safari");
capabilities.setCapability("name", name.getMethodName());
capabilities.setCapability("idleTimeout", "90");
capabilities.setCapability("newCommandTimeout", "90");
driver = new RemoteWebDriver(
new URL("https://" + System.getenv("SAUCE_USERNAME") + ":" +
System.getenv("SAUCE_ACCESS_KEY") +
"@ondemand.saucelabs.com:443" + "/wd/hub"),
capabilities);
}
@After
public void tearDown() {
if (getDriver() != null) {
getDriver().quit();
}
}
@Test
public void shouldLoadWebsite() {
getDriver().navigate().to("https://www.saucedemo.com");
assertTrue(getDriver().findElement(By.id("user-name")).isDisplayed());
}
@Test
public void shouldLogin() {
getDriver().navigate().to("https://www.saucedemo.com");
getDriver().findElement(By.id("user-name")).sendKeys("standard_user");
getDriver().findElement(By.id("password")).sendKeys("secret_sauce");
getDriver().findElement(By.id("login-button")).click();
assertTrue(getDriver().findElement(By.id("inventory_filter_container")).isDisplayed());
}
}