diff --git a/sample-code/examples/java/junit/src/test/java/com/saucelabs/appium/SauceTest.java b/sample-code/examples/java/junit/src/test/java/com/saucelabs/appium/SauceTest.java index bd4799445..5436d8fe3 100644 --- a/sample-code/examples/java/junit/src/test/java/com/saucelabs/appium/SauceTest.java +++ b/sample-code/examples/java/junit/src/test/java/com/saucelabs/appium/SauceTest.java @@ -25,7 +25,7 @@ public class SauceTest { private WebDriver driver; - private List values; + private List values; private static final int MINIMUM = 0; private static final int MAXIMUM = 10; @@ -43,7 +43,7 @@ public class SauceTest { driver = new RemoteWebDriver(new URL(MessageFormat.format("http://{0}:{1}@ondemand.saucelabs.com:80/wd/hub", sauceUserName, sauceAccessKey)), capabilities); - values = new ArrayList(); + values = new ArrayList(); } @After @@ -56,10 +56,9 @@ public class SauceTest { //populate text fields with two random number List elems = driver.findElements(By.tagName("textField")); Random random = new Random(); - for (WebElement elem : elems) { - String rndNum = String.valueOf(random.nextInt(MAXIMUM - MINIMUM + 1) + MINIMUM); - elem.sendKeys(rndNum); + int rndNum = random.nextInt(MAXIMUM - MINIMUM + 1) + MINIMUM; + elem.sendKeys(String.valueOf(rndNum)); values.add(rndNum); } } @@ -74,6 +73,6 @@ public class SauceTest { button.click(); // is sum equal ? WebElement texts = driver.findElement(By.tagName("staticText")); - assertEquals(texts.getText(), values.get(0) + values.get(1)); + assertEquals(texts.getText(), String.valueOf(values.get(0) + values.get(1))); } } diff --git a/sample-code/examples/java/junit/src/test/java/com/saucelabs/appium/SimpleTest.java b/sample-code/examples/java/junit/src/test/java/com/saucelabs/appium/SimpleTest.java index e8d64ab97..452013e0c 100644 --- a/sample-code/examples/java/junit/src/test/java/com/saucelabs/appium/SimpleTest.java +++ b/sample-code/examples/java/junit/src/test/java/com/saucelabs/appium/SimpleTest.java @@ -25,7 +25,7 @@ public class SimpleTest { private WebDriver driver; - private List values; + private List values; private static final int MINIMUM = 0; private static final int MAXIMUM = 10; @@ -42,7 +42,7 @@ public class SimpleTest { capabilities.setCapability(CapabilityType.PLATFORM, "Mac"); capabilities.setCapability("app", app.getAbsolutePath()); driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities); - values = new ArrayList(); + values = new ArrayList(); } @After @@ -56,8 +56,8 @@ public class SimpleTest { List elems = driver.findElements(By.tagName("textField")); Random random = new Random(); for (WebElement elem : elems) { - String rndNum = String.valueOf(random.nextInt(MAXIMUM - MINIMUM + 1) + MINIMUM); - elem.sendKeys(rndNum); + int rndNum = random.nextInt(MAXIMUM - MINIMUM + 1) + MINIMUM; + elem.sendKeys(String.valueOf(rndNum)); values.add(rndNum); } } @@ -72,7 +72,7 @@ public class SimpleTest { button.click(); // is sum equal ? WebElement texts = driver.findElement(By.tagName("staticText")); - assertEquals(texts.getText(), values.get(0) + values.get(1)); + assertEquals(texts.getText(), String.valueOf(values.get(0) + values.get(1))); } diff --git a/sample-code/examples/java/junit/src/test/java/com/saucelabs/appium/UICatalogTest.java b/sample-code/examples/java/junit/src/test/java/com/saucelabs/appium/UICatalogTest.java index b5f262f5e..bc6150fea 100644 --- a/sample-code/examples/java/junit/src/test/java/com/saucelabs/appium/UICatalogTest.java +++ b/sample-code/examples/java/junit/src/test/java/com/saucelabs/appium/UICatalogTest.java @@ -40,7 +40,7 @@ public class UICatalogTest { // set up appium File classpathRoot = new File(System.getProperty("user.dir")); File appDir = new File(classpathRoot, "../../../apps/UICatalog/build/Release-iphonesimulator"); - File app = new File(appDir,"UICatalog.app"); + File app = new File(appDir, "UICatalog.app"); DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setCapability(CapabilityType.BROWSER_NAME, "iOS"); capabilities.setCapability(CapabilityType.VERSION, "6.0"); @@ -62,7 +62,7 @@ public class UICatalogTest { } @Test - public void findElement() throws Exception { + public void testFindElement() throws Exception { //first view in UICatalog is a table WebElement table = driver.findElement(By.tagName("tableView")); assertNotNull(table); @@ -70,11 +70,17 @@ public class UICatalogTest { List rows = table.findElements(By.tagName("tableCell")); assertEquals(12, rows.size()); //is first one about buttons - assertEquals(rows.get(0).getText(), "Buttons, Various uses of UIButton"); + assertEquals(rows.get(0).getAttribute("name"), "Buttons, Various uses of UIButton"); //navigationBar is not inside table - WebElement nav_bar = table.findElement(By.tagName("navigationBar")); + WebElement nav_bar = null; + try { + nav_bar = table.findElement(By.tagName("navigationBar")); + } catch (NoSuchElementException e) { + //expected + } assertNull(nav_bar); //there is nav bar inside the app + driver.getPageSource(); nav_bar = driver.findElement(By.tagName("navigationBar")); assertNotNull(nav_bar); } @@ -92,18 +98,18 @@ public class UICatalogTest { public void testScreenshot() { //make screenshot and get is as base64 WebDriver augmentedDriver = new Augmenter().augment(driver); - String screenshot = ((TakesScreenshot)augmentedDriver).getScreenshotAs(OutputType.BASE64); + String screenshot = ((TakesScreenshot) augmentedDriver).getScreenshotAs(OutputType.BASE64); assertNotNull(screenshot); //make screenshot and save it to the local filesystem - File file = ((TakesScreenshot)augmentedDriver).getScreenshotAs(OutputType.FILE); + File file = ((TakesScreenshot) augmentedDriver).getScreenshotAs(OutputType.FILE); assertNotNull(file); } @Test public void testAttributes() { //go to the toolbar section - openMenuPosition(9); + openMenuPosition(8); WebElement segmented_control = driver.findElement(By.tagName("segmentedControl")); //segmented_control is enabled by default @@ -139,7 +145,7 @@ public class UICatalogTest { Actions swipe = new Actions(driver).sendKeys(rnd_string2); swipe.perform(); //check if text is there - assertEquals(text_field.getAttribute("value"), rnd_string2); + assertEquals(text_field.getAttribute("value"), rnd_string + rnd_string2); //clear text_field.clear(); //check if is empty/has default text @@ -198,7 +204,7 @@ public class UICatalogTest { JSONObject jsonObject = (JSONObject) new JSONParser().parse(EntityUtils.toString(entity)); String sessionId = ((RemoteWebDriver) driver).getSessionId().toString(); - assertEquals(sessionId, jsonObject.get("id")); + assertEquals(sessionId, jsonObject.get("sessionId")); } @Test diff --git a/sample-code/examples/java/testng/src/test/java/com/saucelabs/appium/UICatalogTest.java b/sample-code/examples/java/testng/src/test/java/com/saucelabs/appium/UICatalogTest.java index 93d43a07a..613acce80 100644 --- a/sample-code/examples/java/testng/src/test/java/com/saucelabs/appium/UICatalogTest.java +++ b/sample-code/examples/java/testng/src/test/java/com/saucelabs/appium/UICatalogTest.java @@ -62,7 +62,7 @@ public class UICatalogTest { } @Test - public void findElement() throws Exception { + public void testFindElement() throws Exception { //first view in UICatalog is a table WebElement table = driver.findElement(By.tagName("tableView")); assertNotNull(table); @@ -70,11 +70,17 @@ public class UICatalogTest { List rows = table.findElements(By.tagName("tableCell")); assertEquals(12, rows.size()); //is first one about buttons - assertEquals(rows.get(0).getText(), "Buttons, Various uses of UIButton"); + assertEquals(rows.get(0).getAttribute("name"), "Buttons, Various uses of UIButton"); //navigationBar is not inside table - WebElement nav_bar = table.findElement(By.tagName("navigationBar")); + WebElement nav_bar = null; + try { + nav_bar = table.findElement(By.tagName("navigationBar")); + } catch (NoSuchElementException e) { + //expected + } assertNull(nav_bar); //there is nav bar inside the app + driver.getPageSource(); nav_bar = driver.findElement(By.tagName("navigationBar")); assertNotNull(nav_bar); } @@ -103,7 +109,7 @@ public class UICatalogTest { @Test public void testAttributes() { //go to the toolbar section - openMenuPosition(9); + openMenuPosition(8); WebElement segmented_control = driver.findElement(By.tagName("segmentedControl")); //segmented_control is enabled by default @@ -139,7 +145,7 @@ public class UICatalogTest { Actions swipe = new Actions(driver).sendKeys(rnd_string2); swipe.perform(); //check if text is there - assertEquals(text_field.getAttribute("value"), rnd_string2); + assertEquals(text_field.getAttribute("value"), rnd_string + rnd_string2); //clear text_field.clear(); //check if is empty/has default text @@ -198,7 +204,7 @@ public class UICatalogTest { JSONObject jsonObject = (JSONObject) new JSONParser().parse(EntityUtils.toString(entity)); String sessionId = ((RemoteWebDriver) driver).getSessionId().toString(); - assertEquals(sessionId, jsonObject.get("id")); + assertEquals(sessionId, jsonObject.get("sessionId")); } @Test