Permalink
Browse files

Updated Java Appium examples and documentation

  • Loading branch information...
1 parent b4a7ddd commit 07a7a70c2f91d2d29957af0fc62e42307d72d1cc @rossrowe rossrowe committed Mar 29, 2013
@@ -0,0 +1,18 @@
+Sample Appium JUnit project
+---
+
+This contains the source code for running sample [Appium](http://github.com/appium/appium) tests using [JUnit](http://www.junit.org).
+
+In order to run the tests, you will need to install [Apache Maven](http://maven.apache.org), and Appium (according to the Appium [installation instructions](https://github.com/appium/appium).
+
+You will then need to start appium, eg:
+
+ grunt appium
+
+To compile and run all tests, run:
+
+ mvn test
+
+To run a single test, run:
+
+ mvn -Dtest=com.saucelabs.appium.SimpleTest test
@@ -6,7 +6,7 @@
<artifactId>sauce_appium_junit</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>sauce_appium_junit</name>
-
+ <description>Sample Appium tests using JUnit</description>
<dependencies>
<dependency>
<groupId>junit</groupId>
@@ -15,12 +15,6 @@
<scope>test</scope>
</dependency>
<dependency>
- <groupId>com.saucelabs</groupId>
- <artifactId>sauce_junit</artifactId>
- <version>LATEST</version>
- <scope>test</scope>
- </dependency>
- <dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>LATEST</version>
@@ -46,6 +40,13 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
</plugin>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ </configuration>
+ </plugin>
</plugins>
</build>
@@ -19,6 +19,12 @@
import static org.junit.Assert.assertEquals;
/**
+ * Simple test which demonstrates how to run an <a href="https://github.com/appium/appium">Appium</a>
+ * using <a href="http://saucelabs.com">Sauce Labs</a>.
+ * <p/>
+ * The test relies on SAUCE_USER_NAME and SAUCE_ACCESS_KEY environment variables being set which reference
+ * the Sauce username/access key.
+ *
* @author Ross Rowe
*/
public class SauceTest {
@@ -30,11 +36,16 @@
private static final int MINIMUM = 0;
private static final int MAXIMUM = 10;
+ /**
+ * Sets up appium. You will need to either explictly set the sauce username/access key variables, or set
+ * SAUCE_USER_NAME or SAUCE_USER_NAME environment variables to reference your Sauce account details.
+ *
+ * @throws Exception
+ */
@Before
public void setUp() throws Exception {
- // set up appium
String sauceUserName = System.getenv("SAUCE_USER_NAME");
- String sauceAccessKey = System.getenv("SAUCE_ACCESS_KEY");
+ String sauceAccessKey = System.getenv("SAUCE_USER_NAME");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.BROWSER_NAME, "iOS 6.0");
capabilities.setCapability("device", "iPhone Simulator");
@@ -51,7 +62,6 @@ public void tearDown() throws Exception {
driver.quit();
}
-
private void populate() {
//populate text fields with two random number
List<WebElement> elems = driver.findElements(By.tagName("textField"));
@@ -19,6 +19,9 @@
import static org.junit.Assert.assertEquals;
/**
+ * Simple <a href="https://github.com/appium/appium">Appium</a> test which runs against a local Appium instance deployed
+ * with the 'TestApp' iPhone project which is included in the Appium source distribution.
+ *
* @author Ross Rowe
*/
public class SimpleTest {
@@ -33,8 +36,7 @@
@Before
public void setUp() throws Exception {
// set up appium
- File classpathRoot = new File(System.getProperty("user.dir"));
- File appDir = new File(classpathRoot, "../../../apps/TestApp/build/Release-iphonesimulator");
+ File appDir = new File(System.getProperty("user.dir"), "../../../apps/TestApp/build/Release-iphonesimulator");
File app = new File(appDir, "TestApp.app");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.BROWSER_NAME, "iOS");
@@ -50,21 +52,8 @@ public void tearDown() throws Exception {
driver.quit();
}
-
- private void populate() {
- //populate text fields with two random number
- List<WebElement> elems = driver.findElements(By.tagName("textField"));
- Random random = new Random();
- for (WebElement elem : elems) {
- int rndNum = random.nextInt(MAXIMUM - MINIMUM + 1) + MINIMUM;
- elem.sendKeys(String.valueOf(rndNum));
- values.add(rndNum);
- }
- }
-
@Test
public void testUIComputation() throws Exception {
-
// populate text fields with values
populate();
// trigger computation by using the button
@@ -75,5 +64,14 @@ public void testUIComputation() throws Exception {
assertEquals(texts.getText(), String.valueOf(values.get(0) + values.get(1)));
}
-
+ private void populate() {
+ //populate text fields with two random number
+ List<WebElement> elems = driver.findElements(By.tagName("textField"));
+ Random random = new Random();
+ for (WebElement elem : elems) {
+ int rndNum = random.nextInt(MAXIMUM - MINIMUM + 1) + MINIMUM;
+ elem.sendKeys(String.valueOf(rndNum));
+ values.add(rndNum);
+ }
+ }
}
@@ -11,14 +11,12 @@
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.touch.TouchActions;
-import org.openqa.selenium.remote.Augmenter;
-import org.openqa.selenium.remote.CapabilityType;
-import org.openqa.selenium.remote.DesiredCapabilities;
-import org.openqa.selenium.remote.RemoteWebDriver;
+import org.openqa.selenium.remote.*;
import java.io.File;
import java.net.URL;
@@ -27,6 +25,9 @@
import static org.junit.Assert.*;
/**
+ * <a href="https://github.com/appium/appium">Appium</a> test which runs against a local Appium instance deployed
+ * with the 'UICatalog' iPhone project which is included in the Appium source distribution.
+ *
* @author Ross Rowe
*/
public class UICatalogTest {
@@ -46,7 +47,7 @@ public void setUp() throws Exception {
capabilities.setCapability(CapabilityType.VERSION, "6.0");
capabilities.setCapability(CapabilityType.PLATFORM, "Mac");
capabilities.setCapability("app", app.getAbsolutePath());
- driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
+ driver = new SwipeableWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
}
@After
@@ -95,6 +96,7 @@ public void test_location() {
}
@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);
@@ -107,6 +109,7 @@ public void testScreenshot() {
}
@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);
@@ -159,7 +162,7 @@ public void testAlertInteraction() {
List<WebElement> elements = driver.findElements(By.tagName("staticText"));
//trigger modal alert with cancel & ok buttons
- WebElement triggerOkCancel = elements.get(14);
+ WebElement triggerOkCancel = elements.get(24);
triggerOkCancel.click();
Alert alert = driver.switchTo().alert();
//check if title of alert is correct
@@ -230,4 +233,17 @@ public void testSource() {
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;
+ }
+ }
}
@@ -0,0 +1,18 @@
+Sample Appium TestNG project
+---
+
+This contains the source code for running sample [Appium](http://github.com/appium/appium) tests using [TestNG](http://www.testng.org).
+
+In order to run the tests, you will need to install [Apache Maven](http://maven.apache.org), and Appium (according to the Appium [installation instructions](https://github.com/appium/appium).
+
+You will then need to start appium, eg:
+
+ grunt appium
+
+To compile and run all tests, run:
+
+ mvn test
+
+To run a single test, run:
+
+ mvn -Dtest=com.saucelabs.appium.SimpleTest test
@@ -6,7 +6,7 @@
<artifactId>sauce_appium_testng</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>sauce_appium_testng</name>
-
+ <description>Sample Appium tests using JUnit</description>
<dependencies>
<dependency>
<groupId>org.testng</groupId>
@@ -15,12 +15,6 @@
<scope>test</scope>
</dependency>
<dependency>
- <groupId>com.saucelabs</groupId>
- <artifactId>sauce_testng</artifactId>
- <version>LATEST</version>
- <scope>test</scope>
- </dependency>
- <dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>LATEST</version>
@@ -46,6 +40,13 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
</plugin>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ </configuration>
+ </plugin>
</plugins>
</build>
@@ -20,6 +20,12 @@
import static org.junit.Assert.assertEquals;
/**
+ * Simple test which demonstrates how to run an <a href="https://github.com/appium/appium">Appium</a>
+ * using <a href="http://saucelabs.com">Sauce Labs</a>.
+ * <p/>
+ * The test relies on SAUCE_USER_NAME and SAUCE_ACCESS_KEY environment variables being set which reference
+ * the Sauce username/access key.
+ *
* @author Ross Rowe
*/
public class SauceTest {
@@ -31,6 +37,12 @@
private static final int MINIMUM = 0;
private static final int MAXIMUM = 10;
+ /**
+ * Sets up appium. You will need to either explictly set the sauce username/access key variables, or set
+ * SAUCE_USER_NAME or SAUCE_USER_NAME environment variables to reference your Sauce account details.
+ *
+ * @throws Exception
+ */
@BeforeMethod
public void setUp() throws Exception {
// set up appium
@@ -19,6 +19,9 @@
import static org.junit.Assert.assertEquals;
/**
+ * Simple <a href="https://github.com/appium/appium">Appium</a> test which runs against a local Appium instance deployed
+ * with the 'TestApp' iPhone project which is included in the Appium source distribution.
+ *
* @author Ross Rowe
*/
public class SimpleTest {
Oops, something went wrong.

0 comments on commit 07a7a70

Please sign in to comment.