mirror of
https://github.com/appium/appium.git
synced 2026-10-28 20:31:51 +08:00
updating java-client sample code
This commit is contained in:
@@ -7,7 +7,7 @@ In order to run the tests, you will need to install [Apache Maven](http://maven.
|
||||
|
||||
You will then need to start appium, eg:
|
||||
|
||||
grunt appium
|
||||
appium
|
||||
|
||||
To compile and run all tests, run:
|
||||
|
||||
@@ -15,4 +15,4 @@ To compile and run all tests, run:
|
||||
|
||||
To run a single test, run:
|
||||
|
||||
mvn -Dtest=com.saucelabs.appium.SimpleTest test
|
||||
mvn -Dtest=com.saucelabs.appium.SimpleTest test
|
||||
|
||||
@@ -20,6 +20,11 @@
|
||||
<version>LATEST</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.appium</groupId>
|
||||
<artifactId>java-client</artifactId>
|
||||
<version>1.0.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.googlecode.json-simple</groupId>
|
||||
<artifactId>json-simple</artifactId>
|
||||
|
||||
+10
-23
@@ -1,21 +1,20 @@
|
||||
package com.saucelabs.appium;
|
||||
|
||||
import io.appium.java_client.AppiumDriver;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.openqa.selenium.*;
|
||||
import org.openqa.selenium.interactions.HasTouchScreen;
|
||||
import org.openqa.selenium.interactions.TouchScreen;
|
||||
import org.openqa.selenium.By;
|
||||
import org.openqa.selenium.WebElement;
|
||||
import org.openqa.selenium.remote.CapabilityType;
|
||||
import org.openqa.selenium.remote.DesiredCapabilities;
|
||||
import org.openqa.selenium.remote.RemoteTouchScreen;
|
||||
import org.openqa.selenium.remote.RemoteWebDriver;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
import java.util.List;
|
||||
|
||||
public class AndroidContactsTest {
|
||||
private WebDriver driver;
|
||||
private AppiumDriver driver;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
@@ -26,12 +25,11 @@ public class AndroidContactsTest {
|
||||
DesiredCapabilities capabilities = new DesiredCapabilities();
|
||||
capabilities.setCapability("device","Android");
|
||||
capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
|
||||
capabilities.setCapability(CapabilityType.VERSION, "4.2");
|
||||
capabilities.setCapability(CapabilityType.PLATFORM, "MAC");
|
||||
capabilities.setCapability(CapabilityType.VERSION, "4.4");
|
||||
capabilities.setCapability("app", app.getAbsolutePath());
|
||||
capabilities.setCapability("app-package", "com.example.android.contactmanager");
|
||||
capabilities.setCapability("app-activity", ".ContactManager");
|
||||
driver = new SwipeableWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
|
||||
driver = new AppiumDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
|
||||
}
|
||||
|
||||
@After
|
||||
@@ -43,22 +41,11 @@ public class AndroidContactsTest {
|
||||
public void addContact(){
|
||||
WebElement el = driver.findElement(By.name("Add Contact"));
|
||||
el.click();
|
||||
List<WebElement> textFieldsList = driver.findElements(By.tagName("textfield"));
|
||||
List<WebElement> textFieldsList = driver.findElementsByClassName("android.widget.EditText");
|
||||
textFieldsList.get(0).sendKeys("Some Name");
|
||||
textFieldsList.get(2).sendKeys("Some@example.com");
|
||||
driver.findElement(By.name("Save")).click();
|
||||
driver.swipe(100, 500, 100, 100, 2);
|
||||
driver.findElementByName("Save").click();
|
||||
}
|
||||
|
||||
public class SwipeableWebDriver extends RemoteWebDriver implements HasTouchScreen {
|
||||
private RemoteTouchScreen touch;
|
||||
|
||||
public SwipeableWebDriver(URL remoteAddress, Capabilities desiredCapabilities) {
|
||||
super(remoteAddress, desiredCapabilities);
|
||||
touch = new RemoteTouchScreen(getExecuteMethod());
|
||||
}
|
||||
|
||||
public TouchScreen getTouch() {
|
||||
return touch;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+8
-24
@@ -1,15 +1,13 @@
|
||||
package com.saucelabs.appium;
|
||||
|
||||
import io.appium.java_client.AppiumDriver;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.openqa.selenium.*;
|
||||
import org.openqa.selenium.interactions.HasTouchScreen;
|
||||
import org.openqa.selenium.interactions.TouchScreen;
|
||||
import org.openqa.selenium.By;
|
||||
import org.openqa.selenium.WebElement;
|
||||
import org.openqa.selenium.remote.CapabilityType;
|
||||
import org.openqa.selenium.remote.DesiredCapabilities;
|
||||
import org.openqa.selenium.remote.RemoteTouchScreen;
|
||||
import org.openqa.selenium.remote.RemoteWebDriver;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
@@ -19,7 +17,7 @@ import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class AndroidTest {
|
||||
|
||||
private WebDriver driver;
|
||||
private AppiumDriver driver;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
@@ -29,12 +27,11 @@ public class AndroidTest {
|
||||
DesiredCapabilities capabilities = new DesiredCapabilities();
|
||||
capabilities.setCapability("device","Android");
|
||||
capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
|
||||
capabilities.setCapability(CapabilityType.VERSION, "4.2");
|
||||
capabilities.setCapability(CapabilityType.PLATFORM, "MAC");
|
||||
capabilities.setCapability(CapabilityType.VERSION, "4.4");
|
||||
capabilities.setCapability("app", app.getAbsolutePath());
|
||||
capabilities.setCapability("app-package", "com.example.android.apis");
|
||||
capabilities.setCapability("app-activity", ".ApiDemos");
|
||||
driver = new SwipeableWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
|
||||
driver = new AppiumDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
|
||||
}
|
||||
|
||||
@After
|
||||
@@ -46,27 +43,14 @@ public class AndroidTest {
|
||||
public void apiDemo(){
|
||||
WebElement el = driver.findElement(By.name("Animation"));
|
||||
assertEquals("Animation", el.getText());
|
||||
el = driver.findElement(By.tagName("text"));
|
||||
el = driver.findElementByClassName("android.widget.TextView");
|
||||
assertEquals("API Demos", el.getText());
|
||||
el = driver.findElement(By.name("App"));
|
||||
el.click();
|
||||
List<WebElement> els = driver.findElements(By.tagName("text"));
|
||||
List<WebElement> els = driver.findElementsByClassName("android.widget.TextView");
|
||||
assertEquals("Activity", els.get(2).getText());
|
||||
}
|
||||
|
||||
public class SwipeableWebDriver extends RemoteWebDriver implements HasTouchScreen {
|
||||
private RemoteTouchScreen touch;
|
||||
|
||||
public SwipeableWebDriver(URL remoteAddress, Capabilities desiredCapabilities) {
|
||||
super(remoteAddress, desiredCapabilities);
|
||||
touch = new RemoteTouchScreen(getExecuteMethod());
|
||||
}
|
||||
|
||||
public TouchScreen getTouch() {
|
||||
return touch;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
+19
-24
@@ -1,19 +1,20 @@
|
||||
package com.saucelabs.appium;
|
||||
|
||||
import io.appium.java_client.AppiumDriver;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.openqa.selenium.*;
|
||||
import org.openqa.selenium.interactions.HasTouchScreen;
|
||||
import org.openqa.selenium.interactions.TouchScreen;
|
||||
import org.openqa.selenium.By;
|
||||
import org.openqa.selenium.WebElement;
|
||||
import org.openqa.selenium.remote.CapabilityType;
|
||||
import org.openqa.selenium.remote.DesiredCapabilities;
|
||||
import org.openqa.selenium.remote.RemoteTouchScreen;
|
||||
import org.openqa.selenium.remote.RemoteWebDriver;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
import java.util.Set;
|
||||
|
||||
public class AndroidWebViewTest {
|
||||
private WebDriver driver;
|
||||
private AppiumDriver driver;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
@@ -21,11 +22,12 @@ public class AndroidWebViewTest {
|
||||
File classpathRoot = new File(System.getProperty("user.dir"));
|
||||
File app = new File(classpathRoot, "../../../apps/selendroid-test-app.apk");
|
||||
DesiredCapabilities capabilities = new DesiredCapabilities();
|
||||
capabilities.setCapability("device","selendroid");
|
||||
capabilities.setCapability("automationName","selendroid");
|
||||
capabilities.setCapability(CapabilityType.PLATFORM, "android");
|
||||
capabilities.setCapability("app", app.getAbsolutePath());
|
||||
capabilities.setCapability("app-package", "io.selendroid.testapp");
|
||||
capabilities.setCapability("app-activity", ".HomeScreenActivity");
|
||||
driver = new SwipeableWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
|
||||
driver = new AppiumDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
|
||||
}
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
@@ -33,27 +35,20 @@ public class AndroidWebViewTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void webView(){
|
||||
public void webView() throws InterruptedException {
|
||||
WebElement button = driver.findElement(By.id("buttonStartWebview"));
|
||||
button.click();
|
||||
driver.switchTo().window("WEBVIEW");
|
||||
Thread.sleep(6000);
|
||||
Set<String> contextNames = driver.getContextHandles();
|
||||
for (String contextName : contextNames) {
|
||||
System.out.println(contextName);
|
||||
if (contextName.contains("WEBVIEW")){
|
||||
driver.context(contextName);
|
||||
}
|
||||
}
|
||||
WebElement inputField = driver.findElement(By.id("name_input"));
|
||||
inputField.sendKeys("Some name");
|
||||
inputField.submit();
|
||||
}
|
||||
|
||||
|
||||
public class SwipeableWebDriver extends RemoteWebDriver implements HasTouchScreen {
|
||||
private RemoteTouchScreen touch;
|
||||
|
||||
public SwipeableWebDriver(URL remoteAddress, Capabilities desiredCapabilities) {
|
||||
super(remoteAddress, desiredCapabilities);
|
||||
touch = new RemoteTouchScreen(getExecuteMethod());
|
||||
}
|
||||
|
||||
public TouchScreen getTouch() {
|
||||
return touch;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+16
-58
@@ -1,49 +1,35 @@
|
||||
package com.saucelabs.appium;
|
||||
|
||||
import java.net.URL;
|
||||
|
||||
import org.apache.http.HttpEntity;
|
||||
import com.google.gson.JsonParser;
|
||||
import io.appium.java_client.AppiumDriver;
|
||||
import org.apache.http.client.HttpClient;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.openqa.selenium.WebElement;
|
||||
import org.openqa.selenium.remote.CapabilityType;
|
||||
import org.openqa.selenium.remote.DesiredCapabilities;
|
||||
import org.openqa.selenium.remote.RemoteWebDriver;
|
||||
import org.openqa.selenium.remote.RemoteWebElement;
|
||||
|
||||
import com.google.gson.JsonParser;
|
||||
import java.net.URL;
|
||||
|
||||
public class MobileFindJavaTest {
|
||||
|
||||
private RemoteWebDriver driver;
|
||||
private AppiumDriver driver;
|
||||
private static final String url = "http://127.0.0.1:4723/wd/hub";
|
||||
private static final HttpClient client = HttpClients.createDefault();
|
||||
private static final JsonParser parser = new JsonParser();
|
||||
|
||||
@Test
|
||||
public void apiDemo() throws Exception {
|
||||
final WebElement about_phone = scroll_to("about phone");
|
||||
final String about_phone = scroll_to("about phone");
|
||||
if (about_phone != null) {
|
||||
System.out.println("scrolled to: " + about_phone.getText());
|
||||
System.out.println("scrolled to: aboutPhone");
|
||||
System.out.println("returned: " + about_phone);
|
||||
}
|
||||
|
||||
scroll_to("bluetooth");
|
||||
}
|
||||
|
||||
/** Create a new remote web element. **/
|
||||
public RemoteWebElement newElement(final String elementId) {
|
||||
final RemoteWebElement element = new RemoteWebElement();
|
||||
element.setParent(driver);
|
||||
element.setId(elementId);
|
||||
element.setFileDetector(driver.getFileDetector());
|
||||
return element;
|
||||
}
|
||||
|
||||
// @formatter:off
|
||||
/*
|
||||
@@ -65,52 +51,24 @@ public class MobileFindJavaTest {
|
||||
end
|
||||
*/
|
||||
// @formatter:on
|
||||
public WebElement scroll_to(String text) {
|
||||
RemoteWebElement element = null;
|
||||
try {
|
||||
text = text.replaceAll("\"", "\\\""); // quotes must be escaped.
|
||||
final String jsonString = "{\"script\":\"mobile: find\",\"args\":[[\"scroll\",[[3,\""
|
||||
+ text + "\"]],[[7,\"" + text + "\"]]]]}";
|
||||
final String id = driver.getSessionId().toString();
|
||||
final String executeURL = url + "/session/" + id + "/execute";
|
||||
public String scroll_to(String text) {
|
||||
|
||||
final HttpPost post = new HttpPost(executeURL);
|
||||
post.setEntity(new StringEntity(jsonString, "UTF8"));
|
||||
post.setHeader("Content-type", "application/json");
|
||||
text = text.replaceAll("\"", "\\\""); // quotes must be escaped.
|
||||
final String[] jsonString = {"\"scroll\"","[[3,\"" + text + "\"]]","[[7,\"" + text + "\"]]"};
|
||||
|
||||
final HttpEntity responseEntity = client.execute(post).getEntity();
|
||||
|
||||
if (responseEntity != null) {
|
||||
try {
|
||||
final String responseString = EntityUtils.toString(responseEntity);
|
||||
// {"status":0,"value":{"ELEMENT":"1"},"sessionId":"8e982755-980f-4036-b3d1-c0e14e890273"}
|
||||
final String elementId = parser.parse(responseString)
|
||||
.getAsJsonObject().get("value").getAsJsonObject().get("ELEMENT")
|
||||
.getAsString();
|
||||
return driver.complexFind(jsonString);
|
||||
|
||||
element = newElement(elementId);
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
EntityUtils.consume(responseEntity);
|
||||
}
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return element;
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
final DesiredCapabilities capabilities = new DesiredCapabilities();
|
||||
capabilities.setCapability("device", "Android");
|
||||
capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
|
||||
capabilities.setCapability(CapabilityType.VERSION, "4.2");
|
||||
capabilities.setCapability(CapabilityType.PLATFORM, "MAC");
|
||||
capabilities.setCapability("app-package", "com.android.settings");
|
||||
capabilities.setCapability("app-activity", ".Settings");
|
||||
driver = new RemoteWebDriver(new URL(url), capabilities);
|
||||
capabilities.setCapability("device", "android");
|
||||
capabilities.setCapability(CapabilityType.PLATFORM, "android");
|
||||
capabilities.setCapability("appPackage", "com.android.settings");
|
||||
capabilities.setCapability("appActivity", ".Settings");
|
||||
driver = new AppiumDriver(new URL(url), capabilities);
|
||||
}
|
||||
|
||||
@After
|
||||
|
||||
@@ -10,7 +10,6 @@ import org.openqa.selenium.remote.DesiredCapabilities;
|
||||
import org.openqa.selenium.remote.RemoteWebDriver;
|
||||
|
||||
import java.net.URL;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
@@ -35,11 +34,12 @@ public class SafariTest {
|
||||
public void setUp() throws Exception {
|
||||
DesiredCapabilities capabilities = new DesiredCapabilities();
|
||||
capabilities.setCapability("device", "iPhone Simulator");
|
||||
capabilities.setCapability("version", "6.1");
|
||||
capabilities.setCapability("app", "safari");
|
||||
capabilities.setCapability("platformName", "iOS");
|
||||
capabilities.setCapability("version", "7.1");
|
||||
capabilities.setCapability("browserName", "safari");
|
||||
driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"),
|
||||
capabilities);
|
||||
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
|
||||
//driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -50,6 +50,7 @@ public class SafariTest {
|
||||
@Test
|
||||
public void runTest() throws Exception {
|
||||
driver.get("http://saucelabs.com/test/guinea-pig");
|
||||
Thread.sleep(1000);
|
||||
WebElement idElement = driver.findElement(By.id("i_am_an_id"));
|
||||
assertNotNull(idElement);
|
||||
assertEquals("I am a div", idElement.getText());
|
||||
@@ -59,10 +60,12 @@ public class SafariTest {
|
||||
WebElement submitElement = driver.findElement(By.id("submit"));
|
||||
assertNotNull(submitElement);
|
||||
submitElement.click();
|
||||
Thread.sleep(7000);
|
||||
WebElement yourCommentsElement = driver.findElement(By.id("your_comments"));
|
||||
assertNotNull(yourCommentsElement);
|
||||
assertTrue(driver.findElement(By.id("your_comments")).getText().contains("This is an awesome comment"));
|
||||
|
||||
System.out.println(driver.getCurrentUrl());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -3,12 +3,11 @@ package com.saucelabs.appium;
|
||||
import com.saucelabs.common.SauceOnDemandAuthentication;
|
||||
import com.saucelabs.common.SauceOnDemandSessionIdProvider;
|
||||
import com.saucelabs.junit.SauceOnDemandTestWatcher;
|
||||
import io.appium.java_client.AppiumDriver;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.openqa.selenium.By;
|
||||
import org.openqa.selenium.WebDriver;
|
||||
import org.openqa.selenium.WebElement;
|
||||
import org.openqa.selenium.remote.CapabilityType;
|
||||
import org.openqa.selenium.remote.DesiredCapabilities;
|
||||
@@ -38,7 +37,7 @@ import static org.junit.Assert.assertEquals;
|
||||
*/
|
||||
public class SauceTest implements SauceOnDemandSessionIdProvider {
|
||||
|
||||
private WebDriver driver;
|
||||
private AppiumDriver driver;
|
||||
|
||||
private List<Integer> values;
|
||||
|
||||
@@ -76,7 +75,7 @@ public class SauceTest implements SauceOnDemandSessionIdProvider {
|
||||
capabilities.setCapability(CapabilityType.PLATFORM, "Mac 10.8");
|
||||
capabilities.setCapability("app", "http://appium.s3.amazonaws.com/TestApp6.0.app.zip");
|
||||
|
||||
driver = new RemoteWebDriver(new URL(MessageFormat.format("http://{0}:{1}@ondemand.saucelabs.com:80/wd/hub", sauceUserName, sauceAccessKey)),
|
||||
driver = new AppiumDriver(new URL(MessageFormat.format("http://{0}:{1}@ondemand.saucelabs.com:80/wd/hub", sauceUserName, sauceAccessKey)),
|
||||
capabilities);
|
||||
this.sessionId = ((RemoteWebDriver) driver).getSessionId().toString();
|
||||
values = new ArrayList<Integer>();
|
||||
@@ -89,7 +88,7 @@ public class SauceTest implements SauceOnDemandSessionIdProvider {
|
||||
|
||||
private void populate() {
|
||||
//populate text fields with two random number
|
||||
List<WebElement> elems = driver.findElements(By.tagName("textField"));
|
||||
List<WebElement> elems = driver.findElementsByClassName("UIATextField");
|
||||
Random random = new Random();
|
||||
for (WebElement elem : elems) {
|
||||
int rndNum = random.nextInt(MAXIMUM - MINIMUM + 1) + MINIMUM;
|
||||
@@ -104,10 +103,10 @@ public class SauceTest implements SauceOnDemandSessionIdProvider {
|
||||
// populate text fields with values
|
||||
populate();
|
||||
// trigger computation by using the button
|
||||
WebElement button = driver.findElement(By.tagName("button"));
|
||||
WebElement button = driver.findElementByClassName("UIAButton");
|
||||
button.click();
|
||||
// is sum equal ?
|
||||
WebElement texts = driver.findElement(By.tagName("staticText"));
|
||||
WebElement texts = driver.findElementByClassName("UIAStaticText");
|
||||
assertEquals(String.valueOf(values.get(0) + values.get(1)), texts.getText());
|
||||
}
|
||||
|
||||
|
||||
+54
-143
@@ -1,34 +1,21 @@
|
||||
package com.saucelabs.appium;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.parser.JSONParser;
|
||||
|
||||
import org.apache.http.util.EntityUtils;
|
||||
import io.appium.java_client.AppiumDriver;
|
||||
import io.appium.java_client.MobileBy;
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.client.HttpClient;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.impl.client.DefaultHttpClient;
|
||||
|
||||
import org.openqa.selenium.Dimension;
|
||||
import org.openqa.selenium.Alert;
|
||||
import org.openqa.selenium.By;
|
||||
import org.openqa.selenium.WebDriver;
|
||||
import org.openqa.selenium.WebElement;
|
||||
import org.openqa.selenium.Point;
|
||||
import org.openqa.selenium.interactions.HasTouchScreen;
|
||||
import org.openqa.selenium.Capabilities;
|
||||
import org.openqa.selenium.interactions.TouchScreen;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.parser.JSONParser;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.openqa.selenium.*;
|
||||
import org.openqa.selenium.remote.CapabilityType;
|
||||
import org.openqa.selenium.remote.DesiredCapabilities;
|
||||
import org.openqa.selenium.remote.RemoteWebDriver;
|
||||
import org.openqa.selenium.remote.RemoteTouchScreen;
|
||||
import org.openqa.selenium.interactions.Actions;
|
||||
import org.openqa.selenium.interactions.touch.TouchActions;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
@@ -47,7 +34,7 @@ import static org.junit.Assert.assertTrue;
|
||||
*/
|
||||
public class SimpleTest {
|
||||
|
||||
private WebDriver driver;
|
||||
private AppiumDriver driver;
|
||||
|
||||
private List<Integer> values;
|
||||
|
||||
@@ -61,11 +48,11 @@ public class SimpleTest {
|
||||
File app = new File(appDir, "TestApp.app");
|
||||
DesiredCapabilities capabilities = new DesiredCapabilities();
|
||||
capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
|
||||
capabilities.setCapability(CapabilityType.VERSION, "6.0");
|
||||
capabilities.setCapability(CapabilityType.VERSION, "7.1");
|
||||
capabilities.setCapability(CapabilityType.PLATFORM, "Mac");
|
||||
capabilities.setCapability("device", "iPhone Simulator");
|
||||
capabilities.setCapability("app", app.getAbsolutePath());
|
||||
driver = new SwipeableWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
|
||||
driver = new AppiumDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
|
||||
values = new ArrayList<Integer>();
|
||||
}
|
||||
|
||||
@@ -76,7 +63,7 @@ public class SimpleTest {
|
||||
|
||||
private void populate() {
|
||||
//populate text fields with two random number
|
||||
List<WebElement> elems = driver.findElements(By.tagName("textField"));
|
||||
List<WebElement> elems = driver.findElements(By.className("UIATextField"));
|
||||
Random random = new Random();
|
||||
for (WebElement elem : elems) {
|
||||
int rndNum = random.nextInt(MAXIMUM - MINIMUM + 1) + MINIMUM;
|
||||
@@ -85,52 +72,53 @@ public class SimpleTest {
|
||||
}
|
||||
}
|
||||
|
||||
private Point getCenter(WebElement element) {
|
||||
|
||||
Point upperLeft = element.getLocation();
|
||||
Dimension dimensions = element.getSize();
|
||||
return new Point(upperLeft.getX() + dimensions.getWidth()/2, upperLeft.getY() + dimensions.getHeight()/2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUIComputation() throws Exception {
|
||||
// populate text fields with values
|
||||
populate();
|
||||
// trigger computation by using the button
|
||||
WebElement button = driver.findElement(By.tagName("button"));
|
||||
WebElement button = driver.findElement(By.className("UIAButton"));
|
||||
button.click();
|
||||
// is sum equal ?
|
||||
WebElement texts = driver.findElement(By.tagName("staticText"));
|
||||
WebElement texts = driver.findElement(By.className("UIAStaticText"));
|
||||
assertEquals(String.valueOf(values.get(0) + values.get(1)), texts.getText());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testActive() throws Exception {
|
||||
WebElement text = driver.findElement(By.xpath("//textfield[1]"));
|
||||
WebElement text = driver.findElement(By.xpath("//UIATextField[1]"));
|
||||
assertTrue(text.isDisplayed());
|
||||
|
||||
WebElement button = driver.findElement(By.xpath("//button[1]"));
|
||||
WebElement button = driver.findElement(By.xpath("//UIAButton[1]"));
|
||||
assertTrue(button.isDisplayed());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBasicAlert() throws Exception {
|
||||
driver.findElement(By.xpath("//button[2]")).click();
|
||||
driver.findElement(By.xpath("//UIAButton[2]")).click();
|
||||
|
||||
Alert alert = driver.switchTo().alert();
|
||||
//check if title of alert is correct
|
||||
assertEquals("Cool title", alert.getText());
|
||||
assertEquals("Cool title this alert is so cool.", alert.getText());
|
||||
alert.accept();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBasicTagName() throws Exception {
|
||||
WebElement text = driver.findElement(By.xpath("//textfield[1]"));
|
||||
assertEquals("UIATextField", text.getTagName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBasicButton() throws Exception {
|
||||
WebElement button = driver.findElement(By.xpath("//button[1]"));
|
||||
WebElement button = driver.findElement(By.xpath("//UIAButton[1]"));
|
||||
assertEquals("ComputeSumButton", button.getText());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClear() throws Exception {
|
||||
WebElement text = driver.findElement(By.xpath("//textfield[1]"));
|
||||
WebElement text = driver.findElement(By.xpath("//UIATextField[1]"));
|
||||
text.sendKeys("12");
|
||||
text.clear();
|
||||
|
||||
@@ -139,114 +127,49 @@ public class SimpleTest {
|
||||
|
||||
@Test
|
||||
public void testHideKeyboard() throws Exception {
|
||||
driver.findElement(By.xpath("//textfield[1]")).sendKeys("12");
|
||||
driver.findElement(By.xpath("//UIATextField[1]")).sendKeys("12");
|
||||
|
||||
WebElement button = driver.findElement(By.name("Done"));
|
||||
WebElement button = driver.findElement(MobileBy.AccessibilityId("Done"));
|
||||
assertTrue(button.isDisplayed());
|
||||
|
||||
button.click();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindElementByTagName() throws Exception {
|
||||
public void testFindElementByClassName() throws Exception {
|
||||
Random random = new Random();
|
||||
|
||||
WebElement text = driver.findElement(By.tagName("textField"));
|
||||
WebElement text = driver.findElementByClassName("UIATextField");
|
||||
int number = random.nextInt(MAXIMUM - MINIMUM + 1) + MINIMUM;
|
||||
text.sendKeys(String.valueOf(number));
|
||||
|
||||
driver.findElement(By.tagName("button")).click();
|
||||
driver.findElementByClassName("UIAButton").click();
|
||||
|
||||
// is sum equal ?
|
||||
WebElement sumLabel = driver.findElement(By.tagName("staticText"));
|
||||
WebElement sumLabel = driver.findElementByClassName("UIAStaticText");
|
||||
assertEquals(String.valueOf(number), sumLabel.getText());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindElementsByTagName() throws Exception {
|
||||
Random random = new Random();
|
||||
public void testFindElementsByClassName() throws Exception {
|
||||
Random random = new Random();
|
||||
|
||||
WebElement text = driver.findElements(By.tagName("textField")).get(1);
|
||||
WebElement text = driver.findElementsByClassName("UIATextField").get(1);
|
||||
int number = random.nextInt(MAXIMUM - MINIMUM + 1) + MINIMUM;
|
||||
text.sendKeys(String.valueOf(number));
|
||||
|
||||
int number = random.nextInt(MAXIMUM - MINIMUM + 1) + MINIMUM;
|
||||
text.sendKeys(String.valueOf(number));
|
||||
driver.findElementByClassName("UIAButton").click();
|
||||
|
||||
driver.findElements(By.tagName("button")).get(0).click();
|
||||
|
||||
// is sum equal ?
|
||||
WebElement texts = driver.findElements(By.tagName("staticText")).get(0);
|
||||
assertEquals(String.valueOf(number), texts.getText());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindElementByName() throws Exception {
|
||||
Random random = new Random();
|
||||
|
||||
WebElement text = driver.findElement(By.name("TextField1"));
|
||||
|
||||
int number = random.nextInt(MAXIMUM - MINIMUM + 1) + MINIMUM;
|
||||
text.sendKeys(String.valueOf(number));
|
||||
|
||||
// is sum equal ?
|
||||
WebElement sumLabel = driver.findElement(By.name("SumLabel"));
|
||||
driver.findElement(By.name("ComputeSumButton")).click();
|
||||
|
||||
assertEquals(String.valueOf(number), sumLabel.getText());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindElementsByName() throws Exception {
|
||||
Random random = new Random();
|
||||
|
||||
WebElement text = driver.findElements(By.name("TextField1")).get(0);
|
||||
|
||||
int number = random.nextInt(MAXIMUM - MINIMUM + 1) + MINIMUM;
|
||||
text.sendKeys(String.valueOf(number));
|
||||
|
||||
// is sum equal ?
|
||||
WebElement sumLabel = driver.findElements(By.name("SumLabel")).get(0);
|
||||
driver.findElements(By.name("ComputeSumButton")).get(0).click();
|
||||
|
||||
assertEquals(String.valueOf(number), sumLabel.getText());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindElementByXpath() throws Exception {
|
||||
Random random = new Random();
|
||||
|
||||
WebElement text = driver.findElement(By.xpath("//textfield[1]"));
|
||||
|
||||
int number = random.nextInt(MAXIMUM - MINIMUM + 1) + MINIMUM;
|
||||
text.sendKeys(String.valueOf(number));
|
||||
|
||||
// is sum equal ?
|
||||
driver.findElement(By.xpath("//button[1]")).click();
|
||||
|
||||
WebElement sumLabel = driver.findElement(By.xpath("//text[1]"));
|
||||
assertEquals(String.valueOf(number), sumLabel.getText());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindElementsByXpath() throws Exception {
|
||||
Random random = new Random();
|
||||
|
||||
WebElement text = driver.findElements(By.xpath("//textfield")).get(1);
|
||||
|
||||
int number = random.nextInt(MAXIMUM - MINIMUM + 1) + MINIMUM;
|
||||
text.sendKeys(String.valueOf(number));
|
||||
|
||||
// is sum equal ?
|
||||
driver.findElements(By.xpath("//button")).get(0).click();
|
||||
|
||||
WebElement sumLabel = driver.findElements(By.xpath("//text")).get(0);
|
||||
assertEquals(String.valueOf(number), sumLabel.getText());
|
||||
// is sum equal ?
|
||||
WebElement sumLabel = driver.findElementsByClassName("UIAStaticText").get(0);
|
||||
assertEquals(String.valueOf(number), sumLabel.getText());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAttribute() throws Exception {
|
||||
Random random = new Random();
|
||||
|
||||
WebElement text = driver.findElement(By.xpath("//textfield[1]"));
|
||||
WebElement text = driver.findElement(By.xpath("//UIATextField[1]"));
|
||||
|
||||
int number = random.nextInt(MAXIMUM - MINIMUM + 1) + MINIMUM;
|
||||
text.sendKeys(String.valueOf(number));
|
||||
@@ -259,16 +182,17 @@ public class SimpleTest {
|
||||
@Test
|
||||
public void testSlider() throws Exception {
|
||||
//get the slider
|
||||
WebElement slider = driver.findElement(By.xpath("//slider[1]"));
|
||||
assertEquals("50 %", slider.getAttribute("value"));
|
||||
TouchActions drag = new TouchActions(driver).flick(slider, new Integer(-1), 0, 0);
|
||||
drag.perform();
|
||||
assertEquals("0 %", slider.getAttribute("value"));
|
||||
WebElement slider = driver.findElement(By.xpath("//UIASlider[1]"));
|
||||
assertEquals("50%", slider.getAttribute("value"));
|
||||
Point sliderLocation = getCenter(slider);
|
||||
driver.swipe(sliderLocation.getX(), sliderLocation.getY(), sliderLocation.getX()-100, sliderLocation.getY(), 1);
|
||||
|
||||
assertEquals("0%", slider.getAttribute("value"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLocation() throws Exception {
|
||||
WebElement button = driver.findElement(By.xpath("//button[1]"));
|
||||
WebElement button = driver.findElement(By.xpath("//UIAButton[1]"));
|
||||
|
||||
Point location = button.getLocation();
|
||||
|
||||
@@ -284,28 +208,15 @@ public class SimpleTest {
|
||||
HttpEntity entity = response.getEntity();
|
||||
JSONObject jsonObject = (JSONObject) new JSONParser().parse(EntityUtils.toString(entity));
|
||||
|
||||
String sessionId = ((RemoteWebDriver) driver).getSessionId().toString();
|
||||
String sessionId = driver.getSessionId().toString();
|
||||
assertEquals(jsonObject.get("sessionId"), sessionId);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSize() {
|
||||
Dimension text1 = driver.findElement(By.xpath("//textfield[1]")).getSize();
|
||||
Dimension text2 = driver.findElement(By.xpath("//textfield[2]")).getSize();
|
||||
Dimension text1 = driver.findElement(By.xpath("//UIATextField[1]")).getSize();
|
||||
Dimension text2 = driver.findElement(By.xpath("//UIATextField[2]")).getSize();
|
||||
assertEquals(text1.getWidth(), text2.getWidth());
|
||||
assertEquals(text1.getHeight(), text2.getHeight());
|
||||
}
|
||||
|
||||
public class SwipeableWebDriver extends RemoteWebDriver implements HasTouchScreen {
|
||||
private RemoteTouchScreen touch;
|
||||
|
||||
public SwipeableWebDriver(URL remoteAddress, Capabilities desiredCapabilities) {
|
||||
super(remoteAddress, desiredCapabilities);
|
||||
touch = new RemoteTouchScreen(getExecuteMethod());
|
||||
}
|
||||
|
||||
public TouchScreen getTouch() {
|
||||
return touch;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+47
-79
@@ -1,5 +1,7 @@
|
||||
package com.saucelabs.appium;
|
||||
|
||||
import io.appium.java_client.AppiumDriver;
|
||||
import io.appium.java_client.MobileElement;
|
||||
import org.apache.commons.lang.RandomStringUtils;
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.HttpResponse;
|
||||
@@ -11,14 +13,13 @@ import org.json.simple.JSONObject;
|
||||
import org.json.simple.parser.JSONParser;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.openqa.selenium.*;
|
||||
import org.openqa.selenium.interactions.Actions;
|
||||
import org.openqa.selenium.interactions.HasTouchScreen;
|
||||
import org.openqa.selenium.interactions.TouchScreen;
|
||||
import org.openqa.selenium.interactions.touch.TouchActions;
|
||||
import org.openqa.selenium.remote.*;
|
||||
import org.openqa.selenium.remote.Augmenter;
|
||||
import org.openqa.selenium.remote.CapabilityType;
|
||||
import org.openqa.selenium.remote.DesiredCapabilities;
|
||||
import org.openqa.selenium.remote.RemoteWebElement;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
@@ -34,7 +35,7 @@ import static org.junit.Assert.*;
|
||||
*/
|
||||
public class UICatalogTest {
|
||||
|
||||
private WebDriver driver;
|
||||
private AppiumDriver driver;
|
||||
|
||||
private WebElement row;
|
||||
|
||||
@@ -46,11 +47,11 @@ public class UICatalogTest {
|
||||
File app = new File(appDir, "UICatalog.app");
|
||||
DesiredCapabilities capabilities = new DesiredCapabilities();
|
||||
capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
|
||||
capabilities.setCapability(CapabilityType.VERSION, "6.1");
|
||||
capabilities.setCapability(CapabilityType.VERSION, "7.1");
|
||||
capabilities.setCapability(CapabilityType.PLATFORM, "Mac");
|
||||
capabilities.setCapability("device", "iPhone Simulator");
|
||||
capabilities.setCapability("app", app.getAbsolutePath());
|
||||
driver = new SwipeableWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
|
||||
driver = new AppiumDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
|
||||
}
|
||||
|
||||
@After
|
||||
@@ -60,32 +61,39 @@ public class UICatalogTest {
|
||||
|
||||
private void openMenuPosition(int index) {
|
||||
//populate text fields with two random number
|
||||
WebElement table = driver.findElement(By.tagName("tableView"));
|
||||
row = table.findElements(By.tagName("tableCell")).get(index);
|
||||
MobileElement table = new MobileElement((RemoteWebElement)driver.findElementByClassName("UIATableView"), driver);
|
||||
row = table.findElementsByClassName("UIATableCell").get(index);
|
||||
row.click();
|
||||
}
|
||||
|
||||
private Point getCenter(WebElement element) {
|
||||
|
||||
Point upperLeft = element.getLocation();
|
||||
Dimension dimensions = element.getSize();
|
||||
return new Point(upperLeft.getX() + dimensions.getWidth()/2, upperLeft.getY() + dimensions.getHeight()/2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindElement() throws Exception {
|
||||
//first view in UICatalog is a table
|
||||
WebElement table = driver.findElement(By.tagName("tableView"));
|
||||
MobileElement table = new MobileElement((RemoteWebElement)driver.findElementByClassName("UIATableView"), driver);
|
||||
assertNotNull(table);
|
||||
//is number of cells/rows inside table correct
|
||||
List<WebElement> rows = table.findElements(By.tagName("tableCell"));
|
||||
List<WebElement> rows = table.findElementsByClassName("UIATableCell");
|
||||
assertEquals(12, rows.size());
|
||||
//is first one about buttons
|
||||
assertEquals("Buttons, Various uses of UIButton", rows.get(0).getAttribute("name"));
|
||||
//navigationBar is not inside table
|
||||
WebElement nav_bar = null;
|
||||
try {
|
||||
nav_bar = table.findElement(By.tagName("navigationBar"));
|
||||
nav_bar = table.findElementByClassName("UIANavigationBar");
|
||||
} catch (NoSuchElementException e) {
|
||||
//expected
|
||||
}
|
||||
assertNull(nav_bar);
|
||||
//there is nav bar inside the app
|
||||
driver.getPageSource();
|
||||
nav_bar = driver.findElement(By.tagName("navigationBar"));
|
||||
nav_bar = driver.findElementByClassName("UIANavigationBar");
|
||||
assertNotNull(nav_bar);
|
||||
}
|
||||
|
||||
@@ -93,13 +101,12 @@ public class UICatalogTest {
|
||||
@Test
|
||||
public void test_location() {
|
||||
//get third row location
|
||||
row = driver.findElements(By.tagName("tableCell")).get(2);
|
||||
row = driver.findElementsByClassName("UIATableCell").get(2);
|
||||
assertEquals(0, row.getLocation().getX());
|
||||
assertEquals(152, row.getLocation().getY());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore("Currently failing due to IllegalArgumentException: Superclass has no null constructors but no arguments were given")
|
||||
public void testScreenshot() {
|
||||
//make screenshot and get is as base64
|
||||
WebDriver augmentedDriver = new Augmenter().augment(driver);
|
||||
@@ -111,35 +118,11 @@ public class UICatalogTest {
|
||||
assertNotNull(file);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore("Currently failing because no element with a tag name of 'segmentedControl' can be found")
|
||||
public void testAttributes() {
|
||||
//go to the toolbar section
|
||||
openMenuPosition(8);
|
||||
|
||||
WebElement segmented_control = driver.findElement(By.tagName("segmentedControl"));
|
||||
//segmented_control is enabled by default
|
||||
assertTrue(segmented_control.isEnabled());
|
||||
assertTrue(segmented_control.isDisplayed());
|
||||
//row is from previous view, should not be visible
|
||||
assertFalse(row.isDisplayed());
|
||||
|
||||
WebElement tinted_switch = driver.findElements(By.tagName("switch")).get(1);
|
||||
assertEquals("Tinted", tinted_switch.getText());
|
||||
//check if it is in "off" position
|
||||
assertEquals(new Integer(0), Integer.valueOf(tinted_switch.getAttribute("value")));
|
||||
tinted_switch.click();
|
||||
//check if it is in "on" position
|
||||
assertEquals(new Integer(1), Integer.valueOf(tinted_switch.getAttribute("value")));
|
||||
//segmented_control should now be disabled
|
||||
assertFalse(segmented_control.isEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTextFieldEdit() {
|
||||
//go to the text fields section
|
||||
openMenuPosition(2);
|
||||
WebElement text_field = driver.findElements(By.tagName("textField")).get(0);
|
||||
WebElement text_field = driver.findElementsByClassName("UIATextField").get(0);
|
||||
//get default/empty text
|
||||
String default_val = text_field.getAttribute("value");
|
||||
//write some random text to element
|
||||
@@ -162,14 +145,13 @@ public class UICatalogTest {
|
||||
public void testAlertInteraction() {
|
||||
//go to the alerts section
|
||||
openMenuPosition(10);
|
||||
List<WebElement> elements = driver.findElements(By.tagName("staticText"));
|
||||
|
||||
//trigger modal alert with cancel & ok buttons
|
||||
WebElement triggerOkCancel = elements.get(24);
|
||||
triggerOkCancel.click();
|
||||
List<WebElement> triggerOkCancel = driver.findElementsByAccessibilityId("Show OK-Cancel");
|
||||
triggerOkCancel.get(1).click();
|
||||
Alert alert = driver.switchTo().alert();
|
||||
//check if title of alert is correct
|
||||
assertEquals("UIAlertView", alert.getText());
|
||||
assertEquals("UIAlertView <Alert message>", alert.getText());
|
||||
alert.accept();
|
||||
}
|
||||
|
||||
@@ -177,11 +159,11 @@ public class UICatalogTest {
|
||||
public void testScroll() {
|
||||
//scroll menu
|
||||
//get initial third row location
|
||||
row = driver.findElements(By.tagName("tableCell")).get(2);
|
||||
row = driver.findElementsByClassName("UIATableCell").get(2);
|
||||
Point location1 = row.getLocation();
|
||||
Point center = getCenter(row);
|
||||
//perform swipe gesture
|
||||
TouchActions swipe = new TouchActions(driver).flick(0, -20);
|
||||
swipe.perform();
|
||||
driver.swipe(center.getX(), center.getY(), center.getX(), center.getY()-20, 1);
|
||||
//get new row coordinates
|
||||
Point location2 = row.getLocation();
|
||||
assertEquals(location1.getX(), location2.getX());
|
||||
@@ -190,33 +172,32 @@ public class UICatalogTest {
|
||||
|
||||
@Test
|
||||
public void testSlider() {
|
||||
//go to controls
|
||||
openMenuPosition(1);
|
||||
//get the slider
|
||||
WebElement slider = driver.findElement(By.tagName("slider"));
|
||||
assertEquals("50%", slider.getAttribute("value"));
|
||||
TouchActions drag = new TouchActions(driver).flick(slider, new Integer(-1), 0, 0);
|
||||
drag.perform();
|
||||
assertEquals("0%", slider.getAttribute("value"));
|
||||
//go to controls
|
||||
openMenuPosition(1);
|
||||
//get the slider
|
||||
WebElement slider = driver.findElementByClassName("UIASlider");
|
||||
assertEquals("50%", slider.getAttribute("value"));
|
||||
Point sliderLocation = getCenter(slider);
|
||||
driver.swipe(sliderLocation.getX(), sliderLocation.getY(), sliderLocation.getX()-100, sliderLocation.getY(), 1);
|
||||
assertEquals("0%", slider.getAttribute("value"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSessions() throws Exception {
|
||||
HttpGet request = new HttpGet("http://localhost:4723/wd/hub/sessions");
|
||||
HttpClient httpClient = new DefaultHttpClient();
|
||||
HttpResponse response = httpClient.execute(request);
|
||||
HttpEntity entity = response.getEntity();
|
||||
JSONObject jsonObject = (JSONObject) new JSONParser().parse(EntityUtils.toString(entity));
|
||||
|
||||
HttpGet request = new HttpGet("http://localhost:4723/wd/hub/sessions");
|
||||
HttpClient httpClient = new DefaultHttpClient();
|
||||
HttpResponse response = httpClient.execute(request);
|
||||
HttpEntity entity = response.getEntity();
|
||||
JSONObject jsonObject = (JSONObject) new JSONParser().parse(EntityUtils.toString(entity));
|
||||
|
||||
String sessionId = ((RemoteWebDriver) driver).getSessionId().toString();
|
||||
assertEquals(jsonObject.get("sessionId"), sessionId);
|
||||
String sessionId = driver.getSessionId().toString();
|
||||
assertEquals(jsonObject.get("sessionId"), sessionId);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSize() {
|
||||
Dimension table = driver.findElement(By.tagName("tableView")).getSize();
|
||||
Dimension cell = driver.findElements(By.tagName("tableCell")).get(0).getSize();
|
||||
Dimension table = driver.findElementByClassName("UIATableView").getSize();
|
||||
Dimension cell = driver.findElementsByClassName("UIATableCell").get(0).getSize();
|
||||
assertEquals(table.getWidth(), cell.getWidth());
|
||||
assertNotSame(table.getHeight(), cell.getHeight());
|
||||
}
|
||||
@@ -236,17 +217,4 @@ public class UICatalogTest {
|
||||
|
||||
assertNotSame(source_main, source_textfields);
|
||||
}
|
||||
|
||||
public class SwipeableWebDriver extends RemoteWebDriver implements HasTouchScreen {
|
||||
private RemoteTouchScreen touch;
|
||||
|
||||
public SwipeableWebDriver(URL remoteAddress, Capabilities desiredCapabilities) {
|
||||
super(remoteAddress, desiredCapabilities);
|
||||
touch = new RemoteTouchScreen(getExecuteMethod());
|
||||
}
|
||||
|
||||
public TouchScreen getTouch() {
|
||||
return touch;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user