From b651a882c61140f7d28be818bf8dfce73a9a6cff Mon Sep 17 00:00:00 2001 From: Tejas Shah Date: Mon, 18 Sep 2017 00:29:14 +0530 Subject: [PATCH 01/53] remove local samples --- android/LocalSampleAndroid.java | 74 ----------------------------- ios/LocalSampleIOS.java | 82 --------------------------------- 2 files changed, 156 deletions(-) delete mode 100644 android/LocalSampleAndroid.java delete mode 100644 ios/LocalSampleIOS.java diff --git a/android/LocalSampleAndroid.java b/android/LocalSampleAndroid.java deleted file mode 100644 index 00aaf17..0000000 --- a/android/LocalSampleAndroid.java +++ /dev/null @@ -1,74 +0,0 @@ -import com.browserstack.local.Local; - -import java.net.URL; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import io.appium.java_client.android.AndroidDriver; - -import org.openqa.selenium.By; -import org.openqa.selenium.WebElement; -import org.openqa.selenium.support.ui.ExpectedConditions; -import org.openqa.selenium.support.ui.WebDriverWait; -import org.openqa.selenium.remote.DesiredCapabilities; - - -public class LocalSampleAndroid { - private static Local localInstance; - public static String accessKey = "BROWSERSTACK_USERNAME"; - public static String userName = "BROWSERSTACK_ACCESS_KEY"; - - - public static void setupLocal() throws Exception { - localInstance = new Local(); - Map options = new HashMap(); - options.put("key", accessKey); - localInstance.start(options); - } - - public static void tearDownLocal() throws Exception { - localInstance.stop(); - } - - public static void main(String[] args) throws Exception { - setupLocal(); - - DesiredCapabilities capabilities = new DesiredCapabilities(); - - capabilities.setCapability("browserstack.local", true); - capabilities.setCapability("realMobile", true); - capabilities.setCapability("device", "Samsung Galaxy S7"); - capabilities.setCapability("app", "bs://"); - - AndroidDriver driver = new AndroidDriver(new URL("https://"+userName+":"+accessKey+"@hub.browserstack.com/wd/hub"), capabilities); - - WebElement searchElement = new WebDriverWait(driver, 30).until( - ExpectedConditions.elementToBeClickable(By.id("com.example.android.basicnetworking:id/test_action"))); - searchElement.click(); - WebElement insertTextElement = new WebDriverWait(driver, 30).until( - ExpectedConditions.elementToBeClickable(By.className("android.widget.TextView"))); - - WebElement testElement = null; - List allTextViewElements = driver.findElements(By.className("android.widget.TextView")); - Thread.sleep(10); - for(WebElement textElement : allTextViewElements) { - System.out.println(textElement.getText()); - if(textElement.getText().contains("The active connection is")) { - testElement = textElement; - } - } - - if(testElement == null) { - throw new Error("Cannot find the needed TextView element from app"); - } - String matchedString = testElement.getText(); - System.out.println(matchedString); - assert(matchedString.contains("The active connection is wifi")); - assert(matchedString.contains("Up and running")); - - driver.quit(); - - tearDownLocal(); - } -} diff --git a/ios/LocalSampleIOS.java b/ios/LocalSampleIOS.java deleted file mode 100644 index 75ff044..0000000 --- a/ios/LocalSampleIOS.java +++ /dev/null @@ -1,82 +0,0 @@ -import com.browserstack.local.Local; - -import java.net.URL; -import java.io.File; -import java.util.Map; -import java.util.HashMap; -import org.apache.commons.io.FileUtils; - -import io.appium.java_client.MobileBy; -import io.appium.java_client.ios.IOSDriver; -import io.appium.java_client.ios.IOSElement; - -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.OutputType; -import org.openqa.selenium.TakesScreenshot; -import org.openqa.selenium.support.ui.WebDriverWait; -import org.openqa.selenium.remote.DesiredCapabilities; -import org.openqa.selenium.support.ui.ExpectedCondition; -import org.openqa.selenium.support.ui.ExpectedConditions; - - -public class LocalSampleIOS { - private static Local localInstance; - public static String accessKey = "BROWSERSTACK_USERNAME"; - public static String userName = "BROWSERSTACK_ACCESS_KEY"; - - - public static void setupLocal() throws Exception { - localInstance = new Local(); - Map options = new HashMap(); - options.put("key", accessKey); - localInstance.start(options); - } - - public static void tearDownLocal() throws Exception { - localInstance.stop(); - } - - public static void main(String[] args) throws Exception { - setupLocal(); - - DesiredCapabilities capabilities = new DesiredCapabilities(); - - capabilities.setCapability("browserstack.local", true); - capabilities.setCapability("realMobile", true); - capabilities.setCapability("device", "iPhone 7"); - capabilities.setCapability("app", "bs://"); - capabilities.setCapability("automationName", "XCUITest"); - - IOSDriver driver = new IOSDriver(new URL("http://"+userName+":"+accessKey+"@hub.browserstack.com/wd/hub"), capabilities); - - IOSElement testButton = (IOSElement) new WebDriverWait(driver, 30).until( - ExpectedConditions.elementToBeClickable(MobileBy.AccessibilityId("TestBrowserStackLocal"))); - testButton.click(); - - WebDriverWait wait = new WebDriverWait(driver, 30); - wait.until(new ExpectedCondition() { - @Override - public Boolean apply(WebDriver d) { - String result = d.findElement(MobileBy.AccessibilityId("ResultBrowserStackLocal")).getAttribute("value"); - return result != null && result.length() > 0; - } - }); - IOSElement resultElement = (IOSElement) driver.findElement(MobileBy.AccessibilityId("ResultBrowserStackLocal")); - - String resultString = resultElement.getText().toLowerCase(); - System.out.println(resultString); - if(resultString.contains("not working")) { - File scrFile = (File) ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE); - FileUtils.copyFile(scrFile, new File(System.getProperty("user.dir") + "/screenshot.png")); - System.out.println("Screenshot stored at " + System.getProperty("user.dir") + "/screenshot.png"); - throw new Error("Unexpected BrowserStackLocal test result"); - } - - String expectedString = "Up and running"; - assert(resultString.contains(expectedString.toLowerCase())); - - driver.quit(); - - tearDownLocal(); - } -} From f2b96e2545c3c79abf8b9bd933fd5c24c7336b62 Mon Sep 17 00:00:00 2001 From: Tejas Shah Date: Fri, 22 Sep 2017 02:21:38 +0530 Subject: [PATCH 02/53] use Android Driver Element instead of Selenium --- android/BrowserStackAndroid.java | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/android/BrowserStackAndroid.java b/android/BrowserStackAndroid.java index c4e759e..e45e86f 100644 --- a/android/BrowserStackAndroid.java +++ b/android/BrowserStackAndroid.java @@ -1,16 +1,17 @@ import java.net.URL; import java.util.List; import java.net.MalformedURLException; + +import io.appium.java_client.MobileBy; import io.appium.java_client.android.AndroidDriver; +import io.appium.java_client.android.AndroidElement; -import org.openqa.selenium.By; -import org.openqa.selenium.WebElement; import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.WebDriverWait; import org.openqa.selenium.remote.DesiredCapabilities; public class BrowserStackAndroid { - + public static String accessKey = "BROWSERSTACK_USERNAME"; public static String userName = "BROWSERSTACK_ACCESS_KEY"; @@ -21,17 +22,17 @@ public static void main(String args[]) throws MalformedURLException, Interrupted capabilities.setCapability("device", "Samsung Galaxy S7"); capabilities.setCapability("app", "bs://"); - AndroidDriver driver = new AndroidDriver(new URL("https://"+userName+":"+accessKey+"@hub.browserstack.com/wd/hub"), capabilities); + AndroidDriver driver = new AndroidDriver(new URL("https://"+userName+":"+accessKey+"@hub.browserstack.com/wd/hub"), capabilities); - WebElement searchElement = new WebDriverWait(driver, 30).until( - ExpectedConditions.elementToBeClickable(By.id("Search Wikipedia"))); + AndroidElement searchElement = (AndroidElement) new WebDriverWait(driver, 30).until( + ExpectedConditions.elementToBeClickable(MobileBy.AccessibilityId("Search Wikipedia"))); searchElement.click(); - WebElement insertTextElement = new WebDriverWait(driver, 30).until( - ExpectedConditions.elementToBeClickable(By.id("org.wikipedia.alpha:id/search_src_text"))); + AndroidElement insertTextElement = (AndroidElement) new WebDriverWait(driver, 30).until( + ExpectedConditions.elementToBeClickable(MobileBy.id("org.wikipedia.alpha:id/search_src_text"))); insertTextElement.sendKeys("BrowserStack"); Thread.sleep(5000); - List allProductsName = driver.findElements(By.className("android.widget.TextView")); + List allProductsName = driver.findElementsByClassName("android.widget.TextView"); assert(allProductsName.size() > 0); driver.quit(); From d667cc87981bfd31850358c159a97aa9e0872260 Mon Sep 17 00:00:00 2001 From: Tejas Shah Date: Fri, 22 Sep 2017 12:50:25 +0530 Subject: [PATCH 03/53] add type to AndroidDriver --- android/BrowserStackAndroid.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/BrowserStackAndroid.java b/android/BrowserStackAndroid.java index e45e86f..17d3dea 100644 --- a/android/BrowserStackAndroid.java +++ b/android/BrowserStackAndroid.java @@ -22,7 +22,7 @@ public static void main(String args[]) throws MalformedURLException, Interrupted capabilities.setCapability("device", "Samsung Galaxy S7"); capabilities.setCapability("app", "bs://"); - AndroidDriver driver = new AndroidDriver(new URL("https://"+userName+":"+accessKey+"@hub.browserstack.com/wd/hub"), capabilities); + AndroidDriver driver = new AndroidDriver(new URL("https://"+userName+":"+accessKey+"@hub.browserstack.com/wd/hub"), capabilities); AndroidElement searchElement = (AndroidElement) new WebDriverWait(driver, 30).until( ExpectedConditions.elementToBeClickable(MobileBy.AccessibilityId("Search Wikipedia"))); From a32d46c526462feda77af682aea1206971ced5cf Mon Sep 17 00:00:00 2001 From: Tejas Shah Date: Fri, 22 Sep 2017 12:59:39 +0530 Subject: [PATCH 04/53] re-add local samples | update readme --- android/LocalSampleAndroid.java | 73 +++++++++++++++++++++++++++++ android/README.md | 2 + ios/LocalSampleIOS.java | 82 +++++++++++++++++++++++++++++++++ ios/README.md | 2 + 4 files changed, 159 insertions(+) create mode 100644 android/LocalSampleAndroid.java create mode 100644 ios/LocalSampleIOS.java diff --git a/android/LocalSampleAndroid.java b/android/LocalSampleAndroid.java new file mode 100644 index 0000000..af28764 --- /dev/null +++ b/android/LocalSampleAndroid.java @@ -0,0 +1,73 @@ +import com.browserstack.local.Local; + +import java.net.URL; +import java.util.Map; +import java.util.List; +import java.util.HashMap; + +import io.appium.java_client.MobileBy; +import io.appium.java_client.android.AndroidDriver; +import io.appium.java_client.android.AndroidElement; + +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; +import org.openqa.selenium.remote.DesiredCapabilities; + + +public class LocalSampleAndroid { + private static Local localInstance; + public static String accessKey = "BROWSERSTACK_USERNAME"; + public static String userName = "BROWSERSTACK_ACCESS_KEY"; + + + public static void setupLocal() throws Exception { + localInstance = new Local(); + Map options = new HashMap(); + options.put("key", accessKey); + localInstance.start(options); + } + + public static void tearDownLocal() throws Exception { + localInstance.stop(); + } + + public static void main(String[] args) throws Exception { + setupLocal(); + + DesiredCapabilities capabilities = new DesiredCapabilities(); + + capabilities.setCapability("browserstack.local", true); + capabilities.setCapability("realMobile", true); + capabilities.setCapability("device", "Samsung Galaxy S7"); + capabilities.setCapability("app", "bs://"); + + AndroidDriver driver = new AndroidDriver(new URL("https://"+userName+":"+accessKey+"@hub.browserstack.com/wd/hub"), capabilities); + + AndroidElement searchElement = (AndroidElement) new WebDriverWait(driver, 30).until( + ExpectedConditions.elementToBeClickable(MobileBy.id("com.example.android.basicnetworking:id/test_action"))); + searchElement.click(); + AndroidElement insertTextElement = (AndroidElement) new WebDriverWait(driver, 30).until( + ExpectedConditions.elementToBeClickable(MobileBy.className("android.widget.TextView"))); + + AndroidElement testElement = null; + List allTextViewElements = driver.findElementsByClassName("android.widget.TextView"); + Thread.sleep(10); + for(AndroidElement textElement : allTextViewElements) { + if(textElement.getText().contains("The active connection is")) { + testElement = textElement; + } + } + + if(testElement == null) { + throw new Error("Cannot find the needed TextView element from app"); + } + String matchedString = testElement.getText(); + System.out.println(matchedString); + assert(matchedString.contains("The active connection is wifi")); + assert(matchedString.contains("Up and running")); + + driver.quit(); + + tearDownLocal(); + } +} diff --git a/android/README.md b/android/README.md index 56d99bb..76ca27c 100644 --- a/android/README.md +++ b/android/README.md @@ -10,6 +10,8 @@ to the BrowserStack servers using the above API. - Update the desired capability "app" with the App URL returned from the above API call +For running LocalSample tests, you can download `browserstack-local-java.jar` from [here](http://search.maven.org/#search%7Cga%7C1%7Ca%3A%22browserstack-local-java%22). + For frameworks integration with BrowserStack, refer to their individual repositories - - [JUnit](https://github.com/browserstack/junit-appium-app-browserstack) diff --git a/ios/LocalSampleIOS.java b/ios/LocalSampleIOS.java new file mode 100644 index 0000000..75ff044 --- /dev/null +++ b/ios/LocalSampleIOS.java @@ -0,0 +1,82 @@ +import com.browserstack.local.Local; + +import java.net.URL; +import java.io.File; +import java.util.Map; +import java.util.HashMap; +import org.apache.commons.io.FileUtils; + +import io.appium.java_client.MobileBy; +import io.appium.java_client.ios.IOSDriver; +import io.appium.java_client.ios.IOSElement; + +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.OutputType; +import org.openqa.selenium.TakesScreenshot; +import org.openqa.selenium.support.ui.WebDriverWait; +import org.openqa.selenium.remote.DesiredCapabilities; +import org.openqa.selenium.support.ui.ExpectedCondition; +import org.openqa.selenium.support.ui.ExpectedConditions; + + +public class LocalSampleIOS { + private static Local localInstance; + public static String accessKey = "BROWSERSTACK_USERNAME"; + public static String userName = "BROWSERSTACK_ACCESS_KEY"; + + + public static void setupLocal() throws Exception { + localInstance = new Local(); + Map options = new HashMap(); + options.put("key", accessKey); + localInstance.start(options); + } + + public static void tearDownLocal() throws Exception { + localInstance.stop(); + } + + public static void main(String[] args) throws Exception { + setupLocal(); + + DesiredCapabilities capabilities = new DesiredCapabilities(); + + capabilities.setCapability("browserstack.local", true); + capabilities.setCapability("realMobile", true); + capabilities.setCapability("device", "iPhone 7"); + capabilities.setCapability("app", "bs://"); + capabilities.setCapability("automationName", "XCUITest"); + + IOSDriver driver = new IOSDriver(new URL("http://"+userName+":"+accessKey+"@hub.browserstack.com/wd/hub"), capabilities); + + IOSElement testButton = (IOSElement) new WebDriverWait(driver, 30).until( + ExpectedConditions.elementToBeClickable(MobileBy.AccessibilityId("TestBrowserStackLocal"))); + testButton.click(); + + WebDriverWait wait = new WebDriverWait(driver, 30); + wait.until(new ExpectedCondition() { + @Override + public Boolean apply(WebDriver d) { + String result = d.findElement(MobileBy.AccessibilityId("ResultBrowserStackLocal")).getAttribute("value"); + return result != null && result.length() > 0; + } + }); + IOSElement resultElement = (IOSElement) driver.findElement(MobileBy.AccessibilityId("ResultBrowserStackLocal")); + + String resultString = resultElement.getText().toLowerCase(); + System.out.println(resultString); + if(resultString.contains("not working")) { + File scrFile = (File) ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE); + FileUtils.copyFile(scrFile, new File(System.getProperty("user.dir") + "/screenshot.png")); + System.out.println("Screenshot stored at " + System.getProperty("user.dir") + "/screenshot.png"); + throw new Error("Unexpected BrowserStackLocal test result"); + } + + String expectedString = "Up and running"; + assert(resultString.contains(expectedString.toLowerCase())); + + driver.quit(); + + tearDownLocal(); + } +} diff --git a/ios/README.md b/ios/README.md index dd76f1e..7124353 100644 --- a/ios/README.md +++ b/ios/README.md @@ -10,6 +10,8 @@ to the BrowserStack servers using the above API. - Update the desired capability "app" with the App URL returned from the above API call +For running LocalSample tests, you can download `browserstack-local-java.jar` from [here](http://search.maven.org/#search%7Cga%7C1%7Ca%3A%22browserstack-local-java%22). + For frameworks integration with BrowserStack, refer to their individual repositories - - [JUnit](https://github.com/browserstack/junit-appium-app-browserstack) From 6a58a55a81de4137a6d71ffeded3511a4c591173 Mon Sep 17 00:00:00 2001 From: Tejas Shah Date: Sat, 14 Oct 2017 13:06:17 +0530 Subject: [PATCH 05/53] update sendKeys call --- ios/BrowserStackIOS.java | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/ios/BrowserStackIOS.java b/ios/BrowserStackIOS.java index 0477652..8261de4 100644 --- a/ios/BrowserStackIOS.java +++ b/ios/BrowserStackIOS.java @@ -30,14 +30,7 @@ public static void main(String args[]) throws MalformedURLException, Interrupted loginButton.click(); IOSElement emailTextField = (IOSElement) new WebDriverWait(driver, 30).until( ExpectedConditions.elementToBeClickable(MobileBy.AccessibilityId("Email address"))); - - // element.sendKeys() method is not supported in Appium 1.6.3 - // Workaround for sendKeys() method: - emailTextField.click(); - String email = "hello@browserstack.com"; - for (int i = 0; i < email.length(); i++) { - driver.findElementByXPath("//XCUIElementTypeKey[@name='" + email.charAt(i) + "']").click(); - } + emailTextField.sendKeys("hello@browserstack.com"); driver.findElementByAccessibilityId("Next").click(); Thread.sleep(5000); From 748b7a3561b5b273dfb13ad345bf220970d3c3f5 Mon Sep 17 00:00:00 2001 From: Tejas Shah Date: Tue, 12 Dec 2017 15:47:46 +0530 Subject: [PATCH 06/53] update condition | remove realMobile, automationName cap --- android/BrowserStackAndroid.java | 1 - android/LocalSampleAndroid.java | 1 - ios/BrowserStackIOS.java | 4 +--- ios/LocalSampleIOS.java | 2 -- 4 files changed, 1 insertion(+), 7 deletions(-) diff --git a/android/BrowserStackAndroid.java b/android/BrowserStackAndroid.java index 17d3dea..45eb56d 100644 --- a/android/BrowserStackAndroid.java +++ b/android/BrowserStackAndroid.java @@ -18,7 +18,6 @@ public class BrowserStackAndroid { public static void main(String args[]) throws MalformedURLException, InterruptedException { DesiredCapabilities capabilities = new DesiredCapabilities(); - capabilities.setCapability("realMobile", true); capabilities.setCapability("device", "Samsung Galaxy S7"); capabilities.setCapability("app", "bs://"); diff --git a/android/LocalSampleAndroid.java b/android/LocalSampleAndroid.java index af28764..28483d9 100644 --- a/android/LocalSampleAndroid.java +++ b/android/LocalSampleAndroid.java @@ -37,7 +37,6 @@ public static void main(String[] args) throws Exception { DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setCapability("browserstack.local", true); - capabilities.setCapability("realMobile", true); capabilities.setCapability("device", "Samsung Galaxy S7"); capabilities.setCapability("app", "bs://"); diff --git a/ios/BrowserStackIOS.java b/ios/BrowserStackIOS.java index 8261de4..250e007 100644 --- a/ios/BrowserStackIOS.java +++ b/ios/BrowserStackIOS.java @@ -18,10 +18,8 @@ public class BrowserStackIOS { public static void main(String args[]) throws MalformedURLException, InterruptedException { DesiredCapabilities capabilities = new DesiredCapabilities(); - capabilities.setCapability("realMobile", true); capabilities.setCapability("device", "iPhone 7"); capabilities.setCapability("app", "bs://"); - capabilities.setCapability("automationName", "XCUITest"); IOSDriver driver = new IOSDriver(new URL("http://"+userName+":"+accessKey+"@hub.browserstack.com/wd/hub"), capabilities); @@ -40,7 +38,7 @@ public static void main(String args[]) throws MalformedURLException, Interrupted String matchedString = ""; for(IOSElement textElement : textElements) { String textContent = textElement.getText(); - if(textContent.contains("not registered")) { + if(textContent != null && textContent.contains("not registered")) { matchedString = textContent; } } diff --git a/ios/LocalSampleIOS.java b/ios/LocalSampleIOS.java index 75ff044..bb3f889 100644 --- a/ios/LocalSampleIOS.java +++ b/ios/LocalSampleIOS.java @@ -42,10 +42,8 @@ public static void main(String[] args) throws Exception { DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setCapability("browserstack.local", true); - capabilities.setCapability("realMobile", true); capabilities.setCapability("device", "iPhone 7"); capabilities.setCapability("app", "bs://"); - capabilities.setCapability("automationName", "XCUITest"); IOSDriver driver = new IOSDriver(new URL("http://"+userName+":"+accessKey+"@hub.browserstack.com/wd/hub"), capabilities); From 1924c1642a89fcd88345f70a3d65472fda2238d0 Mon Sep 17 00:00:00 2001 From: srishti11010 Date: Wed, 2 May 2018 16:53:12 +0530 Subject: [PATCH 07/53] Changes for new sample app --- ios/BrowserStackIOS.java | 42 +++++++++++++++++----------------------- ios/README.md | 2 +- 2 files changed, 19 insertions(+), 25 deletions(-) diff --git a/ios/BrowserStackIOS.java b/ios/BrowserStackIOS.java index 250e007..48b2799 100644 --- a/ios/BrowserStackIOS.java +++ b/ios/BrowserStackIOS.java @@ -16,36 +16,30 @@ public class BrowserStackIOS { public static String userName = "BROWSERSTACK_ACCESS_KEY"; public static void main(String args[]) throws MalformedURLException, InterruptedException { - DesiredCapabilities capabilities = new DesiredCapabilities(); + DesiredCapabilities caps = new DesiredCapabilities(); - capabilities.setCapability("device", "iPhone 7"); - capabilities.setCapability("app", "bs://"); + caps.setCapability("device", "iPhone 7 Plus"); + caps.setCapability("app", "bs://"); - IOSDriver driver = new IOSDriver(new URL("http://"+userName+":"+accessKey+"@hub.browserstack.com/wd/hub"), capabilities); + IOSDriver driver = new IOSDriver(new URL("http://"+userName+":"+accessKey+"@hub-cloud.browserstack.com/wd/hub"), caps); - IOSElement loginButton = (IOSElement) new WebDriverWait(driver, 30).until( - ExpectedConditions.elementToBeClickable(MobileBy.AccessibilityId("Log In"))); - loginButton.click(); - IOSElement emailTextField = (IOSElement) new WebDriverWait(driver, 30).until( - ExpectedConditions.elementToBeClickable(MobileBy.AccessibilityId("Email address"))); - emailTextField.sendKeys("hello@browserstack.com"); + IOSElement textButton = (IOSElement) new WebDriverWait(driver, 30).until( + ExpectedConditions.elementToBeClickable(MobileBy.AccessibilityId("Text Button"))); + textButton.click(); + IOSElement textInput = (IOSElement) new WebDriverWait(driver, 30).until( + ExpectedConditions.elementToBeClickable(MobileBy.AccessibilityId("Text Input"))); + textInput.sendKeys("hello@browserstack.com"); - driver.findElementByAccessibilityId("Next").click(); Thread.sleep(5000); - List textElements = driver.findElementsByXPath("//XCUIElementTypeStaticText"); - assert(textElements.size() > 0); - String matchedString = ""; - for(IOSElement textElement : textElements) { - String textContent = textElement.getText(); - if(textContent != null && textContent.contains("not registered")) { - matchedString = textContent; - } - } - - System.out.println(matchedString); - assert(matchedString.contains("not registered on WordPress.com")); - + IOSElement textOutput = (IOSElement) new WebDriverWait(driver, 30).until( + ExpectedConditions.elementToBeClickable(MobileBy.AccessibilityId("Text Output"))); + + if(textOutput != null && textOutput.getText().equals("hello@browserstack.com")) + assert(true); + else + assert(false); + driver.quit(); } } diff --git a/ios/README.md b/ios/README.md index 7124353..91485a6 100644 --- a/ios/README.md +++ b/ios/README.md @@ -6,7 +6,7 @@ curl -u "username:accesskey" -X POST "https://api.browserstack.com/app-automate/upload" -F "file=@/path/to/app/file/Application-debug.ipa" ``` -- If you do not have an .ipa file and looking to simply try App Automate, [you can download our sample app and upload](https://www.browserstack.com/app-automate/sample-apps/ios/WordPressSample.ipa) +- If you do not have an .ipa file and looking to simply try App Automate, [you can download our sample app and upload](https://www.browserstack.com/app-automate/sample-apps/ios/BStackSampleApp.ipa) to the BrowserStack servers using the above API. - Update the desired capability "app" with the App URL returned from the above API call From 1bc5d60d4b8f53f51b498ee1ae140f7e2e796d36 Mon Sep 17 00:00:00 2001 From: Neeraj Kumar Date: Sat, 29 Aug 2020 23:06:56 +0530 Subject: [PATCH 08/53] New Maven project --- .gitignore | 5 ++ README.md | 9 --- android/BrowserStackAndroid.java | 39 --------- android/LocalSampleAndroid.java | 72 ----------------- android/README.md | 18 ----- ios/BrowserStackIOS.java | 45 ----------- ios/LocalSampleIOS.java | 80 ------------------- ios/README.md | 18 ----- java-browserstack/.classpath | 38 +++++++++ java-browserstack/.project | 23 ++++++ java-browserstack/README.md | 70 ++++++++++++++++ java-browserstack/pom.xml | 64 +++++++++++++++ .../java/android/BrowserStackAndroid.java | 67 ++++++++++++++++ .../src/test/java/ios/BrowserStackiOS.java | 64 +++++++++++++++ 14 files changed, 331 insertions(+), 281 deletions(-) create mode 100644 .gitignore delete mode 100644 README.md delete mode 100644 android/BrowserStackAndroid.java delete mode 100644 android/LocalSampleAndroid.java delete mode 100644 android/README.md delete mode 100644 ios/BrowserStackIOS.java delete mode 100644 ios/LocalSampleIOS.java delete mode 100644 ios/README.md create mode 100644 java-browserstack/.classpath create mode 100644 java-browserstack/.project create mode 100644 java-browserstack/README.md create mode 100644 java-browserstack/pom.xml create mode 100644 java-browserstack/src/test/java/android/BrowserStackAndroid.java create mode 100644 java-browserstack/src/test/java/ios/BrowserStackiOS.java diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..871cd6a --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +*.png +target/ +local.log +.idea +*.iml diff --git a/README.md b/README.md deleted file mode 100644 index 446876b..0000000 --- a/README.md +++ /dev/null @@ -1,9 +0,0 @@ -App Automate Java Samples ---------------------- - -This repository contains code for Automated Native App tests using Appium in Java. Please feel free to clone the repo and use the example code. - -For frameworks integration with BrowserStack, refer to their individual repositories - - -- [JUnit](https://github.com/browserstack/junit-appium-app-browserstack) -- [TestNg](https://github.com/browserstack/testng-appium-app-browserstack) \ No newline at end of file diff --git a/android/BrowserStackAndroid.java b/android/BrowserStackAndroid.java deleted file mode 100644 index 45eb56d..0000000 --- a/android/BrowserStackAndroid.java +++ /dev/null @@ -1,39 +0,0 @@ -import java.net.URL; -import java.util.List; -import java.net.MalformedURLException; - -import io.appium.java_client.MobileBy; -import io.appium.java_client.android.AndroidDriver; -import io.appium.java_client.android.AndroidElement; - -import org.openqa.selenium.support.ui.ExpectedConditions; -import org.openqa.selenium.support.ui.WebDriverWait; -import org.openqa.selenium.remote.DesiredCapabilities; - -public class BrowserStackAndroid { - - public static String accessKey = "BROWSERSTACK_USERNAME"; - public static String userName = "BROWSERSTACK_ACCESS_KEY"; - - public static void main(String args[]) throws MalformedURLException, InterruptedException { - DesiredCapabilities capabilities = new DesiredCapabilities(); - - capabilities.setCapability("device", "Samsung Galaxy S7"); - capabilities.setCapability("app", "bs://"); - - AndroidDriver driver = new AndroidDriver(new URL("https://"+userName+":"+accessKey+"@hub.browserstack.com/wd/hub"), capabilities); - - AndroidElement searchElement = (AndroidElement) new WebDriverWait(driver, 30).until( - ExpectedConditions.elementToBeClickable(MobileBy.AccessibilityId("Search Wikipedia"))); - searchElement.click(); - AndroidElement insertTextElement = (AndroidElement) new WebDriverWait(driver, 30).until( - ExpectedConditions.elementToBeClickable(MobileBy.id("org.wikipedia.alpha:id/search_src_text"))); - insertTextElement.sendKeys("BrowserStack"); - Thread.sleep(5000); - - List allProductsName = driver.findElementsByClassName("android.widget.TextView"); - assert(allProductsName.size() > 0); - - driver.quit(); - } -} diff --git a/android/LocalSampleAndroid.java b/android/LocalSampleAndroid.java deleted file mode 100644 index 28483d9..0000000 --- a/android/LocalSampleAndroid.java +++ /dev/null @@ -1,72 +0,0 @@ -import com.browserstack.local.Local; - -import java.net.URL; -import java.util.Map; -import java.util.List; -import java.util.HashMap; - -import io.appium.java_client.MobileBy; -import io.appium.java_client.android.AndroidDriver; -import io.appium.java_client.android.AndroidElement; - -import org.openqa.selenium.support.ui.ExpectedConditions; -import org.openqa.selenium.support.ui.WebDriverWait; -import org.openqa.selenium.remote.DesiredCapabilities; - - -public class LocalSampleAndroid { - private static Local localInstance; - public static String accessKey = "BROWSERSTACK_USERNAME"; - public static String userName = "BROWSERSTACK_ACCESS_KEY"; - - - public static void setupLocal() throws Exception { - localInstance = new Local(); - Map options = new HashMap(); - options.put("key", accessKey); - localInstance.start(options); - } - - public static void tearDownLocal() throws Exception { - localInstance.stop(); - } - - public static void main(String[] args) throws Exception { - setupLocal(); - - DesiredCapabilities capabilities = new DesiredCapabilities(); - - capabilities.setCapability("browserstack.local", true); - capabilities.setCapability("device", "Samsung Galaxy S7"); - capabilities.setCapability("app", "bs://"); - - AndroidDriver driver = new AndroidDriver(new URL("https://"+userName+":"+accessKey+"@hub.browserstack.com/wd/hub"), capabilities); - - AndroidElement searchElement = (AndroidElement) new WebDriverWait(driver, 30).until( - ExpectedConditions.elementToBeClickable(MobileBy.id("com.example.android.basicnetworking:id/test_action"))); - searchElement.click(); - AndroidElement insertTextElement = (AndroidElement) new WebDriverWait(driver, 30).until( - ExpectedConditions.elementToBeClickable(MobileBy.className("android.widget.TextView"))); - - AndroidElement testElement = null; - List allTextViewElements = driver.findElementsByClassName("android.widget.TextView"); - Thread.sleep(10); - for(AndroidElement textElement : allTextViewElements) { - if(textElement.getText().contains("The active connection is")) { - testElement = textElement; - } - } - - if(testElement == null) { - throw new Error("Cannot find the needed TextView element from app"); - } - String matchedString = testElement.getText(); - System.out.println(matchedString); - assert(matchedString.contains("The active connection is wifi")); - assert(matchedString.contains("Up and running")); - - driver.quit(); - - tearDownLocal(); - } -} diff --git a/android/README.md b/android/README.md deleted file mode 100644 index 76ca27c..0000000 --- a/android/README.md +++ /dev/null @@ -1,18 +0,0 @@ -## Running your tests -- Do remember to switch the USERNAME and ACCESS_KEY with your own browserstack credentials. -- Upload your Native App (.apk file) to BrowserStack servers using upload API: - - ``` - curl -u "username:accesskey" -X POST "https://api.browserstack.com/app-automate/upload" -F "file=@/path/to/app/file/Application-debug.apk" - ``` - -- If you do not have an .apk file and looking to simply try App Automate, [you can download our sample app and upload](https://www.browserstack.com/app-automate/sample-apps/android/WikipediaSample.apk) -to the BrowserStack servers using the above API. -- Update the desired capability "app" with the App URL returned from the above API call - -For running LocalSample tests, you can download `browserstack-local-java.jar` from [here](http://search.maven.org/#search%7Cga%7C1%7Ca%3A%22browserstack-local-java%22). - -For frameworks integration with BrowserStack, refer to their individual repositories - - -- [JUnit](https://github.com/browserstack/junit-appium-app-browserstack) -- [TestNG](https://github.com/browserstack/testng-appium-app-browserstack) diff --git a/ios/BrowserStackIOS.java b/ios/BrowserStackIOS.java deleted file mode 100644 index 48b2799..0000000 --- a/ios/BrowserStackIOS.java +++ /dev/null @@ -1,45 +0,0 @@ -import java.net.URL; -import java.util.List; -import java.net.MalformedURLException; - -import org.openqa.selenium.support.ui.WebDriverWait; -import org.openqa.selenium.remote.DesiredCapabilities; -import org.openqa.selenium.support.ui.ExpectedConditions; - -import io.appium.java_client.MobileBy; -import io.appium.java_client.ios.IOSDriver; -import io.appium.java_client.ios.IOSElement; - - -public class BrowserStackIOS { - public static String accessKey = "BROWSERSTACK_USERNAME"; - public static String userName = "BROWSERSTACK_ACCESS_KEY"; - - public static void main(String args[]) throws MalformedURLException, InterruptedException { - DesiredCapabilities caps = new DesiredCapabilities(); - - caps.setCapability("device", "iPhone 7 Plus"); - caps.setCapability("app", "bs://"); - - IOSDriver driver = new IOSDriver(new URL("http://"+userName+":"+accessKey+"@hub-cloud.browserstack.com/wd/hub"), caps); - - IOSElement textButton = (IOSElement) new WebDriverWait(driver, 30).until( - ExpectedConditions.elementToBeClickable(MobileBy.AccessibilityId("Text Button"))); - textButton.click(); - IOSElement textInput = (IOSElement) new WebDriverWait(driver, 30).until( - ExpectedConditions.elementToBeClickable(MobileBy.AccessibilityId("Text Input"))); - textInput.sendKeys("hello@browserstack.com"); - - Thread.sleep(5000); - - IOSElement textOutput = (IOSElement) new WebDriverWait(driver, 30).until( - ExpectedConditions.elementToBeClickable(MobileBy.AccessibilityId("Text Output"))); - - if(textOutput != null && textOutput.getText().equals("hello@browserstack.com")) - assert(true); - else - assert(false); - - driver.quit(); - } -} diff --git a/ios/LocalSampleIOS.java b/ios/LocalSampleIOS.java deleted file mode 100644 index bb3f889..0000000 --- a/ios/LocalSampleIOS.java +++ /dev/null @@ -1,80 +0,0 @@ -import com.browserstack.local.Local; - -import java.net.URL; -import java.io.File; -import java.util.Map; -import java.util.HashMap; -import org.apache.commons.io.FileUtils; - -import io.appium.java_client.MobileBy; -import io.appium.java_client.ios.IOSDriver; -import io.appium.java_client.ios.IOSElement; - -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.OutputType; -import org.openqa.selenium.TakesScreenshot; -import org.openqa.selenium.support.ui.WebDriverWait; -import org.openqa.selenium.remote.DesiredCapabilities; -import org.openqa.selenium.support.ui.ExpectedCondition; -import org.openqa.selenium.support.ui.ExpectedConditions; - - -public class LocalSampleIOS { - private static Local localInstance; - public static String accessKey = "BROWSERSTACK_USERNAME"; - public static String userName = "BROWSERSTACK_ACCESS_KEY"; - - - public static void setupLocal() throws Exception { - localInstance = new Local(); - Map options = new HashMap(); - options.put("key", accessKey); - localInstance.start(options); - } - - public static void tearDownLocal() throws Exception { - localInstance.stop(); - } - - public static void main(String[] args) throws Exception { - setupLocal(); - - DesiredCapabilities capabilities = new DesiredCapabilities(); - - capabilities.setCapability("browserstack.local", true); - capabilities.setCapability("device", "iPhone 7"); - capabilities.setCapability("app", "bs://"); - - IOSDriver driver = new IOSDriver(new URL("http://"+userName+":"+accessKey+"@hub.browserstack.com/wd/hub"), capabilities); - - IOSElement testButton = (IOSElement) new WebDriverWait(driver, 30).until( - ExpectedConditions.elementToBeClickable(MobileBy.AccessibilityId("TestBrowserStackLocal"))); - testButton.click(); - - WebDriverWait wait = new WebDriverWait(driver, 30); - wait.until(new ExpectedCondition() { - @Override - public Boolean apply(WebDriver d) { - String result = d.findElement(MobileBy.AccessibilityId("ResultBrowserStackLocal")).getAttribute("value"); - return result != null && result.length() > 0; - } - }); - IOSElement resultElement = (IOSElement) driver.findElement(MobileBy.AccessibilityId("ResultBrowserStackLocal")); - - String resultString = resultElement.getText().toLowerCase(); - System.out.println(resultString); - if(resultString.contains("not working")) { - File scrFile = (File) ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE); - FileUtils.copyFile(scrFile, new File(System.getProperty("user.dir") + "/screenshot.png")); - System.out.println("Screenshot stored at " + System.getProperty("user.dir") + "/screenshot.png"); - throw new Error("Unexpected BrowserStackLocal test result"); - } - - String expectedString = "Up and running"; - assert(resultString.contains(expectedString.toLowerCase())); - - driver.quit(); - - tearDownLocal(); - } -} diff --git a/ios/README.md b/ios/README.md deleted file mode 100644 index 91485a6..0000000 --- a/ios/README.md +++ /dev/null @@ -1,18 +0,0 @@ -## Running your tests -- Do remember to switch the USERNAME and ACCESS_KEY with your own browserstack credentials. -- Upload your Native App (.ipa file) to BrowserStack servers using upload API: - - ``` - curl -u "username:accesskey" -X POST "https://api.browserstack.com/app-automate/upload" -F "file=@/path/to/app/file/Application-debug.ipa" - ``` - -- If you do not have an .ipa file and looking to simply try App Automate, [you can download our sample app and upload](https://www.browserstack.com/app-automate/sample-apps/ios/BStackSampleApp.ipa) -to the BrowserStack servers using the above API. -- Update the desired capability "app" with the App URL returned from the above API call - -For running LocalSample tests, you can download `browserstack-local-java.jar` from [here](http://search.maven.org/#search%7Cga%7C1%7Ca%3A%22browserstack-local-java%22). - -For frameworks integration with BrowserStack, refer to their individual repositories - - -- [JUnit](https://github.com/browserstack/junit-appium-app-browserstack) -- [TestNG](https://github.com/browserstack/testng-appium-app-browserstack) \ No newline at end of file diff --git a/java-browserstack/.classpath b/java-browserstack/.classpath new file mode 100644 index 0000000..90f81ed --- /dev/null +++ b/java-browserstack/.classpath @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/java-browserstack/.project b/java-browserstack/.project new file mode 100644 index 0000000..8b53c97 --- /dev/null +++ b/java-browserstack/.project @@ -0,0 +1,23 @@ + + + java-browserstack + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + + diff --git a/java-browserstack/README.md b/java-browserstack/README.md new file mode 100644 index 0000000..cc19fde --- /dev/null +++ b/java-browserstack/README.md @@ -0,0 +1,70 @@ +# java-appium-app-browserstack + +This repository demonstrates how to run Appium Java tests on BrowserStack App Automate. + +## Setup + +### Requirements + +1. Java 8+ + +- If Java is not installed, follow these instructions: + - For Windows, download latest java version from [here](https://java.com/en/download/) and run the installer executable + - For Mac and Linux, run `java -version` to see what java version is pre-installed. If you want a different version download from [here](https://java.com/en/download/) + +2. Eclipse IDE or IntelliJ IDEA + + - If not installed, download and install Eclipse IDE from [here](https://www.eclipse.org/downloads/) or IntelliJ IDEA from [here](https://www.jetbrains.com/idea/download/#section=windows) + +### Install the dependencies + +1. Import the project as an existing Maven project in your IDE + +2. Clean and build the imported project + +## Getting Started + +Getting Started with Appium tests in Java on BrowserStack couldn't be easier! + +### Upoad your Android or iOS App + +Upload your Android app (.apk or .aab file) or iOS app (.ipa file) to BrowserStack servers using our REST API. Here is an example cURL request : + +``` +curl -u "YOUR_USERNAME:YOUR_ACCESS_KEY" \ +-X POST "https://api-cloud.browserstack.com/app-automate/upload" \ +-F "file=@/path/to/apk/file" +``` + +Ensure that @ symbol is prepended to the file path in the above request. Please note the `app_url` value returned in the API response. We will use this to set the application under test while configuring the test later on. + +**Note**: If you do not have an .apk or .ipa file and are looking to simply try App Automate, you can download and test using our [sample Android app](https://www.browserstack.com/app-automate/sample-apps/android/WikipediaSample.apk) or [sample iOS app](https://www.browserstack.com/app-automate/sample-apps/ios/BStackSampleApp.ipa). + +### **Run first test :** + +Open `BrowserStackAndroid.java` file for Android test or `BrowserStackiOS.java` for iOS test + +- Replace `YOUR_USERNAME` & `YOUR_ACCESS_KEY` with your BrowserStack access credentials + +- Replace `bs://` wkth the URL obtained from app upload step + +- Set the device and OS version + +- If you have uploaded your own app update the test case + +- Run `BrowserStackAndroid.java` for android test or `BrowserStackiOS.java` for iOS test + +For more details, refer to our documentation - [Get Started with your first test on App Automate](https://www.browserstack.com/docs/app-automate/appium/getting-started/java) + +### **Use Local testing for apps that access resources hosted in development or testing environments :** + +Refer to our documentation - [Get Started with Local testing on App Automate](https://www.browserstack.com/docs/app-automate/appium/getting-started/java/local-testing) + +## Integration with other Java frameworks + +- [JUnit](https://github.com/browserstack/junit-appium-app-browserstack) +- [TestNg](https://github.com/browserstack/testng-appium-app-browserstack) + +## Getting Help + +If you are running into any issues or have any queries, please check [Browserstack Support page](https://www.browserstack.com/support/app-automate) or [get in touch with us](https://www.browserstack.com/contact?ref=help). diff --git a/java-browserstack/pom.xml b/java-browserstack/pom.xml new file mode 100644 index 0000000..f738c84 --- /dev/null +++ b/java-browserstack/pom.xml @@ -0,0 +1,64 @@ + + 4.0.0 + com.browserstack + java-browserstack + 0.0.1-SNAPSHOT + java-browserstack + Java appium app browserstack + + + UTF-8 + 2.19.1 + + default + + + + + + commons-io + commons-io + 1.3.2 + + + org.seleniumhq.selenium + selenium-java + 3.141.59 + + + io.appium + java-client + 7.0.0 + + + com.browserstack + browserstack-local-java + 1.0.3 + + + com.googlecode.json-simple + json-simple + 1.1.1 + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.22.2 + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + 1.8 + 1.8 + + + + + + \ No newline at end of file diff --git a/java-browserstack/src/test/java/android/BrowserStackAndroid.java b/java-browserstack/src/test/java/android/BrowserStackAndroid.java new file mode 100644 index 0000000..23b01e0 --- /dev/null +++ b/java-browserstack/src/test/java/android/BrowserStackAndroid.java @@ -0,0 +1,67 @@ +package android; + +import java.net.URL; +import java.util.List; +import java.util.function.Function; +import java.net.MalformedURLException; + +import io.appium.java_client.MobileBy; +import io.appium.java_client.android.AndroidDriver; +import io.appium.java_client.android.AndroidElement; + +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.remote.DesiredCapabilities; + +public class BrowserStackAndroid { + + public static void main(String[] args) throws MalformedURLException, InterruptedException { + + DesiredCapabilities capabilities = new DesiredCapabilities(); + + // Set your access credentials + capabilities.setCapability("browserstack.user", "neerajkumar42"); + capabilities.setCapability("browserstack.key", "MXmmyxNzZTYmXyyA8xyB"); + + // Set URL of the application under test + capabilities.setCapability("app", "bs://d318ec55142bf92b1fec9fce6904109294db6678"); + + // Specify device and os_version for testing + capabilities.setCapability("device", "Google Pixel 3"); + capabilities.setCapability("os_version", "9.0"); + + // Set other BrowserStack capabilities + capabilities.setCapability("project", "First Java Project"); + capabilities.setCapability("build", "Java Android"); + capabilities.setCapability("name", "first_test"); + + + // Initialise the remote Webdriver using BrowserStack remote URL + // and desired capabilities defined above + AndroidDriver driver = new AndroidDriver( + new URL("http://hub.browserstack.com/wd/hub"), capabilities); + + + // Test case for the BrowserStack sample Android app. + // If you have uploaded your app, update the test case here. + AndroidElement searchElement = (AndroidElement) new WebDriverWait(driver, 30).until( + ExpectedConditions.elementToBeClickable( + MobileBy.AccessibilityId("Search Wikipedia"))); + searchElement.click(); + AndroidElement insertTextElement = (AndroidElement) new WebDriverWait(driver, 30).until( + ExpectedConditions.elementToBeClickable( + MobileBy.id("org.wikipedia.alpha:id/search_src_text"))); + insertTextElement.sendKeys("BrowserStack"); + Thread.sleep(5000); + List allProductsName = driver.findElementsByClassName( + "android.widget.TextView"); + assert(allProductsName.size() > 0); + + + // Invoke driver.quit() after the test is done to indicate that the test is completed. + driver.quit(); + + } + +} diff --git a/java-browserstack/src/test/java/ios/BrowserStackiOS.java b/java-browserstack/src/test/java/ios/BrowserStackiOS.java new file mode 100644 index 0000000..d02d769 --- /dev/null +++ b/java-browserstack/src/test/java/ios/BrowserStackiOS.java @@ -0,0 +1,64 @@ +package ios; + +import java.net.URL; +import java.util.List; +import java.net.MalformedURLException; + +import org.openqa.selenium.support.ui.WebDriverWait; +import org.openqa.selenium.remote.DesiredCapabilities; +import org.openqa.selenium.support.ui.ExpectedConditions; + +import io.appium.java_client.MobileBy; +import io.appium.java_client.ios.IOSDriver; +import io.appium.java_client.ios.IOSElement; + +public class BrowserStackiOS { + + public static void main(String[] args) throws MalformedURLException, InterruptedException { + DesiredCapabilities capabilities = new DesiredCapabilities(); + + // Set your access credentials + capabilities.setCapability("browserstack.user", "neerajkumar42"); + capabilities.setCapability("browserstack.key", "MXmmyxNzZTYmXyyA8xyB"); + + // Set URL of the application under test + capabilities.setCapability("app", "bs://a2c4c0bd114ce9765af0988a632982cb42688b81"); + + // Specify device and os_version for testing + capabilities.setCapability("device", "iPhone 11 Pro"); + capabilities.setCapability("os_version", "13"); + + // Set other BrowserStack capabilities + capabilities.setCapability("project", "First Java Project"); + capabilities.setCapability("build", "Java iOS"); + capabilities.setCapability("name", "first_test"); + + + // Initialise the remote Webdriver using BrowserStack remote URL + // and desired capabilities defined above + IOSDriver driver = new IOSDriver( + new URL("http://hub-cloud.browserstack.com/wd/hub"), capabilities); + + + // Test case for the BrowserStack sample iOS app. + // If you have uploaded your app, update the test case here. + IOSElement textButton = (IOSElement) new WebDriverWait(driver, 30).until( + ExpectedConditions.elementToBeClickable(MobileBy.AccessibilityId("Text Button"))); + textButton.click(); + IOSElement textInput = (IOSElement) new WebDriverWait(driver, 30).until( + ExpectedConditions.elementToBeClickable(MobileBy.AccessibilityId("Text Input"))); + textInput.sendKeys("hello@browserstack.com"); + Thread.sleep(5000); + IOSElement textOutput = (IOSElement) new WebDriverWait(driver, 30).until( + ExpectedConditions.elementToBeClickable(MobileBy.AccessibilityId("Text Output"))); + if(textOutput != null && textOutput.getText().equals("hello@browserstack.com")) + assert(true); + else + assert(false); + + // Invoke driver.quit() after the test is done to indicate that the test is completed. + driver.quit(); + + } + +} From ee602276253086b0dc074bb9a2ca59f3f2cba8d2 Mon Sep 17 00:00:00 2001 From: Neeraj Kumar Date: Sat, 29 Aug 2020 23:09:48 +0530 Subject: [PATCH 09/53] Adding .DS_Store and IDE Settings to Git Ignore file --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 871cd6a..cd3e417 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,5 @@ target/ local.log .idea *.iml +**/.DS_Store +**/.settings From 9e93054e41b0facd754c83ad7789af1668aea894 Mon Sep 17 00:00:00 2001 From: Neeraj Kumar Date: Sat, 29 Aug 2020 23:31:33 +0530 Subject: [PATCH 10/53] Adding Local script files --- java-browserstack/.classpath | 2 +- .../java/android/BrowserStackAndroid.java | 6 +- .../android/BrowserStackAndroidLocal.java | 78 +++++++++++++++++ .../src/test/java/ios/BrowserStackiOS.java | 6 +- .../test/java/ios/BrowserStackiOSLocal.java | 87 +++++++++++++++++++ 5 files changed, 172 insertions(+), 7 deletions(-) create mode 100644 java-browserstack/src/test/java/android/BrowserStackAndroidLocal.java create mode 100644 java-browserstack/src/test/java/ios/BrowserStackiOSLocal.java diff --git a/java-browserstack/.classpath b/java-browserstack/.classpath index 90f81ed..002ad57 100644 --- a/java-browserstack/.classpath +++ b/java-browserstack/.classpath @@ -24,7 +24,7 @@ - + diff --git a/java-browserstack/src/test/java/android/BrowserStackAndroid.java b/java-browserstack/src/test/java/android/BrowserStackAndroid.java index 23b01e0..be1ac58 100644 --- a/java-browserstack/src/test/java/android/BrowserStackAndroid.java +++ b/java-browserstack/src/test/java/android/BrowserStackAndroid.java @@ -21,11 +21,11 @@ public static void main(String[] args) throws MalformedURLException, Interrupted DesiredCapabilities capabilities = new DesiredCapabilities(); // Set your access credentials - capabilities.setCapability("browserstack.user", "neerajkumar42"); - capabilities.setCapability("browserstack.key", "MXmmyxNzZTYmXyyA8xyB"); + capabilities.setCapability("browserstack.user", "YOUR_USERNAME"); + capabilities.setCapability("browserstack.key", "YOUR_ACCESS_KEY"); // Set URL of the application under test - capabilities.setCapability("app", "bs://d318ec55142bf92b1fec9fce6904109294db6678"); + capabilities.setCapability("app", "bs://"); // Specify device and os_version for testing capabilities.setCapability("device", "Google Pixel 3"); diff --git a/java-browserstack/src/test/java/android/BrowserStackAndroidLocal.java b/java-browserstack/src/test/java/android/BrowserStackAndroidLocal.java new file mode 100644 index 0000000..740273d --- /dev/null +++ b/java-browserstack/src/test/java/android/BrowserStackAndroidLocal.java @@ -0,0 +1,78 @@ +package android; + +import com.browserstack.local.Local; + +import java.net.URL; +import java.util.Map; +import java.util.List; +import java.util.HashMap; + +import io.appium.java_client.MobileBy; +import io.appium.java_client.android.AndroidDriver; +import io.appium.java_client.android.AndroidElement; + +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; +import org.openqa.selenium.remote.DesiredCapabilities; + +public class BrowserStackAndroidLocal { + + private static Local localInstance; + public static String accessKey = "BROWSERSTACK_USERNAME"; + public static String userName = "BROWSERSTACK_ACCESS_KEY"; + + + public static void setupLocal() throws Exception { + localInstance = new Local(); + Map options = new HashMap(); + options.put("key", accessKey); + localInstance.start(options); + } + + public static void tearDownLocal() throws Exception { + localInstance.stop(); + } + + + + public static void main(String[] args) throws Exception { + setupLocal(); + + DesiredCapabilities capabilities = new DesiredCapabilities(); + + capabilities.setCapability("browserstack.local", true); + capabilities.setCapability("device", "Samsung Galaxy S7"); + capabilities.setCapability("app", "bs://"); + + AndroidDriver driver = new AndroidDriver(new URL("https://"+userName+":"+accessKey+"@hub.browserstack.com/wd/hub"), capabilities); + + AndroidElement searchElement = (AndroidElement) new WebDriverWait(driver, 30).until( + ExpectedConditions.elementToBeClickable(MobileBy.id("com.example.android.basicnetworking:id/test_action"))); + searchElement.click(); + AndroidElement insertTextElement = (AndroidElement) new WebDriverWait(driver, 30).until( + ExpectedConditions.elementToBeClickable(MobileBy.className("android.widget.TextView"))); + + AndroidElement testElement = null; + List allTextViewElements = driver.findElementsByClassName("android.widget.TextView"); + Thread.sleep(10); + for(AndroidElement textElement : allTextViewElements) { + if(textElement.getText().contains("The active connection is")) { + testElement = textElement; + } + } + + if(testElement == null) { + throw new Error("Cannot find the needed TextView element from app"); + } + String matchedString = testElement.getText(); + System.out.println(matchedString); + assert(matchedString.contains("The active connection is wifi")); + assert(matchedString.contains("Up and running")); + + driver.quit(); + + tearDownLocal(); + + } + +} diff --git a/java-browserstack/src/test/java/ios/BrowserStackiOS.java b/java-browserstack/src/test/java/ios/BrowserStackiOS.java index d02d769..3f3b392 100644 --- a/java-browserstack/src/test/java/ios/BrowserStackiOS.java +++ b/java-browserstack/src/test/java/ios/BrowserStackiOS.java @@ -18,11 +18,11 @@ public static void main(String[] args) throws MalformedURLException, Interrupted DesiredCapabilities capabilities = new DesiredCapabilities(); // Set your access credentials - capabilities.setCapability("browserstack.user", "neerajkumar42"); - capabilities.setCapability("browserstack.key", "MXmmyxNzZTYmXyyA8xyB"); + capabilities.setCapability("browserstack.user", "YOUR_USERNAME"); + capabilities.setCapability("browserstack.key", "YOUR_ACCESS_KEY"); // Set URL of the application under test - capabilities.setCapability("app", "bs://a2c4c0bd114ce9765af0988a632982cb42688b81"); + capabilities.setCapability("app", "bs://"); // Specify device and os_version for testing capabilities.setCapability("device", "iPhone 11 Pro"); diff --git a/java-browserstack/src/test/java/ios/BrowserStackiOSLocal.java b/java-browserstack/src/test/java/ios/BrowserStackiOSLocal.java new file mode 100644 index 0000000..ad9a04c --- /dev/null +++ b/java-browserstack/src/test/java/ios/BrowserStackiOSLocal.java @@ -0,0 +1,87 @@ +package ios; + +import com.browserstack.local.Local; + +import java.net.URL; +import java.io.File; +import java.util.Map; +import java.util.HashMap; +import org.apache.commons.io.FileUtils; + +import io.appium.java_client.MobileBy; +import io.appium.java_client.ios.IOSDriver; +import io.appium.java_client.ios.IOSElement; + +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.OutputType; +import org.openqa.selenium.TakesScreenshot; +import org.openqa.selenium.support.ui.WebDriverWait; +import org.openqa.selenium.remote.DesiredCapabilities; +import org.openqa.selenium.support.ui.ExpectedCondition; +import org.openqa.selenium.support.ui.ExpectedConditions; + + +public class BrowserStackiOSLocal { + + private static Local localInstance; + public static String accessKey = "BROWSERSTACK_USERNAME"; + public static String userName = "BROWSERSTACK_ACCESS_KEY"; + + + public static void setupLocal() throws Exception { + localInstance = new Local(); + Map options = new HashMap(); + options.put("key", accessKey); + localInstance.start(options); + } + + public static void tearDownLocal() throws Exception { + localInstance.stop(); + } + + + public static void main(String[] args) throws Exception { + + setupLocal(); + + DesiredCapabilities capabilities = new DesiredCapabilities(); + + capabilities.setCapability("browserstack.local", true); + capabilities.setCapability("device", "iPhone 7"); + capabilities.setCapability("app", "bs://"); + + IOSDriver driver = new IOSDriver(new URL("http://"+userName+":"+accessKey+"@hub.browserstack.com/wd/hub"), capabilities); + + IOSElement testButton = (IOSElement) new WebDriverWait(driver, 30).until( + ExpectedConditions.elementToBeClickable(MobileBy.AccessibilityId("TestBrowserStackLocal"))); + testButton.click(); + + WebDriverWait wait = new WebDriverWait(driver, 30); + wait.until(new ExpectedCondition() { + @Override + public Boolean apply(WebDriver d) { + String result = d.findElement(MobileBy.AccessibilityId("ResultBrowserStackLocal")).getAttribute("value"); + return result != null && result.length() > 0; + } + }); + IOSElement resultElement = (IOSElement) driver.findElement(MobileBy.AccessibilityId("ResultBrowserStackLocal")); + + String resultString = resultElement.getText().toLowerCase(); + System.out.println(resultString); + if(resultString.contains("not working")) { + File scrFile = (File) ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE); + FileUtils.copyFile(scrFile, new File(System.getProperty("user.dir") + "/screenshot.png")); + System.out.println("Screenshot stored at " + System.getProperty("user.dir") + "/screenshot.png"); + throw new Error("Unexpected BrowserStackLocal test result"); + } + + String expectedString = "Up and running"; + assert(resultString.contains(expectedString.toLowerCase())); + + driver.quit(); + + tearDownLocal(); + + } + +} From 70a6a4feb237404007f1d7bed0ba35e9222853d4 Mon Sep 17 00:00:00 2001 From: Neeraj Kumar Date: Sat, 29 Aug 2020 23:33:10 +0530 Subject: [PATCH 11/53] Update README.md --- java-browserstack/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/java-browserstack/README.md b/java-browserstack/README.md index cc19fde..6090e28 100644 --- a/java-browserstack/README.md +++ b/java-browserstack/README.md @@ -18,15 +18,15 @@ This repository demonstrates how to run Appium Java tests on BrowserStack App Au ### Install the dependencies -1. Import the project as an existing Maven project in your IDE +1. Import the `java-browserstack` Maven project as an existing Maven project in your IDE -2. Clean and build the imported project +2. Clean and build the project ## Getting Started Getting Started with Appium tests in Java on BrowserStack couldn't be easier! -### Upoad your Android or iOS App +### Upload your Android or iOS App Upload your Android app (.apk or .aab file) or iOS app (.ipa file) to BrowserStack servers using our REST API. Here is an example cURL request : From e4dde43cf4e42787ea9a1eae2b6880f129cf7cdc Mon Sep 17 00:00:00 2001 From: Neeraj Kumar Date: Mon, 31 Aug 2020 18:00:32 +0530 Subject: [PATCH 12/53] Updating readme. Removing .classpath from gitignore --- .gitignore | 1 + java-browserstack/.classpath | 38 ------------------------------------ java-browserstack/README.md | 4 +++- 3 files changed, 4 insertions(+), 39 deletions(-) delete mode 100644 java-browserstack/.classpath diff --git a/.gitignore b/.gitignore index cd3e417..ffcb8e2 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ local.log *.iml **/.DS_Store **/.settings +java-browserstack/.classpath diff --git a/java-browserstack/.classpath b/java-browserstack/.classpath deleted file mode 100644 index 002ad57..0000000 --- a/java-browserstack/.classpath +++ /dev/null @@ -1,38 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/java-browserstack/README.md b/java-browserstack/README.md index 6090e28..63b4c79 100644 --- a/java-browserstack/README.md +++ b/java-browserstack/README.md @@ -18,7 +18,7 @@ This repository demonstrates how to run Appium Java tests on BrowserStack App Au ### Install the dependencies -1. Import the `java-browserstack` Maven project as an existing Maven project in your IDE +1. Import the `java-browserstack` Maven project as an "Existing Maven project" in your IDE 2. Clean and build the project @@ -54,6 +54,8 @@ Open `BrowserStackAndroid.java` file for Android test or `BrowserStackiOS.java` - Run `BrowserStackAndroid.java` for android test or `BrowserStackiOS.java` for iOS test +- - You can access the test execution results, and debugging information such as video recording, network logs on [App Automate dashboard](https://app-automate.browserstack.com/dashboard) + For more details, refer to our documentation - [Get Started with your first test on App Automate](https://www.browserstack.com/docs/app-automate/appium/getting-started/java) ### **Use Local testing for apps that access resources hosted in development or testing environments :** From b19e063a779f4ce73f06bfb0feb1738a3d058876 Mon Sep 17 00:00:00 2001 From: Neeraj Kumar Date: Tue, 1 Sep 2020 16:47:18 +0530 Subject: [PATCH 13/53] Updated pom to work from terminal --- java-browserstack/pom.xml | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/java-browserstack/pom.xml b/java-browserstack/pom.xml index f738c84..4f29a62 100644 --- a/java-browserstack/pom.xml +++ b/java-browserstack/pom.xml @@ -60,5 +60,32 @@ + + + + first + + + + org.codehaus.mojo + exec-maven-plugin + 1.1.1 + + + test + + java + + + android.BrowserStackAndroid + test + + + + + + + + \ No newline at end of file From 39afd53cf3adcee4f2dac94aae1cc76058cb6b84 Mon Sep 17 00:00:00 2001 From: Neeraj Kumar Date: Tue, 1 Sep 2020 16:56:39 +0530 Subject: [PATCH 14/53] Bringing all files to the main folder --- java-browserstack/README.md => README.md | 0 java-browserstack/pom.xml => pom.xml | 0 .../src => src}/test/java/android/BrowserStackAndroid.java | 6 +++--- .../test/java/android/BrowserStackAndroidLocal.java | 0 .../src => src}/test/java/ios/BrowserStackiOS.java | 0 .../src => src}/test/java/ios/BrowserStackiOSLocal.java | 0 6 files changed, 3 insertions(+), 3 deletions(-) rename java-browserstack/README.md => README.md (100%) rename java-browserstack/pom.xml => pom.xml (100%) rename {java-browserstack/src => src}/test/java/android/BrowserStackAndroid.java (91%) rename {java-browserstack/src => src}/test/java/android/BrowserStackAndroidLocal.java (100%) rename {java-browserstack/src => src}/test/java/ios/BrowserStackiOS.java (100%) rename {java-browserstack/src => src}/test/java/ios/BrowserStackiOSLocal.java (100%) diff --git a/java-browserstack/README.md b/README.md similarity index 100% rename from java-browserstack/README.md rename to README.md diff --git a/java-browserstack/pom.xml b/pom.xml similarity index 100% rename from java-browserstack/pom.xml rename to pom.xml diff --git a/java-browserstack/src/test/java/android/BrowserStackAndroid.java b/src/test/java/android/BrowserStackAndroid.java similarity index 91% rename from java-browserstack/src/test/java/android/BrowserStackAndroid.java rename to src/test/java/android/BrowserStackAndroid.java index be1ac58..23b01e0 100644 --- a/java-browserstack/src/test/java/android/BrowserStackAndroid.java +++ b/src/test/java/android/BrowserStackAndroid.java @@ -21,11 +21,11 @@ public static void main(String[] args) throws MalformedURLException, Interrupted DesiredCapabilities capabilities = new DesiredCapabilities(); // Set your access credentials - capabilities.setCapability("browserstack.user", "YOUR_USERNAME"); - capabilities.setCapability("browserstack.key", "YOUR_ACCESS_KEY"); + capabilities.setCapability("browserstack.user", "neerajkumar42"); + capabilities.setCapability("browserstack.key", "MXmmyxNzZTYmXyyA8xyB"); // Set URL of the application under test - capabilities.setCapability("app", "bs://"); + capabilities.setCapability("app", "bs://d318ec55142bf92b1fec9fce6904109294db6678"); // Specify device and os_version for testing capabilities.setCapability("device", "Google Pixel 3"); diff --git a/java-browserstack/src/test/java/android/BrowserStackAndroidLocal.java b/src/test/java/android/BrowserStackAndroidLocal.java similarity index 100% rename from java-browserstack/src/test/java/android/BrowserStackAndroidLocal.java rename to src/test/java/android/BrowserStackAndroidLocal.java diff --git a/java-browserstack/src/test/java/ios/BrowserStackiOS.java b/src/test/java/ios/BrowserStackiOS.java similarity index 100% rename from java-browserstack/src/test/java/ios/BrowserStackiOS.java rename to src/test/java/ios/BrowserStackiOS.java diff --git a/java-browserstack/src/test/java/ios/BrowserStackiOSLocal.java b/src/test/java/ios/BrowserStackiOSLocal.java similarity index 100% rename from java-browserstack/src/test/java/ios/BrowserStackiOSLocal.java rename to src/test/java/ios/BrowserStackiOSLocal.java From 97b8d8b86ebcfda3ea5b6409ed5d1df92573605b Mon Sep 17 00:00:00 2001 From: Neeraj Kumar Date: Tue, 1 Sep 2020 17:22:33 +0530 Subject: [PATCH 15/53] Adding mvn profiles for all the test scenarios --- .gitignore | 4 +- java-browserstack/.project | 23 -- pom.xml | 252 +++++++++++------- .../java/android/BrowserStackAndroid.java | 6 +- 4 files changed, 169 insertions(+), 116 deletions(-) delete mode 100644 java-browserstack/.project diff --git a/.gitignore b/.gitignore index ffcb8e2..cb0ef2d 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,6 @@ local.log *.iml **/.DS_Store **/.settings -java-browserstack/.classpath +.classpath +.project + diff --git a/java-browserstack/.project b/java-browserstack/.project deleted file mode 100644 index 8b53c97..0000000 --- a/java-browserstack/.project +++ /dev/null @@ -1,23 +0,0 @@ - - - java-browserstack - - - - - - org.eclipse.jdt.core.javabuilder - - - - - org.eclipse.m2e.core.maven2Builder - - - - - - org.eclipse.jdt.core.javanature - org.eclipse.m2e.core.maven2Nature - - diff --git a/pom.xml b/pom.xml index 4f29a62..b89a106 100644 --- a/pom.xml +++ b/pom.xml @@ -1,91 +1,165 @@ - - 4.0.0 - com.browserstack - java-browserstack - 0.0.1-SNAPSHOT - java-browserstack - Java appium app browserstack - - - UTF-8 - 2.19.1 - - default - - - - - - commons-io - commons-io - 1.3.2 - - - org.seleniumhq.selenium - selenium-java - 3.141.59 - - - io.appium - java-client - 7.0.0 - - - com.browserstack - browserstack-local-java - 1.0.3 - - - com.googlecode.json-simple - json-simple - 1.1.1 - - - - - - - org.apache.maven.plugins - maven-surefire-plugin - 2.22.2 - - - org.apache.maven.plugins - maven-compiler-plugin - 3.8.1 - - 1.8 - 1.8 - - - - + + 4.0.0 + com.browserstack + java-browserstack + 0.0.1-SNAPSHOT + java-browserstack + Java appium app browserstack + + + UTF-8 + 2.19.1 + + default + + + + + + commons-io + commons-io + 1.3.2 + + + org.seleniumhq.selenium + selenium-java + 3.141.59 + + + io.appium + java-client + 7.0.0 + + + com.browserstack + browserstack-local-java + 1.0.3 + + + com.googlecode.json-simple + json-simple + 1.1.1 + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.22.2 + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + 1.8 + 1.8 + + + + + + + + android-first-test + + + + org.codehaus.mojo + exec-maven-plugin + 1.1.1 + + + test + + java + + + android.BrowserStackAndroid + test + + + + + + + + + android-local-test + + + + org.codehaus.mojo + exec-maven-plugin + 1.1.1 + + + test + + java + + + android.BrowserStackAndroidLocal + test + + + + + + + + + ios-first-test + + + + org.codehaus.mojo + exec-maven-plugin + 1.1.1 + + + test + + java + + + ios.BrowserStackiOS + test + + + + + + + + + ios-local-test + + + + org.codehaus.mojo + exec-maven-plugin + 1.1.1 + + + test + + java + + + ios.BrowserStackiOSLocal + test + + + + + + + + - - - first - - - - org.codehaus.mojo - exec-maven-plugin - 1.1.1 - - - test - - java - - - android.BrowserStackAndroid - test - - - - - - - - - \ No newline at end of file diff --git a/src/test/java/android/BrowserStackAndroid.java b/src/test/java/android/BrowserStackAndroid.java index 23b01e0..be1ac58 100644 --- a/src/test/java/android/BrowserStackAndroid.java +++ b/src/test/java/android/BrowserStackAndroid.java @@ -21,11 +21,11 @@ public static void main(String[] args) throws MalformedURLException, Interrupted DesiredCapabilities capabilities = new DesiredCapabilities(); // Set your access credentials - capabilities.setCapability("browserstack.user", "neerajkumar42"); - capabilities.setCapability("browserstack.key", "MXmmyxNzZTYmXyyA8xyB"); + capabilities.setCapability("browserstack.user", "YOUR_USERNAME"); + capabilities.setCapability("browserstack.key", "YOUR_ACCESS_KEY"); // Set URL of the application under test - capabilities.setCapability("app", "bs://d318ec55142bf92b1fec9fce6904109294db6678"); + capabilities.setCapability("app", "bs://"); // Specify device and os_version for testing capabilities.setCapability("device", "Google Pixel 3"); From 399c10702b5f04c05ae39de4001207812d772351 Mon Sep 17 00:00:00 2001 From: Neeraj Kumar Date: Tue, 1 Sep 2020 17:41:53 +0530 Subject: [PATCH 16/53] Updated Readme --- README.md | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 63b4c79..090f912 100644 --- a/README.md +++ b/README.md @@ -12,15 +12,18 @@ This repository demonstrates how to run Appium Java tests on BrowserStack App Au - For Windows, download latest java version from [here](https://java.com/en/download/) and run the installer executable - For Mac and Linux, run `java -version` to see what java version is pre-installed. If you want a different version download from [here](https://java.com/en/download/) -2. Eclipse IDE or IntelliJ IDEA +2. Maven - - If not installed, download and install Eclipse IDE from [here](https://www.eclipse.org/downloads/) or IntelliJ IDEA from [here](https://www.jetbrains.com/idea/download/#section=windows) + - If Maven is not downloaded, download it from [here](https://maven.apache.org/download.cgi) + - For installation, follow the instructions [here](https://maven.apache.org/install.html) ### Install the dependencies -1. Import the `java-browserstack` Maven project as an "Existing Maven project" in your IDE +1. Run the following command in the project's base folder -2. Clean and build the project +```cmd +mvn clean install +``` ## Getting Started @@ -42,7 +45,7 @@ Ensure that @ symbol is prepended to the file path in the above request. Please ### **Run first test :** -Open `BrowserStackAndroid.java` file for Android test or `BrowserStackiOS.java` for iOS test +Open `BrowserStackAndroid.java` file in the `android` directory or `BrowserStackiOS.java` in the `ios` directory - Replace `YOUR_USERNAME` & `YOUR_ACCESS_KEY` with your BrowserStack access credentials @@ -52,9 +55,21 @@ Open `BrowserStackAndroid.java` file for Android test or `BrowserStackiOS.java` - If you have uploaded your own app update the test case -- Run `BrowserStackAndroid.java` for android test or `BrowserStackiOS.java` for iOS test +- To run the test, use the following command in the base directory : + + - For Android test, run + + ```cmd + mvn test -P android-first-test + ``` + + - For iOS test, run + + ```cmd + mvn test -P ios-first-test + ``` -- - You can access the test execution results, and debugging information such as video recording, network logs on [App Automate dashboard](https://app-automate.browserstack.com/dashboard) +- You can access the test execution results, and debugging information such as video recording, network logs on [App Automate dashboard](https://app-automate.browserstack.com/dashboard) For more details, refer to our documentation - [Get Started with your first test on App Automate](https://www.browserstack.com/docs/app-automate/appium/getting-started/java) From 788a1f87b0639d1c0ff3950f1c1d9f91848cb224 Mon Sep 17 00:00:00 2001 From: Neeraj Kumar Date: Tue, 1 Sep 2020 17:59:01 +0530 Subject: [PATCH 17/53] Removing selenium dependency. Typo fix in Readme --- README.md | 2 +- pom.xml | 5 ----- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/README.md b/README.md index 090f912..79fb59f 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ Open `BrowserStackAndroid.java` file in the `android` directory or `BrowserStack - Replace `YOUR_USERNAME` & `YOUR_ACCESS_KEY` with your BrowserStack access credentials -- Replace `bs://` wkth the URL obtained from app upload step +- Replace `bs://` with the URL obtained from app upload step - Set the device and OS version diff --git a/pom.xml b/pom.xml index b89a106..838152f 100644 --- a/pom.xml +++ b/pom.xml @@ -22,11 +22,6 @@ commons-io 1.3.2 - - org.seleniumhq.selenium - selenium-java - 3.141.59 - io.appium java-client From eda63520d9eda02281c5d8f44f0730c481a3d354 Mon Sep 17 00:00:00 2001 From: Neeraj Kumar Date: Fri, 25 Sep 2020 02:03:42 +0530 Subject: [PATCH 18/53] Updating Local test for Android and iOS. --- .../android/BrowserStackAndroidLocal.java | 62 +++++++++++++------ src/test/java/ios/BrowserStackiOSLocal.java | 42 ++++++++++--- 2 files changed, 74 insertions(+), 30 deletions(-) diff --git a/src/test/java/android/BrowserStackAndroidLocal.java b/src/test/java/android/BrowserStackAndroidLocal.java index 740273d..deb092a 100644 --- a/src/test/java/android/BrowserStackAndroidLocal.java +++ b/src/test/java/android/BrowserStackAndroidLocal.java @@ -17,35 +17,55 @@ public class BrowserStackAndroidLocal { - private static Local localInstance; - public static String accessKey = "BROWSERSTACK_USERNAME"; - public static String userName = "BROWSERSTACK_ACCESS_KEY"; - + private static Local localInstance; + public static String userName = "YOUR_USERNAME"; + public static String accessKey = "YOUR_ACCESS_KEY"; - public static void setupLocal() throws Exception { - localInstance = new Local(); - Map options = new HashMap(); - options.put("key", accessKey); - localInstance.start(options); - } - - public static void tearDownLocal() throws Exception { - localInstance.stop(); - } + public static void setupLocal() throws Exception { + localInstance = new Local(); + Map options = new HashMap(); + options.put("key", accessKey); + localInstance.start(options); + } + public static void tearDownLocal() throws Exception { + localInstance.stop(); + } public static void main(String[] args) throws Exception { - setupLocal(); + // Start the BrowserStack Local binary + setupLocal(); + + DesiredCapabilities capabilities = new DesiredCapabilities(); + + // Set your access credentials + capabilities.setCapability("browserstack.user", userName); + capabilities.setCapability("browserstack.key", accessKey); + + // Set URL of the application under test + capabilities.setCapability("app", "bs://"); + + // Specify device and os_version for testing + capabilities.setCapability("device", "Google Pixel 3"); + capabilities.setCapability("os_version", "9.0"); - DesiredCapabilities capabilities = new DesiredCapabilities(); + // Set the browserstack.local capability to true + capabilities.setCapability("browserstack.local", true); - capabilities.setCapability("browserstack.local", true); - capabilities.setCapability("device", "Samsung Galaxy S7"); - capabilities.setCapability("app", "bs://"); + // Set other BrowserStack capabilities + capabilities.setCapability("project", "First Java Project"); + capabilities.setCapability("build", "Java Android Local"); + capabilities.setCapability("name", "local_test"); + - AndroidDriver driver = new AndroidDriver(new URL("https://"+userName+":"+accessKey+"@hub.browserstack.com/wd/hub"), capabilities); + // Initialise the remote Webdriver using BrowserStack remote URL + // and desired capabilities defined above + AndroidDriver driver = new AndroidDriver( + new URL("http://hub.browserstack.com/wd/hub"), capabilities); + // Test case for the BrowserStack sample Android Local app. + // If you have uploaded your app, update the test case here. AndroidElement searchElement = (AndroidElement) new WebDriverWait(driver, 30).until( ExpectedConditions.elementToBeClickable(MobileBy.id("com.example.android.basicnetworking:id/test_action"))); searchElement.click(); @@ -69,8 +89,10 @@ public static void main(String[] args) throws Exception { assert(matchedString.contains("The active connection is wifi")); assert(matchedString.contains("Up and running")); + // Invoke driver.quit() after the test is done to indicate that the test is completed. driver.quit(); + // Stop the BrowserStack Local binary tearDownLocal(); } diff --git a/src/test/java/ios/BrowserStackiOSLocal.java b/src/test/java/ios/BrowserStackiOSLocal.java index ad9a04c..e992434 100644 --- a/src/test/java/ios/BrowserStackiOSLocal.java +++ b/src/test/java/ios/BrowserStackiOSLocal.java @@ -24,8 +24,8 @@ public class BrowserStackiOSLocal { private static Local localInstance; - public static String accessKey = "BROWSERSTACK_USERNAME"; - public static String userName = "BROWSERSTACK_ACCESS_KEY"; + public static String accessKey = "YOUR_USERNAME"; + public static String userName = "YOUR_ACCESS_KEY"; public static void setupLocal() throws Exception { @@ -41,17 +41,37 @@ public static void tearDownLocal() throws Exception { public static void main(String[] args) throws Exception { - + // Start the BrowserStack Local binary setupLocal(); DesiredCapabilities capabilities = new DesiredCapabilities(); - capabilities.setCapability("browserstack.local", true); - capabilities.setCapability("device", "iPhone 7"); - capabilities.setCapability("app", "bs://"); - - IOSDriver driver = new IOSDriver(new URL("http://"+userName+":"+accessKey+"@hub.browserstack.com/wd/hub"), capabilities); - + // Set your access credentials + capabilities.setCapability("browserstack.user", userName); + capabilities.setCapability("browserstack.key", accessKey); + + // Set URL of the application under test + capabilities.setCapability("app", "bs://"); + + // Specify device and os_version for testing + capabilities.setCapability("device", "iPhone 11 Pro"); + capabilities.setCapability("os_version", "13"); + + // Set the browserstack.local capability to true + capabilities.setCapability("browserstack.local", true); + + // Set other BrowserStack capabilities + capabilities.setCapability("project", "First Java Project"); + capabilities.setCapability("build", "Java iOS Local"); + capabilities.setCapability("name", "local_test"); + + // Initialise the remote Webdriver using BrowserStack remote URL + // and desired capabilities defined above + IOSDriver driver = new IOSDriver( + new URL("http://hub.browserstack.com/wd/hub"), capabilities); + + // Test case for the BrowserStack sample iOS Local app. + // If you have uploaded your app, update the test case here. IOSElement testButton = (IOSElement) new WebDriverWait(driver, 30).until( ExpectedConditions.elementToBeClickable(MobileBy.AccessibilityId("TestBrowserStackLocal"))); testButton.click(); @@ -78,8 +98,10 @@ public Boolean apply(WebDriver d) { String expectedString = "Up and running"; assert(resultString.contains(expectedString.toLowerCase())); + // Invoke driver.quit() after the test is done to indicate that the test is completed. driver.quit(); - + + // Stop the BrowserStack Local binary tearDownLocal(); } From f8ff5f5ec3ca30327cec0be3688e2b8e6f0b44ba Mon Sep 17 00:00:00 2001 From: Neeraj Kumar Date: Fri, 25 Sep 2020 02:28:35 +0530 Subject: [PATCH 19/53] Updating Readme with Local test --- README.md | 55 +++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 47 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 79fb59f..c3c8922 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ This repository demonstrates how to run Appium Java tests on BrowserStack App Au ### Install the dependencies -1. Run the following command in the project's base folder +To install the dependencies, run the following command in the project's base folder ```cmd mvn clean install @@ -29,7 +29,9 @@ mvn clean install Getting Started with Appium tests in Java on BrowserStack couldn't be easier! -### Upload your Android or iOS App +### Run your first test : + +**1. Upload your Android or iOS App** Upload your Android app (.apk or .aab file) or iOS app (.ipa file) to BrowserStack servers using our REST API. Here is an example cURL request : @@ -43,9 +45,7 @@ Ensure that @ symbol is prepended to the file path in the above request. Please **Note**: If you do not have an .apk or .ipa file and are looking to simply try App Automate, you can download and test using our [sample Android app](https://www.browserstack.com/app-automate/sample-apps/android/WikipediaSample.apk) or [sample iOS app](https://www.browserstack.com/app-automate/sample-apps/ios/BStackSampleApp.ipa). -### **Run first test :** - -Open `BrowserStackAndroid.java` file in the `android` directory or `BrowserStackiOS.java` in the `ios` directory +**2. Open `BrowserStackAndroid.java` file in the `android` directory or `BrowserStackiOS.java` in the `ios` directory :** - Replace `YOUR_USERNAME` & `YOUR_ACCESS_KEY` with your BrowserStack access credentials @@ -71,11 +71,50 @@ Open `BrowserStackAndroid.java` file in the `android` directory or `BrowserStack - You can access the test execution results, and debugging information such as video recording, network logs on [App Automate dashboard](https://app-automate.browserstack.com/dashboard) -For more details, refer to our documentation - [Get Started with your first test on App Automate](https://www.browserstack.com/docs/app-automate/appium/getting-started/java) +--- + +### Use Local testing for apps that access resources hosted in development or testing environments : + +**1. Upoad your Android or iOS App** + +Upload your Android app (.apk or .aab file) or iOS app (.ipa file) that access resources hosted on your internal or test environments to BrowserStack servers using our REST API. Here is an example cURL request : + +``` +curl -u "YOUR_USERNAME:YOUR_ACCESS_KEY" \ +-X POST "https://api-cloud.browserstack.com/app-automate/upload" \ +-F "file=@/path/to/apk/file" +``` + +Ensure that @ symbol is prepended to the file path in the above request. Please note the `app_url` value returned in the API response. We will use this to set the application under test while configuring the test later on. + +**Note**: If you do not have an .apk or .ipa file and are looking to simply try App Automate, you can download and test using our [sample Android Local app](https://www.browserstack.com/app-automate/sample-apps/android/LocalSample.apk) or [sample iOS Local app](https://www.browserstack.com/app-automate/sample-apps/ios/LocalSample.ipa). + +**2. Open `BrowserStackAndroidLocal.java` file in the `android` directory or `BrowserStackiOSLocal.java` in the `ios` directory :** + +- Replace `YOUR_USERNAME` & `YOUR_ACCESS_KEY` with your BrowserStack access credentials + +- Replace `bs://` with the URL obtained from app upload step + +- Set the device and OS version + +- If you have uploaded your own app update the test case + +- To run the test, use the following command in the base directory : + + - For Android test, run -### **Use Local testing for apps that access resources hosted in development or testing environments :** + ```cmd + mvn test -P android-local-test + ``` + + - For iOS test, run + + ```cmd + mvn test -P ios-local-test + ``` + +- You can access the test execution results, and debugging information such as video recording, network logs on [App Automate dashboard](https://app-automate.browserstack.com/dashboard) -Refer to our documentation - [Get Started with Local testing on App Automate](https://www.browserstack.com/docs/app-automate/appium/getting-started/java/local-testing) ## Integration with other Java frameworks From 9e698bcdc5b8e297f0abf9f1fb72f8f2606ae2fc Mon Sep 17 00:00:00 2001 From: Neeraj Kumar Date: Fri, 25 Sep 2020 15:03:38 +0530 Subject: [PATCH 20/53] Update README.md --- README.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c3c8922..2c7724a 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,9 @@ Ensure that @ symbol is prepended to the file path in the above request. Please **Note**: If you do not have an .apk or .ipa file and are looking to simply try App Automate, you can download and test using our [sample Android app](https://www.browserstack.com/app-automate/sample-apps/android/WikipediaSample.apk) or [sample iOS app](https://www.browserstack.com/app-automate/sample-apps/ios/BStackSampleApp.ipa). -**2. Open `BrowserStackAndroid.java` file in the `android` directory or `BrowserStackiOS.java` in the `ios` directory :** +**2. Configure and run your first test** + +Open `BrowserStackAndroid.java` file in the `android` directory or `BrowserStackiOS.java` in the `ios` directory : - Replace `YOUR_USERNAME` & `YOUR_ACCESS_KEY` with your BrowserStack access credentials @@ -89,7 +91,9 @@ Ensure that @ symbol is prepended to the file path in the above request. Please **Note**: If you do not have an .apk or .ipa file and are looking to simply try App Automate, you can download and test using our [sample Android Local app](https://www.browserstack.com/app-automate/sample-apps/android/LocalSample.apk) or [sample iOS Local app](https://www.browserstack.com/app-automate/sample-apps/ios/LocalSample.ipa). -**2. Open `BrowserStackAndroidLocal.java` file in the `android` directory or `BrowserStackiOSLocal.java` in the `ios` directory :** +**2. Configure and run your local test** + +Open `BrowserStackAndroidLocal.java` file in the `android` directory or `BrowserStackiOSLocal.java` in the `ios` directory : - Replace `YOUR_USERNAME` & `YOUR_ACCESS_KEY` with your BrowserStack access credentials From 2673193260239d61a9add2a3729be0e12f9b621d Mon Sep 17 00:00:00 2001 From: Neeraj Kumar Date: Fri, 25 Sep 2020 15:25:07 +0530 Subject: [PATCH 21/53] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 2c7724a..7ffeca4 100644 --- a/README.md +++ b/README.md @@ -101,6 +101,8 @@ Open `BrowserStackAndroidLocal.java` file in the `android` directory or `Browser - Set the device and OS version +- Ensure that `browserstack.local` capability is set to `true`. Within the test script, there is code snippet that automatically establishes Local Testing connection to BrowserStack servers using Java binding for BrowserStack Local. + - If you have uploaded your own app update the test case - To run the test, use the following command in the base directory : From c14a7912de69cc2146236094ab0c637894bff4e7 Mon Sep 17 00:00:00 2001 From: Neeraj Kumar Date: Sat, 26 Sep 2020 16:01:57 +0530 Subject: [PATCH 22/53] Updating class names according to QSG. Removing unwanted imports. --- pom.xml | 8 +++--- ...ckAndroid.java => BrowserStackSample.java} | 18 +++--------- ...ocal.java => BrowserStackSampleLocal.java} | 18 +++--------- ...rStackiOS.java => BrowserStackSample.java} | 16 +++-------- ...ocal.java => BrowserStackSampleLocal.java} | 28 +++++-------------- 5 files changed, 23 insertions(+), 65 deletions(-) rename src/test/java/android/{BrowserStackAndroid.java => BrowserStackSample.java} (81%) rename src/test/java/android/{BrowserStackAndroidLocal.java => BrowserStackSampleLocal.java} (88%) rename src/test/java/ios/{BrowserStackiOS.java => BrowserStackSample.java} (84%) rename src/test/java/ios/{BrowserStackiOSLocal.java => BrowserStackSampleLocal.java} (82%) diff --git a/pom.xml b/pom.xml index 838152f..74fc8bd 100644 --- a/pom.xml +++ b/pom.xml @@ -74,7 +74,7 @@ java - android.BrowserStackAndroid + android.BrowserStackSample test @@ -98,7 +98,7 @@ java - android.BrowserStackAndroidLocal + android.BrowserStackSampleLocal test @@ -122,7 +122,7 @@ java - ios.BrowserStackiOS + ios.BrowserStackSample test @@ -146,7 +146,7 @@ java - ios.BrowserStackiOSLocal + ios.BrowserStackSampleLocal test diff --git a/src/test/java/android/BrowserStackAndroid.java b/src/test/java/android/BrowserStackSample.java similarity index 81% rename from src/test/java/android/BrowserStackAndroid.java rename to src/test/java/android/BrowserStackSample.java index be1ac58..725150c 100644 --- a/src/test/java/android/BrowserStackAndroid.java +++ b/src/test/java/android/BrowserStackSample.java @@ -1,20 +1,10 @@ package android; -import java.net.URL; -import java.util.List; -import java.util.function.Function; -import java.net.MalformedURLException; +import java.net.*; import java.util.List; +import io.appium.java_client.*; import io.appium.java_client.android.*; +import org.openqa.selenium.support.ui.*; import org.openqa.selenium.remote.*; -import io.appium.java_client.MobileBy; -import io.appium.java_client.android.AndroidDriver; -import io.appium.java_client.android.AndroidElement; - -import org.openqa.selenium.support.ui.ExpectedConditions; -import org.openqa.selenium.support.ui.WebDriverWait; -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.remote.DesiredCapabilities; - -public class BrowserStackAndroid { +public class BrowserStackSample { public static void main(String[] args) throws MalformedURLException, InterruptedException { diff --git a/src/test/java/android/BrowserStackAndroidLocal.java b/src/test/java/android/BrowserStackSampleLocal.java similarity index 88% rename from src/test/java/android/BrowserStackAndroidLocal.java rename to src/test/java/android/BrowserStackSampleLocal.java index deb092a..cb6f71e 100644 --- a/src/test/java/android/BrowserStackAndroidLocal.java +++ b/src/test/java/android/BrowserStackSampleLocal.java @@ -1,21 +1,11 @@ package android; import com.browserstack.local.Local; +import java.net.URL; import java.util.*; +import io.appium.java_client.MobileBy; import io.appium.java_client.android.*; +import org.openqa.selenium.support.ui.*;import org.openqa.selenium.remote.*; -import java.net.URL; -import java.util.Map; -import java.util.List; -import java.util.HashMap; - -import io.appium.java_client.MobileBy; -import io.appium.java_client.android.AndroidDriver; -import io.appium.java_client.android.AndroidElement; - -import org.openqa.selenium.support.ui.ExpectedConditions; -import org.openqa.selenium.support.ui.WebDriverWait; -import org.openqa.selenium.remote.DesiredCapabilities; - -public class BrowserStackAndroidLocal { +public class BrowserStackSampleLocal { private static Local localInstance; public static String userName = "YOUR_USERNAME"; diff --git a/src/test/java/ios/BrowserStackiOS.java b/src/test/java/ios/BrowserStackSample.java similarity index 84% rename from src/test/java/ios/BrowserStackiOS.java rename to src/test/java/ios/BrowserStackSample.java index 3f3b392..dfb7a47 100644 --- a/src/test/java/ios/BrowserStackiOS.java +++ b/src/test/java/ios/BrowserStackSample.java @@ -1,18 +1,10 @@ package ios; -import java.net.URL; -import java.util.List; -import java.net.MalformedURLException; +import java.net.*; +import org.openqa.selenium.remote.*; import org.openqa.selenium.support.ui.*; +import io.appium.java_client.MobileBy;import io.appium.java_client.ios.*; -import org.openqa.selenium.support.ui.WebDriverWait; -import org.openqa.selenium.remote.DesiredCapabilities; -import org.openqa.selenium.support.ui.ExpectedConditions; - -import io.appium.java_client.MobileBy; -import io.appium.java_client.ios.IOSDriver; -import io.appium.java_client.ios.IOSElement; - -public class BrowserStackiOS { +public class BrowserStackSample { public static void main(String[] args) throws MalformedURLException, InterruptedException { DesiredCapabilities capabilities = new DesiredCapabilities(); diff --git a/src/test/java/ios/BrowserStackiOSLocal.java b/src/test/java/ios/BrowserStackSampleLocal.java similarity index 82% rename from src/test/java/ios/BrowserStackiOSLocal.java rename to src/test/java/ios/BrowserStackSampleLocal.java index e992434..4a6daf4 100644 --- a/src/test/java/ios/BrowserStackiOSLocal.java +++ b/src/test/java/ios/BrowserStackSampleLocal.java @@ -1,31 +1,17 @@ package ios; import com.browserstack.local.Local; - -import java.net.URL; -import java.io.File; -import java.util.Map; -import java.util.HashMap; +import java.net.URL; import java.io.File; import java.util.*; import org.apache.commons.io.FileUtils; +import io.appium.java_client.MobileBy; import io.appium.java_client.ios.*; +import org.openqa.selenium.*; +import org.openqa.selenium.support.ui.*;import org.openqa.selenium.remote.*; -import io.appium.java_client.MobileBy; -import io.appium.java_client.ios.IOSDriver; -import io.appium.java_client.ios.IOSElement; - -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.OutputType; -import org.openqa.selenium.TakesScreenshot; -import org.openqa.selenium.support.ui.WebDriverWait; -import org.openqa.selenium.remote.DesiredCapabilities; -import org.openqa.selenium.support.ui.ExpectedCondition; -import org.openqa.selenium.support.ui.ExpectedConditions; - - -public class BrowserStackiOSLocal { +public class BrowserStackSampleLocal { private static Local localInstance; - public static String accessKey = "YOUR_USERNAME"; - public static String userName = "YOUR_ACCESS_KEY"; + public static String userName = "YOUR_USERNAME"; + public static String accessKey = "YOUR_ACCESS_KEY"; public static void setupLocal() throws Exception { From d834fc4ff01f788d20543fc25cc23a99af1812b7 Mon Sep 17 00:00:00 2001 From: Neeraj Kumar Date: Sat, 26 Sep 2020 16:04:09 +0530 Subject: [PATCH 23/53] Updating Readme --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 7ffeca4..f955c5b 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ Ensure that @ symbol is prepended to the file path in the above request. Please **2. Configure and run your first test** -Open `BrowserStackAndroid.java` file in the `android` directory or `BrowserStackiOS.java` in the `ios` directory : +Open `BrowserStackSample.java` file in the `android` directory or `ios` directory : - Replace `YOUR_USERNAME` & `YOUR_ACCESS_KEY` with your BrowserStack access credentials @@ -93,7 +93,7 @@ Ensure that @ symbol is prepended to the file path in the above request. Please **2. Configure and run your local test** -Open `BrowserStackAndroidLocal.java` file in the `android` directory or `BrowserStackiOSLocal.java` in the `ios` directory : +Open `BrowserStackSampleLocal.java` file in the `android` or `ios` directory : - Replace `YOUR_USERNAME` & `YOUR_ACCESS_KEY` with your BrowserStack access credentials @@ -101,7 +101,7 @@ Open `BrowserStackAndroidLocal.java` file in the `android` directory or `Browser - Set the device and OS version -- Ensure that `browserstack.local` capability is set to `true`. Within the test script, there is code snippet that automatically establishes Local Testing connection to BrowserStack servers using Java binding for BrowserStack Local. +- Ensure that `browserstack.local` capability is set to `true`. Within the test script, there is code snippet that automatically establishes Local Testing connection to BrowserStack servers using Java binding for BrowserStack Local. - If you have uploaded your own app update the test case From 3d232d6dc0b64dd82bf26f3d4883e0fa50bde82a Mon Sep 17 00:00:00 2001 From: Neeraj Kumar Date: Wed, 30 Sep 2020 10:17:45 +0530 Subject: [PATCH 24/53] Reverting to previous imports for android and ios sample tests --- src/test/java/android/BrowserStackSample.java | 17 ++++++++++++++--- src/test/java/ios/BrowserStackSample.java | 14 +++++++++++--- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/test/java/android/BrowserStackSample.java b/src/test/java/android/BrowserStackSample.java index 725150c..e404a8a 100644 --- a/src/test/java/android/BrowserStackSample.java +++ b/src/test/java/android/BrowserStackSample.java @@ -1,8 +1,19 @@ package android; -import java.net.*; import java.util.List; -import io.appium.java_client.*; import io.appium.java_client.android.*; -import org.openqa.selenium.support.ui.*; import org.openqa.selenium.remote.*; +import java.net.URL; +import java.util.List; +import java.util.function.Function; +import java.net.MalformedURLException; + +import io.appium.java_client.MobileBy; +import io.appium.java_client.android.AndroidDriver; +import io.appium.java_client.android.AndroidElement; + +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.remote.DesiredCapabilities; + public class BrowserStackSample { diff --git a/src/test/java/ios/BrowserStackSample.java b/src/test/java/ios/BrowserStackSample.java index dfb7a47..79d5e9e 100644 --- a/src/test/java/ios/BrowserStackSample.java +++ b/src/test/java/ios/BrowserStackSample.java @@ -1,8 +1,16 @@ package ios; -import java.net.*; -import org.openqa.selenium.remote.*; import org.openqa.selenium.support.ui.*; -import io.appium.java_client.MobileBy;import io.appium.java_client.ios.*; +import java.net.URL; +import java.util.List; +import java.net.MalformedURLException; + +import org.openqa.selenium.support.ui.WebDriverWait; +import org.openqa.selenium.remote.DesiredCapabilities; +import org.openqa.selenium.support.ui.ExpectedConditions; + +import io.appium.java_client.MobileBy; +import io.appium.java_client.ios.IOSDriver; +import io.appium.java_client.ios.IOSElement; public class BrowserStackSample { From 60ecc209ef8398b9543806f3561f6f4ee8f650e3 Mon Sep 17 00:00:00 2001 From: Neeraj Kumar Date: Thu, 1 Oct 2020 13:07:12 +0530 Subject: [PATCH 25/53] changing 'capabilities' to 'caps' --- src/test/java/android/BrowserStackSample.java | 20 +++++++++---------- src/test/java/ios/BrowserStackSample.java | 20 +++++++++---------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/test/java/android/BrowserStackSample.java b/src/test/java/android/BrowserStackSample.java index e404a8a..4deea4f 100644 --- a/src/test/java/android/BrowserStackSample.java +++ b/src/test/java/android/BrowserStackSample.java @@ -19,29 +19,29 @@ public class BrowserStackSample { public static void main(String[] args) throws MalformedURLException, InterruptedException { - DesiredCapabilities capabilities = new DesiredCapabilities(); + DesiredCapabilities caps = new DesiredCapabilities(); // Set your access credentials - capabilities.setCapability("browserstack.user", "YOUR_USERNAME"); - capabilities.setCapability("browserstack.key", "YOUR_ACCESS_KEY"); + caps.setCapability("browserstack.user", "YOUR_USERNAME"); + caps.setCapability("browserstack.key", "YOUR_ACCESS_KEY"); // Set URL of the application under test - capabilities.setCapability("app", "bs://"); + caps.setCapability("app", "bs://"); // Specify device and os_version for testing - capabilities.setCapability("device", "Google Pixel 3"); - capabilities.setCapability("os_version", "9.0"); + caps.setCapability("device", "Google Pixel 3"); + caps.setCapability("os_version", "9.0"); // Set other BrowserStack capabilities - capabilities.setCapability("project", "First Java Project"); - capabilities.setCapability("build", "Java Android"); - capabilities.setCapability("name", "first_test"); + caps.setCapability("project", "First Java Project"); + caps.setCapability("build", "Java Android"); + caps.setCapability("name", "first_test"); // Initialise the remote Webdriver using BrowserStack remote URL // and desired capabilities defined above AndroidDriver driver = new AndroidDriver( - new URL("http://hub.browserstack.com/wd/hub"), capabilities); + new URL("http://hub.browserstack.com/wd/hub"), caps); // Test case for the BrowserStack sample Android app. diff --git a/src/test/java/ios/BrowserStackSample.java b/src/test/java/ios/BrowserStackSample.java index 79d5e9e..841a807 100644 --- a/src/test/java/ios/BrowserStackSample.java +++ b/src/test/java/ios/BrowserStackSample.java @@ -15,29 +15,29 @@ public class BrowserStackSample { public static void main(String[] args) throws MalformedURLException, InterruptedException { - DesiredCapabilities capabilities = new DesiredCapabilities(); + DesiredCapabilities caps = new DesiredCapabilities(); // Set your access credentials - capabilities.setCapability("browserstack.user", "YOUR_USERNAME"); - capabilities.setCapability("browserstack.key", "YOUR_ACCESS_KEY"); + caps.setCapability("browserstack.user", "YOUR_USERNAME"); + caps.setCapability("browserstack.key", "YOUR_ACCESS_KEY"); // Set URL of the application under test - capabilities.setCapability("app", "bs://"); + caps.setCapability("app", "bs://"); // Specify device and os_version for testing - capabilities.setCapability("device", "iPhone 11 Pro"); - capabilities.setCapability("os_version", "13"); + caps.setCapability("device", "iPhone 11 Pro"); + caps.setCapability("os_version", "13"); // Set other BrowserStack capabilities - capabilities.setCapability("project", "First Java Project"); - capabilities.setCapability("build", "Java iOS"); - capabilities.setCapability("name", "first_test"); + caps.setCapability("project", "First Java Project"); + caps.setCapability("build", "Java iOS"); + caps.setCapability("name", "first_test"); // Initialise the remote Webdriver using BrowserStack remote URL // and desired capabilities defined above IOSDriver driver = new IOSDriver( - new URL("http://hub-cloud.browserstack.com/wd/hub"), capabilities); + new URL("http://hub-cloud.browserstack.com/wd/hub"), caps); // Test case for the BrowserStack sample iOS app. From e7f7f02453d38b238f5082bdcea7f7b1de05212d Mon Sep 17 00:00:00 2001 From: Neeraj Kumar Date: Thu, 1 Oct 2020 18:54:01 +0530 Subject: [PATCH 26/53] Adding Access credentials URL for convenience. --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f955c5b..c8321a1 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ Ensure that @ symbol is prepended to the file path in the above request. Please Open `BrowserStackSample.java` file in the `android` directory or `ios` directory : -- Replace `YOUR_USERNAME` & `YOUR_ACCESS_KEY` with your BrowserStack access credentials +- Replace `YOUR_USERNAME` & `YOUR_ACCESS_KEY` with your BrowserStack access credentials. Get your BrowserStack access credentials from [here](https://www.browserstack.com/accounts/settings) - Replace `bs://` with the URL obtained from app upload step @@ -95,7 +95,7 @@ Ensure that @ symbol is prepended to the file path in the above request. Please Open `BrowserStackSampleLocal.java` file in the `android` or `ios` directory : -- Replace `YOUR_USERNAME` & `YOUR_ACCESS_KEY` with your BrowserStack access credentials +- Replace `YOUR_USERNAME` & `YOUR_ACCESS_KEY` with your BrowserStack access credentials. Get your BrowserStack access credentials from [here](https://www.browserstack.com/accounts/settings) - Replace `bs://` with the URL obtained from app upload step From db95171b5c330734c14c31864ac2fc2b0074a557 Mon Sep 17 00:00:00 2001 From: Nitish Bhardwaj Date: Mon, 20 Sep 2021 16:46:27 +0530 Subject: [PATCH 27/53] Updated build names as per QIG --- src/test/java/android/BrowserStackSample.java | 2 +- src/test/java/android/BrowserStackSampleLocal.java | 2 +- src/test/java/ios/BrowserStackSample.java | 2 +- src/test/java/ios/BrowserStackSampleLocal.java | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/test/java/android/BrowserStackSample.java b/src/test/java/android/BrowserStackSample.java index 4deea4f..136ee81 100644 --- a/src/test/java/android/BrowserStackSample.java +++ b/src/test/java/android/BrowserStackSample.java @@ -34,7 +34,7 @@ public static void main(String[] args) throws MalformedURLException, Interrupted // Set other BrowserStack capabilities caps.setCapability("project", "First Java Project"); - caps.setCapability("build", "Java Android"); + caps.setCapability("build", "browserstack-build-1"); caps.setCapability("name", "first_test"); diff --git a/src/test/java/android/BrowserStackSampleLocal.java b/src/test/java/android/BrowserStackSampleLocal.java index cb6f71e..0854db1 100644 --- a/src/test/java/android/BrowserStackSampleLocal.java +++ b/src/test/java/android/BrowserStackSampleLocal.java @@ -45,7 +45,7 @@ public static void main(String[] args) throws Exception { // Set other BrowserStack capabilities capabilities.setCapability("project", "First Java Project"); - capabilities.setCapability("build", "Java Android Local"); + capabilities.setCapability("build", "browserstack-build-1"); capabilities.setCapability("name", "local_test"); diff --git a/src/test/java/ios/BrowserStackSample.java b/src/test/java/ios/BrowserStackSample.java index 841a807..6fd9eea 100644 --- a/src/test/java/ios/BrowserStackSample.java +++ b/src/test/java/ios/BrowserStackSample.java @@ -30,7 +30,7 @@ public static void main(String[] args) throws MalformedURLException, Interrupted // Set other BrowserStack capabilities caps.setCapability("project", "First Java Project"); - caps.setCapability("build", "Java iOS"); + caps.setCapability("build", "browserstack-build-1"); caps.setCapability("name", "first_test"); diff --git a/src/test/java/ios/BrowserStackSampleLocal.java b/src/test/java/ios/BrowserStackSampleLocal.java index 4a6daf4..f278a07 100644 --- a/src/test/java/ios/BrowserStackSampleLocal.java +++ b/src/test/java/ios/BrowserStackSampleLocal.java @@ -48,7 +48,7 @@ public static void main(String[] args) throws Exception { // Set other BrowserStack capabilities capabilities.setCapability("project", "First Java Project"); - capabilities.setCapability("build", "Java iOS Local"); + capabilities.setCapability("build", "browserstack-build-1"); capabilities.setCapability("name", "local_test"); // Initialise the remote Webdriver using BrowserStack remote URL From 3e7d33bee365587cda70bf66b39c7d26cbdbd0e2 Mon Sep 17 00:00:00 2001 From: Abhishek Jha <21086203+innovater21@users.noreply.github.com> Date: Thu, 10 Mar 2022 20:34:28 +0530 Subject: [PATCH 28/53] Added support for java-client 8.0.0 --- src/test/java/android/BrowserStackSample.java | 26 +++++++++---------- .../java/android/BrowserStackSampleLocal.java | 26 +++++++++++-------- src/test/java/ios/BrowserStackSample.java | 21 ++++++++------- .../java/ios/BrowserStackSampleLocal.java | 18 ++++++++----- 4 files changed, 50 insertions(+), 41 deletions(-) diff --git a/src/test/java/android/BrowserStackSample.java b/src/test/java/android/BrowserStackSample.java index 136ee81..fba3e2e 100644 --- a/src/test/java/android/BrowserStackSample.java +++ b/src/test/java/android/BrowserStackSample.java @@ -5,15 +5,15 @@ import java.util.function.Function; import java.net.MalformedURLException; -import io.appium.java_client.MobileBy; -import io.appium.java_client.android.AndroidDriver; -import io.appium.java_client.android.AndroidElement; - import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.WebDriverWait; -import org.openqa.selenium.WebDriver; import org.openqa.selenium.remote.DesiredCapabilities; +import io.appium.java_client.AppiumBy; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.remote.RemoteWebDriver; + public class BrowserStackSample { @@ -40,23 +40,23 @@ public static void main(String[] args) throws MalformedURLException, Interrupted // Initialise the remote Webdriver using BrowserStack remote URL // and desired capabilities defined above - AndroidDriver driver = new AndroidDriver( + RemoteWebDriver driver = new RemoteWebDriver( new URL("http://hub.browserstack.com/wd/hub"), caps); - + // Test case for the BrowserStack sample Android app. // If you have uploaded your app, update the test case here. - AndroidElement searchElement = (AndroidElement) new WebDriverWait(driver, 30).until( + WebElement searchElement = (WebElement) new WebDriverWait(driver, 30).until( ExpectedConditions.elementToBeClickable( - MobileBy.AccessibilityId("Search Wikipedia"))); + AppiumBy.accessibilityId("Search Wikipedia"))); searchElement.click(); - AndroidElement insertTextElement = (AndroidElement) new WebDriverWait(driver, 30).until( + WebElement insertTextElement = (WebElement) new WebDriverWait(driver, 30).until( ExpectedConditions.elementToBeClickable( - MobileBy.id("org.wikipedia.alpha:id/search_src_text"))); + AppiumBy.id("org.wikipedia.alpha:id/search_src_text"))); insertTextElement.sendKeys("BrowserStack"); Thread.sleep(5000); - List allProductsName = driver.findElementsByClassName( - "android.widget.TextView"); + List allProductsName = driver.findElements(AppiumBy.className("android.widget.TextView")); + assert(allProductsName.size() > 0); diff --git a/src/test/java/android/BrowserStackSampleLocal.java b/src/test/java/android/BrowserStackSampleLocal.java index 0854db1..c977af5 100644 --- a/src/test/java/android/BrowserStackSampleLocal.java +++ b/src/test/java/android/BrowserStackSampleLocal.java @@ -2,8 +2,13 @@ import com.browserstack.local.Local; import java.net.URL; import java.util.*; -import io.appium.java_client.MobileBy; import io.appium.java_client.android.*; -import org.openqa.selenium.support.ui.*;import org.openqa.selenium.remote.*; +import io.appium.java_client.android.*; +import org.openqa.selenium.support.ui.*; +import org.openqa.selenium.remote.*; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.remote.RemoteWebDriver; public class BrowserStackSampleLocal { @@ -51,21 +56,20 @@ public static void main(String[] args) throws Exception { // Initialise the remote Webdriver using BrowserStack remote URL // and desired capabilities defined above - AndroidDriver driver = new AndroidDriver( - new URL("http://hub.browserstack.com/wd/hub"), capabilities); + RemoteWebDriver driver = new RemoteWebDriver(new URL("http://hub.browserstack.com/wd/hub"), capabilities); // Test case for the BrowserStack sample Android Local app. // If you have uploaded your app, update the test case here. - AndroidElement searchElement = (AndroidElement) new WebDriverWait(driver, 30).until( - ExpectedConditions.elementToBeClickable(MobileBy.id("com.example.android.basicnetworking:id/test_action"))); + WebElement searchElement = new WebDriverWait(driver, 30).until( + ExpectedConditions.elementToBeClickable(By.id("com.example.android.basicnetworking:id/test_action"))); searchElement.click(); - AndroidElement insertTextElement = (AndroidElement) new WebDriverWait(driver, 30).until( - ExpectedConditions.elementToBeClickable(MobileBy.className("android.widget.TextView"))); + WebElement insertTextElement = (WebElement) new WebDriverWait(driver, 30).until( + ExpectedConditions.elementToBeClickable(By.className("android.widget.TextView"))); - AndroidElement testElement = null; - List allTextViewElements = driver.findElementsByClassName("android.widget.TextView"); + WebElement testElement = null; + List allTextViewElements = driver.findElements(By.className("android.widget.TextView")); Thread.sleep(10); - for(AndroidElement textElement : allTextViewElements) { + for(WebElement textElement : allTextViewElements) { if(textElement.getText().contains("The active connection is")) { testElement = textElement; } diff --git a/src/test/java/ios/BrowserStackSample.java b/src/test/java/ios/BrowserStackSample.java index 6fd9eea..ca09d8b 100644 --- a/src/test/java/ios/BrowserStackSample.java +++ b/src/test/java/ios/BrowserStackSample.java @@ -8,9 +8,10 @@ import org.openqa.selenium.remote.DesiredCapabilities; import org.openqa.selenium.support.ui.ExpectedConditions; -import io.appium.java_client.MobileBy; -import io.appium.java_client.ios.IOSDriver; -import io.appium.java_client.ios.IOSElement; +import io.appium.java_client.AppiumBy; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.remote.RemoteWebDriver; public class BrowserStackSample { @@ -36,21 +37,21 @@ public static void main(String[] args) throws MalformedURLException, Interrupted // Initialise the remote Webdriver using BrowserStack remote URL // and desired capabilities defined above - IOSDriver driver = new IOSDriver( + RemoteWebDriver driver = new RemoteWebDriver( new URL("http://hub-cloud.browserstack.com/wd/hub"), caps); // Test case for the BrowserStack sample iOS app. // If you have uploaded your app, update the test case here. - IOSElement textButton = (IOSElement) new WebDriverWait(driver, 30).until( - ExpectedConditions.elementToBeClickable(MobileBy.AccessibilityId("Text Button"))); + WebElement textButton = (WebElement) new WebDriverWait(driver, 30).until( + ExpectedConditions.elementToBeClickable(AppiumBy.accessibilityId("Text Button"))); textButton.click(); - IOSElement textInput = (IOSElement) new WebDriverWait(driver, 30).until( - ExpectedConditions.elementToBeClickable(MobileBy.AccessibilityId("Text Input"))); + WebElement textInput = (WebElement) new WebDriverWait(driver, 30).until( + ExpectedConditions.elementToBeClickable(AppiumBy.accessibilityId("Text Input"))); textInput.sendKeys("hello@browserstack.com"); Thread.sleep(5000); - IOSElement textOutput = (IOSElement) new WebDriverWait(driver, 30).until( - ExpectedConditions.elementToBeClickable(MobileBy.AccessibilityId("Text Output"))); + WebElement textOutput = (WebElement) new WebDriverWait(driver, 30).until( + ExpectedConditions.elementToBeClickable(AppiumBy.accessibilityId("Text Output"))); if(textOutput != null && textOutput.getText().equals("hello@browserstack.com")) assert(true); else diff --git a/src/test/java/ios/BrowserStackSampleLocal.java b/src/test/java/ios/BrowserStackSampleLocal.java index f278a07..4663f1b 100644 --- a/src/test/java/ios/BrowserStackSampleLocal.java +++ b/src/test/java/ios/BrowserStackSampleLocal.java @@ -3,9 +3,13 @@ import com.browserstack.local.Local; import java.net.URL; import java.io.File; import java.util.*; import org.apache.commons.io.FileUtils; -import io.appium.java_client.MobileBy; import io.appium.java_client.ios.*; +import io.appium.java_client.ios.*; import org.openqa.selenium.*; import org.openqa.selenium.support.ui.*;import org.openqa.selenium.remote.*; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.remote.RemoteWebDriver; public class BrowserStackSampleLocal { @@ -53,24 +57,24 @@ public static void main(String[] args) throws Exception { // Initialise the remote Webdriver using BrowserStack remote URL // and desired capabilities defined above - IOSDriver driver = new IOSDriver( + RemoteWebDriver driver = new RemoteWebDriver( new URL("http://hub.browserstack.com/wd/hub"), capabilities); // Test case for the BrowserStack sample iOS Local app. // If you have uploaded your app, update the test case here. - IOSElement testButton = (IOSElement) new WebDriverWait(driver, 30).until( - ExpectedConditions.elementToBeClickable(MobileBy.AccessibilityId("TestBrowserStackLocal"))); + WebElement testButton = (WebElement) new WebDriverWait(driver, 30).until( + ExpectedConditions.elementToBeClickable(By.xpath("//*[@content-desc='TestBrowserStackLocal']"))); testButton.click(); - + WebDriverWait wait = new WebDriverWait(driver, 30); wait.until(new ExpectedCondition() { @Override public Boolean apply(WebDriver d) { - String result = d.findElement(MobileBy.AccessibilityId("ResultBrowserStackLocal")).getAttribute("value"); + String result = d.findElement(By.xpath("//*[@content-desc='ResultBrowserStackLocal']")).getAttribute("value"); return result != null && result.length() > 0; } }); - IOSElement resultElement = (IOSElement) driver.findElement(MobileBy.AccessibilityId("ResultBrowserStackLocal")); + WebElement resultElement = (WebElement) driver.findElement(By.xpath("//*[@content-desc='ResultBrowserStackLocal']")); String resultString = resultElement.getText().toLowerCase(); System.out.println(resultString); From 10120bb0ec87e4932beb2e1b835ad446c0b0931b Mon Sep 17 00:00:00 2001 From: Abhishek Jha <21086203+innovater21@users.noreply.github.com> Date: Fri, 11 Mar 2022 10:57:03 +0530 Subject: [PATCH 29/53] Updated java-client version to 8.0.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 74fc8bd..300166e 100644 --- a/pom.xml +++ b/pom.xml @@ -25,7 +25,7 @@ io.appium java-client - 7.0.0 + 8.0.0 com.browserstack From c1b2e32b1ddede09dadf5bb42f857d81ee0181e6 Mon Sep 17 00:00:00 2001 From: Abhishek Jha <21086203+innovater21@users.noreply.github.com> Date: Fri, 11 Mar 2022 14:58:55 +0530 Subject: [PATCH 30/53] added w3c capabilities --- src/test/java/android/BrowserStackSample.java | 25 ++++++++----------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/src/test/java/android/BrowserStackSample.java b/src/test/java/android/BrowserStackSample.java index fba3e2e..6559904 100644 --- a/src/test/java/android/BrowserStackSample.java +++ b/src/test/java/android/BrowserStackSample.java @@ -5,15 +5,14 @@ import java.util.function.Function; import java.net.MalformedURLException; -import org.openqa.selenium.support.ui.ExpectedConditions; -import org.openqa.selenium.support.ui.WebDriverWait; -import org.openqa.selenium.remote.DesiredCapabilities; - import io.appium.java_client.AppiumBy; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.remote.RemoteWebDriver; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; +import org.openqa.selenium.remote.DesiredCapabilities; public class BrowserStackSample { @@ -23,26 +22,24 @@ public static void main(String[] args) throws MalformedURLException, Interrupted // Set your access credentials caps.setCapability("browserstack.user", "YOUR_USERNAME"); - caps.setCapability("browserstack.key", "YOUR_ACCESS_KEY"); + caps.setCapability("browserstack.key", "YOUR_ACCESS_KEY"); // Set URL of the application under test caps.setCapability("app", "bs://"); - // Specify device and os_version for testing - caps.setCapability("device", "Google Pixel 3"); - caps.setCapability("os_version", "9.0"); + // Specify deviceName and platformName for testing + caps.setCapability("deviceName", "Google Pixel 3"); + caps.setCapability("platformName", "android"); + caps.setCapability("platformVersion", "9.0"); // Set other BrowserStack capabilities caps.setCapability("project", "First Java Project"); caps.setCapability("build", "browserstack-build-1"); caps.setCapability("name", "first_test"); - // Initialise the remote Webdriver using BrowserStack remote URL // and desired capabilities defined above - RemoteWebDriver driver = new RemoteWebDriver( - new URL("http://hub.browserstack.com/wd/hub"), caps); - + RemoteWebDriver driver = new RemoteWebDriver(new URL("http://hub.browserstack.com/wd/hub"), caps); // Test case for the BrowserStack sample Android app. // If you have uploaded your app, update the test case here. @@ -50,16 +47,16 @@ public static void main(String[] args) throws MalformedURLException, Interrupted ExpectedConditions.elementToBeClickable( AppiumBy.accessibilityId("Search Wikipedia"))); searchElement.click(); + WebElement insertTextElement = (WebElement) new WebDriverWait(driver, 30).until( ExpectedConditions.elementToBeClickable( AppiumBy.id("org.wikipedia.alpha:id/search_src_text"))); insertTextElement.sendKeys("BrowserStack"); Thread.sleep(5000); + List allProductsName = driver.findElements(AppiumBy.className("android.widget.TextView")); - assert(allProductsName.size() > 0); - // Invoke driver.quit() after the test is done to indicate that the test is completed. driver.quit(); From 15c4e051db867946882d617de3d9678fd3e430a0 Mon Sep 17 00:00:00 2001 From: Abhishek Jha <21086203+innovater21@users.noreply.github.com> Date: Fri, 11 Mar 2022 15:00:32 +0530 Subject: [PATCH 31/53] added w3c capabilities --- src/test/java/ios/BrowserStackSample.java | 46 +++++++++++------------ 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/src/test/java/ios/BrowserStackSample.java b/src/test/java/ios/BrowserStackSample.java index ca09d8b..2efee79 100644 --- a/src/test/java/ios/BrowserStackSample.java +++ b/src/test/java/ios/BrowserStackSample.java @@ -16,50 +16,50 @@ public class BrowserStackSample { public static void main(String[] args) throws MalformedURLException, InterruptedException { - DesiredCapabilities caps = new DesiredCapabilities(); - - // Set your access credentials - caps.setCapability("browserstack.user", "YOUR_USERNAME"); - caps.setCapability("browserstack.key", "YOUR_ACCESS_KEY"); + + DesiredCapabilities caps = new DesiredCapabilities(); + + // Set your access credentials + caps.setCapability("browserstack.user", "YOUR_USERNAME"); + caps.setCapability("browserstack.key", "YOUR_ACCESS_KEY"); // Set URL of the application under test caps.setCapability("app", "bs://"); - - // Specify device and os_version for testing - caps.setCapability("device", "iPhone 11 Pro"); - caps.setCapability("os_version", "13"); - // Set other BrowserStack capabilities - caps.setCapability("project", "First Java Project"); - caps.setCapability("build", "browserstack-build-1"); - caps.setCapability("name", "first_test"); - - - // Initialise the remote Webdriver using BrowserStack remote URL - // and desired capabilities defined above + // Specify device and os_version for testing + caps.setCapability("deviceName", "iPhone 11 Pro"); + caps.setCapability("platformName", "ios"); + caps.setCapability("platformVersion", "13"); + + // Set other BrowserStack capabilities + caps.setCapability("project", "First Java Project"); + caps.setCapability("build", "browserstack-build-1"); + caps.setCapability("name", "first_test"); + + // Initialise the remote Webdriver using BrowserStack remote URL + // and desired capabilities defined above RemoteWebDriver driver = new RemoteWebDriver( - new URL("http://hub-cloud.browserstack.com/wd/hub"), caps); + new URL("http://hub-cloud.browserstack.com/wd/hub"), caps); - // Test case for the BrowserStack sample iOS app. // If you have uploaded your app, update the test case here. WebElement textButton = (WebElement) new WebDriverWait(driver, 30).until( ExpectedConditions.elementToBeClickable(AppiumBy.accessibilityId("Text Button"))); textButton.click(); + WebElement textInput = (WebElement) new WebDriverWait(driver, 30).until( ExpectedConditions.elementToBeClickable(AppiumBy.accessibilityId("Text Input"))); textInput.sendKeys("hello@browserstack.com"); Thread.sleep(5000); + WebElement textOutput = (WebElement) new WebDriverWait(driver, 30).until( ExpectedConditions.elementToBeClickable(AppiumBy.accessibilityId("Text Output"))); if(textOutput != null && textOutput.getText().equals("hello@browserstack.com")) assert(true); else assert(false); - + // Invoke driver.quit() after the test is done to indicate that the test is completed. driver.quit(); - - } - + } } From 8073b7f6726bfb23d5a24453800ec2f91f439149 Mon Sep 17 00:00:00 2001 From: Abhishek Jha <21086203+innovater21@users.noreply.github.com> Date: Fri, 11 Mar 2022 16:13:39 +0530 Subject: [PATCH 32/53] Added w3c capabilities and support --- .../java/android/BrowserStackSampleLocal.java | 154 ++++++++++-------- 1 file changed, 83 insertions(+), 71 deletions(-) diff --git a/src/test/java/android/BrowserStackSampleLocal.java b/src/test/java/android/BrowserStackSampleLocal.java index c977af5..33a88eb 100644 --- a/src/test/java/android/BrowserStackSampleLocal.java +++ b/src/test/java/android/BrowserStackSampleLocal.java @@ -1,26 +1,26 @@ package android; import com.browserstack.local.Local; -import java.net.URL; import java.util.*; -import io.appium.java_client.android.*; -import org.openqa.selenium.support.ui.*; -import org.openqa.selenium.remote.*; -import org.openqa.selenium.By; -import org.openqa.selenium.WebDriver; +import io.appium.java_client.AppiumBy; +import java.net.URL; +import java.time.Duration; +import java.util.*; import org.openqa.selenium.WebElement; +import org.openqa.selenium.remote.*; import org.openqa.selenium.remote.RemoteWebDriver; +import org.openqa.selenium.support.ui.*; public class BrowserStackSampleLocal { - + private static Local localInstance; public static String userName = "YOUR_USERNAME"; public static String accessKey = "YOUR_ACCESS_KEY"; - public static void setupLocal() throws Exception { localInstance = new Local(); Map options = new HashMap(); options.put("key", accessKey); + options.put("local", "true"); localInstance.start(options); } @@ -28,67 +28,79 @@ public static void tearDownLocal() throws Exception { localInstance.stop(); } - public static void main(String[] args) throws Exception { - // Start the BrowserStack Local binary - setupLocal(); - - DesiredCapabilities capabilities = new DesiredCapabilities(); - - // Set your access credentials - capabilities.setCapability("browserstack.user", userName); - capabilities.setCapability("browserstack.key", accessKey); - - // Set URL of the application under test - capabilities.setCapability("app", "bs://"); - - // Specify device and os_version for testing - capabilities.setCapability("device", "Google Pixel 3"); - capabilities.setCapability("os_version", "9.0"); - - // Set the browserstack.local capability to true - capabilities.setCapability("browserstack.local", true); - - // Set other BrowserStack capabilities - capabilities.setCapability("project", "First Java Project"); - capabilities.setCapability("build", "browserstack-build-1"); - capabilities.setCapability("name", "local_test"); - - - // Initialise the remote Webdriver using BrowserStack remote URL - // and desired capabilities defined above - RemoteWebDriver driver = new RemoteWebDriver(new URL("http://hub.browserstack.com/wd/hub"), capabilities); - - // Test case for the BrowserStack sample Android Local app. - // If you have uploaded your app, update the test case here. - WebElement searchElement = new WebDriverWait(driver, 30).until( - ExpectedConditions.elementToBeClickable(By.id("com.example.android.basicnetworking:id/test_action"))); - searchElement.click(); - WebElement insertTextElement = (WebElement) new WebDriverWait(driver, 30).until( - ExpectedConditions.elementToBeClickable(By.className("android.widget.TextView"))); - - WebElement testElement = null; - List allTextViewElements = driver.findElements(By.className("android.widget.TextView")); - Thread.sleep(10); - for(WebElement textElement : allTextViewElements) { - if(textElement.getText().contains("The active connection is")) { - testElement = textElement; - } - } - - if(testElement == null) { - throw new Error("Cannot find the needed TextView element from app"); - } - String matchedString = testElement.getText(); - System.out.println(matchedString); - assert(matchedString.contains("The active connection is wifi")); - assert(matchedString.contains("Up and running")); - - // Invoke driver.quit() after the test is done to indicate that the test is completed. - driver.quit(); - - // Stop the BrowserStack Local binary - tearDownLocal(); - - } - + public static void main(String[] args) throws Exception { + // Start the BrowserStack Local binary + setupLocal(); + + DesiredCapabilities capabilities = new DesiredCapabilities(); + + // Set your access credentials + capabilities.setCapability("browserstack.user", userName); + capabilities.setCapability("browserstack.key", accessKey); + + // Set URL of the application under test + capabilities.setCapability("app", "bs://"); + + // Specify device and os_version for testing + capabilities.setCapability("deviceName", "Google Pixel 3"); + capabilities.setCapability("platformName", "android"); + capabilities.setCapability("platformVersion", "9.0"); + + // Set other BrowserStack capabilities + capabilities.setCapability("project", "First Java Project"); + capabilities.setCapability("build", "browserstack-build-1"); + capabilities.setCapability("name", "local_test"); + + // Initialise the remote Webdriver using BrowserStack remote URL + // and desired capabilities defined above + RemoteWebDriver driver = new RemoteWebDriver( + new URL("http://hub.browserstack.com/wd/hub"), + capabilities + ); + + // Test case for the BrowserStack sample Android Local app. + // If you have uploaded your app, update the test case here. + WebElement searchElement = new WebDriverWait(driver, Duration.ofSeconds(30)) + .until( + ExpectedConditions.elementToBeClickable( + AppiumBy.id("com.example.android.basicnetworking:id/test_action") + ) + ); + searchElement.click(); + + WebElement insertTextElement = (WebElement) new WebDriverWait( + driver, + Duration.ofSeconds(30) + ) + .until( + ExpectedConditions.elementToBeClickable( + AppiumBy.className("android.widget.TextView") + ) + ); + + WebElement testElement = null; + List allTextViewElements = driver.findElements( + AppiumBy.className("android.widget.TextView") + ); + Thread.sleep(10); + for (WebElement textElement : allTextViewElements) { + if (textElement.getText().contains("The active connection is")) { + testElement = textElement; + } + } + + if (testElement == null) { + throw new Error("Cannot find the needed TextView element from app"); + } + String matchedString = testElement.getText(); + System.out.println(matchedString); + assert (matchedString.contains("The active connection is wifi")); + assert (matchedString.contains("Up and running")); + + // Invoke driver.quit() after the test is done to indicate that the test is completed. + driver.quit(); + + // Stop the BrowserStack Local binary + tearDownLocal(); + } } From 680d0701ae9ce69129fccacb875e358a82d7a544 Mon Sep 17 00:00:00 2001 From: Abhishek Jha <21086203+innovater21@users.noreply.github.com> Date: Fri, 11 Mar 2022 16:19:59 +0530 Subject: [PATCH 33/53] added support for w3c and upgrade --- .../java/ios/BrowserStackSampleLocal.java | 187 ++++++++++-------- 1 file changed, 106 insertions(+), 81 deletions(-) diff --git a/src/test/java/ios/BrowserStackSampleLocal.java b/src/test/java/ios/BrowserStackSampleLocal.java index 4663f1b..d1b1521 100644 --- a/src/test/java/ios/BrowserStackSampleLocal.java +++ b/src/test/java/ios/BrowserStackSampleLocal.java @@ -1,99 +1,124 @@ package ios; import com.browserstack.local.Local; -import java.net.URL; import java.io.File; import java.util.*; +import io.appium.java_client.AppiumBy; +import java.io.File; +import java.net.URL; +import java.time.Duration; +import java.util.*; import org.apache.commons.io.FileUtils; -import io.appium.java_client.ios.*; import org.openqa.selenium.*; -import org.openqa.selenium.support.ui.*;import org.openqa.selenium.remote.*; -import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; +import org.openqa.selenium.remote.*; import org.openqa.selenium.remote.RemoteWebDriver; +import org.openqa.selenium.support.ui.*; public class BrowserStackSampleLocal { - - private static Local localInstance; - public static String userName = "YOUR_USERNAME"; - public static String accessKey = "YOUR_ACCESS_KEY"; - - - public static void setupLocal() throws Exception { - localInstance = new Local(); - Map options = new HashMap(); - options.put("key", accessKey); - localInstance.start(options); - } - public static void tearDownLocal() throws Exception { - localInstance.stop(); - } + private static Local localInstance; + public static String userName = "YOUR_USERNAME"; + public static String accessKey = "YOUR_ACCESS_KEY"; + + public static void setupLocal() throws Exception { + localInstance = new Local(); + Map options = new HashMap(); + options.put("key", accessKey); + options.put("local", "true"); + localInstance.start(options); + } + + public static void tearDownLocal() throws Exception { + localInstance.stop(); + } + + public static void main(String[] args) throws Exception { + // Start the BrowserStack Local binary + setupLocal(); + + DesiredCapabilities capabilities = new DesiredCapabilities(); + + // Set your access credentials + capabilities.setCapability("browserstack.user", userName); + capabilities.setCapability("browserstack.key", accessKey); + // Set URL of the application under test + capabilities.setCapability("app", ""); - public static void main(String[] args) throws Exception { - // Start the BrowserStack Local binary - setupLocal(); - - DesiredCapabilities capabilities = new DesiredCapabilities(); - - // Set your access credentials - capabilities.setCapability("browserstack.user", userName); - capabilities.setCapability("browserstack.key", accessKey); - - // Set URL of the application under test - capabilities.setCapability("app", "bs://"); - - // Specify device and os_version for testing - capabilities.setCapability("device", "iPhone 11 Pro"); - capabilities.setCapability("os_version", "13"); - - // Set the browserstack.local capability to true - capabilities.setCapability("browserstack.local", true); - - // Set other BrowserStack capabilities - capabilities.setCapability("project", "First Java Project"); - capabilities.setCapability("build", "browserstack-build-1"); - capabilities.setCapability("name", "local_test"); - - // Initialise the remote Webdriver using BrowserStack remote URL - // and desired capabilities defined above - RemoteWebDriver driver = new RemoteWebDriver( - new URL("http://hub.browserstack.com/wd/hub"), capabilities); - - // Test case for the BrowserStack sample iOS Local app. - // If you have uploaded your app, update the test case here. - WebElement testButton = (WebElement) new WebDriverWait(driver, 30).until( - ExpectedConditions.elementToBeClickable(By.xpath("//*[@content-desc='TestBrowserStackLocal']"))); - testButton.click(); - - WebDriverWait wait = new WebDriverWait(driver, 30); - wait.until(new ExpectedCondition() { - @Override - public Boolean apply(WebDriver d) { - String result = d.findElement(By.xpath("//*[@content-desc='ResultBrowserStackLocal']")).getAttribute("value"); - return result != null && result.length() > 0; - } - }); - WebElement resultElement = (WebElement) driver.findElement(By.xpath("//*[@content-desc='ResultBrowserStackLocal']")); - - String resultString = resultElement.getText().toLowerCase(); - System.out.println(resultString); - if(resultString.contains("not working")) { - File scrFile = (File) ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE); - FileUtils.copyFile(scrFile, new File(System.getProperty("user.dir") + "/screenshot.png")); - System.out.println("Screenshot stored at " + System.getProperty("user.dir") + "/screenshot.png"); - throw new Error("Unexpected BrowserStackLocal test result"); + // Specify device and os_version for testing + capabilities.setCapability("deviceName", "iPhone 11 Pro"); + capabilities.setCapability("platformName", "ios"); + capabilities.setCapability("platformVersion", "13"); + + // Set the browserstack.local capability to true + capabilities.setCapability("browserstack.local", true); + + // Set other BrowserStack capabilities + capabilities.setCapability("project", "First Java Project"); + capabilities.setCapability("build", "browserstack-build-1"); + capabilities.setCapability("name", "local_test"); + + // Initialise the remote Webdriver using BrowserStack remote URL + // and desired capabilities defined above + RemoteWebDriver driver = new RemoteWebDriver( + new URL("http://hub.browserstack.com/wd/hub"), + capabilities + ); + + // Test case for the BrowserStack sample iOS Local app. + // If you have uploaded your app, update the test case here. + WebElement testButton = (WebElement) new WebDriverWait( + driver, + Duration.ofSeconds(30) + ) + .until( + ExpectedConditions.elementToBeClickable( + AppiumBy.accessibilityId("TestBrowserStackLocal") + ) + ); + testButton.click(); + + WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(30)); + wait.until( + new ExpectedCondition() { + @Override + public Boolean apply(WebDriver d) { + String result = d + .findElement(AppiumBy.accessibilityId("ResultBrowserStackLocal")) + .getAttribute("value"); + return result != null && result.length() > 0; } + } + ); + WebElement resultElement = (WebElement) driver.findElement( + AppiumBy.accessibilityId("ResultBrowserStackLocal") + ); + + String resultString = resultElement.getText().toLowerCase(); + System.out.println(resultString); + if (resultString.contains("not working")) { + File scrFile = (File) ((TakesScreenshot) driver).getScreenshotAs( + OutputType.FILE + ); + FileUtils.copyFile( + scrFile, + new File(System.getProperty("user.dir") + "/screenshot.png") + ); + System.out.println( + "Screenshot stored at " + + System.getProperty("user.dir") + + "/screenshot.png" + ); + throw new Error("Unexpected BrowserStackLocal test result"); + } - String expectedString = "Up and running"; - assert(resultString.contains(expectedString.toLowerCase())); + String expectedString = "Up and running"; + assert (resultString.contains(expectedString.toLowerCase())); - // Invoke driver.quit() after the test is done to indicate that the test is completed. - driver.quit(); - - // Stop the BrowserStack Local binary - tearDownLocal(); - - } + // Invoke driver.quit() after the test is done to indicate that the test is completed. + driver.quit(); + // Stop the BrowserStack Local binary + tearDownLocal(); + } } From 500451967e7e1b4cb2dc4d5edc4c20518211e821 Mon Sep 17 00:00:00 2001 From: Abhishek Jha <21086203+innovater21@users.noreply.github.com> Date: Fri, 11 Mar 2022 16:22:54 +0530 Subject: [PATCH 34/53] removed deprecated syntax --- src/test/java/android/BrowserStackSample.java | 104 ++++++++-------- src/test/java/ios/BrowserStackSample.java | 116 ++++++++++-------- 2 files changed, 119 insertions(+), 101 deletions(-) diff --git a/src/test/java/android/BrowserStackSample.java b/src/test/java/android/BrowserStackSample.java index 6559904..cb5c514 100644 --- a/src/test/java/android/BrowserStackSample.java +++ b/src/test/java/android/BrowserStackSample.java @@ -1,65 +1,71 @@ package android; +import io.appium.java_client.AppiumBy; +import java.net.MalformedURLException; import java.net.URL; +import java.time.Duration; import java.util.List; -import java.util.function.Function; -import java.net.MalformedURLException; - -import io.appium.java_client.AppiumBy; -import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; +import org.openqa.selenium.remote.DesiredCapabilities; import org.openqa.selenium.remote.RemoteWebDriver; - import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.WebDriverWait; -import org.openqa.selenium.remote.DesiredCapabilities; public class BrowserStackSample { - public static void main(String[] args) throws MalformedURLException, InterruptedException { - - DesiredCapabilities caps = new DesiredCapabilities(); - - // Set your access credentials - caps.setCapability("browserstack.user", "YOUR_USERNAME"); - caps.setCapability("browserstack.key", "YOUR_ACCESS_KEY"); - - // Set URL of the application under test - caps.setCapability("app", "bs://"); - - // Specify deviceName and platformName for testing - caps.setCapability("deviceName", "Google Pixel 3"); - caps.setCapability("platformName", "android"); - caps.setCapability("platformVersion", "9.0"); - - // Set other BrowserStack capabilities - caps.setCapability("project", "First Java Project"); - caps.setCapability("build", "browserstack-build-1"); - caps.setCapability("name", "first_test"); - - // Initialise the remote Webdriver using BrowserStack remote URL - // and desired capabilities defined above - RemoteWebDriver driver = new RemoteWebDriver(new URL("http://hub.browserstack.com/wd/hub"), caps); + public static void main(String[] args) + throws MalformedURLException, InterruptedException { + DesiredCapabilities caps = new DesiredCapabilities(); + + // Set your access credentials + caps.setCapability("browserstack.user", "YOUR_USERNAME"); + caps.setCapability("browserstack.key", "YOUR_ACCESS_KEY"); + + // Set URL of the application under test + caps.setCapability("app", "bs://"); + + // Specify deviceName and platformName for testing + caps.setCapability("deviceName", "Google Pixel 3"); + caps.setCapability("platformName", "android"); + caps.setCapability("platformVersion", "9.0"); + + // Set other BrowserStack capabilities + caps.setCapability("project", "First Java Project"); + caps.setCapability("build", "browserstack-build-1"); + caps.setCapability("name", "first_test"); + + // Initialise the remote Webdriver using BrowserStack remote URL + // and desired capabilities defined above + RemoteWebDriver driver = new RemoteWebDriver( + new URL("http://hub.browserstack.com/wd/hub"), + caps + ); - // Test case for the BrowserStack sample Android app. - // If you have uploaded your app, update the test case here. - WebElement searchElement = (WebElement) new WebDriverWait(driver, 30).until( - ExpectedConditions.elementToBeClickable( - AppiumBy.accessibilityId("Search Wikipedia"))); - searchElement.click(); + // Test case for the BrowserStack sample Android app. + // If you have uploaded your app, update the test case here. + WebElement searchElement = (WebElement) new WebDriverWait(driver, Duration.ofSeconds(30)) + .until( + ExpectedConditions.elementToBeClickable( + AppiumBy.accessibilityId("Search Wikipedia") + ) + ); + searchElement.click(); - WebElement insertTextElement = (WebElement) new WebDriverWait(driver, 30).until( - ExpectedConditions.elementToBeClickable( - AppiumBy.id("org.wikipedia.alpha:id/search_src_text"))); - insertTextElement.sendKeys("BrowserStack"); - Thread.sleep(5000); + WebElement insertTextElement = (WebElement) new WebDriverWait(driver, Duration.ofSeconds(30)) + .until( + ExpectedConditions.elementToBeClickable( + AppiumBy.id("org.wikipedia.alpha:id/search_src_text") + ) + ); + insertTextElement.sendKeys("BrowserStack"); + Thread.sleep(5000); - List allProductsName = driver.findElements(AppiumBy.className("android.widget.TextView")); - assert(allProductsName.size() > 0); - - // Invoke driver.quit() after the test is done to indicate that the test is completed. - driver.quit(); - - } + List allProductsName = driver.findElements( + AppiumBy.className("android.widget.TextView") + ); + assert (allProductsName.size() > 0); + // Invoke driver.quit() after the test is done to indicate that the test is completed. + driver.quit(); + } } diff --git a/src/test/java/ios/BrowserStackSample.java b/src/test/java/ios/BrowserStackSample.java index 2efee79..6acc160 100644 --- a/src/test/java/ios/BrowserStackSample.java +++ b/src/test/java/ios/BrowserStackSample.java @@ -1,65 +1,77 @@ package ios; -import java.net.URL; -import java.util.List; +import io.appium.java_client.AppiumBy; import java.net.MalformedURLException; +import java.net.URL; +import java.time.Duration; -import org.openqa.selenium.support.ui.WebDriverWait; -import org.openqa.selenium.remote.DesiredCapabilities; -import org.openqa.selenium.support.ui.ExpectedConditions; - -import io.appium.java_client.AppiumBy; -import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; +import org.openqa.selenium.remote.DesiredCapabilities; import org.openqa.selenium.remote.RemoteWebDriver; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; public class BrowserStackSample { - public static void main(String[] args) throws MalformedURLException, InterruptedException { - - DesiredCapabilities caps = new DesiredCapabilities(); - - // Set your access credentials - caps.setCapability("browserstack.user", "YOUR_USERNAME"); - caps.setCapability("browserstack.key", "YOUR_ACCESS_KEY"); - - // Set URL of the application under test - caps.setCapability("app", "bs://"); - - // Specify device and os_version for testing - caps.setCapability("deviceName", "iPhone 11 Pro"); - caps.setCapability("platformName", "ios"); - caps.setCapability("platformVersion", "13"); - - // Set other BrowserStack capabilities - caps.setCapability("project", "First Java Project"); - caps.setCapability("build", "browserstack-build-1"); - caps.setCapability("name", "first_test"); - - // Initialise the remote Webdriver using BrowserStack remote URL - // and desired capabilities defined above - RemoteWebDriver driver = new RemoteWebDriver( - new URL("http://hub-cloud.browserstack.com/wd/hub"), caps); - - // Test case for the BrowserStack sample iOS app. - // If you have uploaded your app, update the test case here. - WebElement textButton = (WebElement) new WebDriverWait(driver, 30).until( - ExpectedConditions.elementToBeClickable(AppiumBy.accessibilityId("Text Button"))); - textButton.click(); + public static void main(String[] args) + throws MalformedURLException, InterruptedException { + DesiredCapabilities caps = new DesiredCapabilities(); + + // Set your access credentials + caps.setCapability("browserstack.user", "YOUR_USERNAME"); + caps.setCapability("browserstack.key", "YOUR_ACCESS_KEY"); + + // Set URL of the application under test + caps.setCapability("app", "bs://"); + + // Specify device and os_version for testing + caps.setCapability("deviceName", "iPhone 11 Pro"); + caps.setCapability("platformName", "ios"); + caps.setCapability("platformVersion", "13"); + + // Set other BrowserStack capabilities + caps.setCapability("project", "First Java Project"); + caps.setCapability("build", "browserstack-build-1"); + caps.setCapability("name", "first_test"); + + // Initialise the remote Webdriver using BrowserStack remote URL + // and desired capabilities defined above + RemoteWebDriver driver = new RemoteWebDriver( + new URL("http://hub-cloud.browserstack.com/wd/hub"), + caps + ); + + // Test case for the BrowserStack sample iOS app. + // If you have uploaded your app, update the test case here. + WebElement textButton = (WebElement) new WebDriverWait(driver, Duration.ofSeconds(30)) + .until( + ExpectedConditions.elementToBeClickable( + AppiumBy.accessibilityId("Text Button") + ) + ); + textButton.click(); - WebElement textInput = (WebElement) new WebDriverWait(driver, 30).until( - ExpectedConditions.elementToBeClickable(AppiumBy.accessibilityId("Text Input"))); - textInput.sendKeys("hello@browserstack.com"); - Thread.sleep(5000); + WebElement textInput = (WebElement) new WebDriverWait(driver, Duration.ofSeconds(30)) + .until( + ExpectedConditions.elementToBeClickable( + AppiumBy.accessibilityId("Text Input") + ) + ); + textInput.sendKeys("hello@browserstack.com"); + Thread.sleep(5000); - WebElement textOutput = (WebElement) new WebDriverWait(driver, 30).until( - ExpectedConditions.elementToBeClickable(AppiumBy.accessibilityId("Text Output"))); - if(textOutput != null && textOutput.getText().equals("hello@browserstack.com")) - assert(true); - else - assert(false); + WebElement textOutput = (WebElement) new WebDriverWait(driver, Duration.ofSeconds(30)) + .until( + ExpectedConditions.elementToBeClickable( + AppiumBy.accessibilityId("Text Output") + ) + ); + if ( + textOutput != null && + textOutput.getText().equals("hello@browserstack.com") + ) assert (true); else assert (false); - // Invoke driver.quit() after the test is done to indicate that the test is completed. - driver.quit(); - } + // Invoke driver.quit() after the test is done to indicate that the test is completed. + driver.quit(); + } } From 2a41e1dade1b80387cdbd4f092f7e47f58b965c4 Mon Sep 17 00:00:00 2001 From: Abhishek Jha <21086203+innovater21@users.noreply.github.com> Date: Wed, 16 Mar 2022 11:06:36 +0530 Subject: [PATCH 35/53] added comment for w3c support --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index c8321a1..e8e80e1 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,10 @@ mvn clean install Getting Started with Appium tests in Java on BrowserStack couldn't be easier! +For java-client 8.0.0 and above +NOTE : Any BrowserStack capability passed outside bstack:options will not be honoured. +[Browserstack Capability Builder](https://www.browserstack.com/app-automate/capabilities?tag=w3c) + ### Run your first test : **1. Upload your Android or iOS App** From 9f20467d688bd9c9cbf28d2da3f02d2be1281301 Mon Sep 17 00:00:00 2001 From: Abhishek Jha <21086203+innovater21@users.noreply.github.com> Date: Wed, 16 Mar 2022 11:06:58 +0530 Subject: [PATCH 36/53] w3c compliant --- src/test/java/android/BrowserStackSample.java | 28 +++++++++------ .../java/android/BrowserStackSampleLocal.java | 29 ++++++++++------ src/test/java/ios/BrowserStackSample.java | 31 ++++++++++------- .../java/ios/BrowserStackSampleLocal.java | 34 +++++++++++-------- 4 files changed, 75 insertions(+), 47 deletions(-) diff --git a/src/test/java/android/BrowserStackSample.java b/src/test/java/android/BrowserStackSample.java index cb5c514..6fdac68 100644 --- a/src/test/java/android/BrowserStackSample.java +++ b/src/test/java/android/BrowserStackSample.java @@ -1,13 +1,14 @@ package android; import io.appium.java_client.AppiumBy; +import io.appium.java_client.android.AndroidDriver; import java.net.MalformedURLException; import java.net.URL; import java.time.Duration; +import java.util.HashMap; import java.util.List; import org.openqa.selenium.WebElement; import org.openqa.selenium.remote.DesiredCapabilities; -import org.openqa.selenium.remote.RemoteWebDriver; import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.WebDriverWait; @@ -16,27 +17,32 @@ public class BrowserStackSample { public static void main(String[] args) throws MalformedURLException, InterruptedException { DesiredCapabilities caps = new DesiredCapabilities(); - + HashMap browserstackOptions = new HashMap(); + // Set your access credentials - caps.setCapability("browserstack.user", "YOUR_USERNAME"); - caps.setCapability("browserstack.key", "YOUR_ACCESS_KEY"); + browserstackOptions.put("userName", "YOUR_USERNAME"); + browserstackOptions.put("accessKey", "YOUR_ACCESS_KEY"); + // Set other BrowserStack capabilities + browserstackOptions.put("appiumVersion", "1.22.0"); + browserstackOptions.put("projectName", "First Java Project"); + browserstackOptions.put("buildName", "browserstack-build-1"); + browserstackOptions.put("sessionName", "first_test"); + + // Passing browserstack caspabilities inside bstack:options + caps.setCapability("bstack:options", browserstackOptions); + // Set URL of the application under test caps.setCapability("app", "bs://"); - + // Specify deviceName and platformName for testing caps.setCapability("deviceName", "Google Pixel 3"); caps.setCapability("platformName", "android"); caps.setCapability("platformVersion", "9.0"); - // Set other BrowserStack capabilities - caps.setCapability("project", "First Java Project"); - caps.setCapability("build", "browserstack-build-1"); - caps.setCapability("name", "first_test"); - // Initialise the remote Webdriver using BrowserStack remote URL // and desired capabilities defined above - RemoteWebDriver driver = new RemoteWebDriver( + AndroidDriver driver = new AndroidDriver( new URL("http://hub.browserstack.com/wd/hub"), caps ); diff --git a/src/test/java/android/BrowserStackSampleLocal.java b/src/test/java/android/BrowserStackSampleLocal.java index 33a88eb..53acf12 100644 --- a/src/test/java/android/BrowserStackSampleLocal.java +++ b/src/test/java/android/BrowserStackSampleLocal.java @@ -2,12 +2,13 @@ import com.browserstack.local.Local; import io.appium.java_client.AppiumBy; +import io.appium.java_client.android.AndroidDriver; + import java.net.URL; import java.time.Duration; import java.util.*; import org.openqa.selenium.WebElement; import org.openqa.selenium.remote.*; -import org.openqa.selenium.remote.RemoteWebDriver; import org.openqa.selenium.support.ui.*; public class BrowserStackSampleLocal { @@ -33,10 +34,23 @@ public static void main(String[] args) throws Exception { setupLocal(); DesiredCapabilities capabilities = new DesiredCapabilities(); - + HashMap browserstackOptions = new HashMap(); + // Set your access credentials - capabilities.setCapability("browserstack.user", userName); - capabilities.setCapability("browserstack.key", accessKey); + browserstackOptions.put("userName", userName); + browserstackOptions.put("accessKey", accessKey); + + // Set other BrowserStack capabilities + browserstackOptions.put("appiumVersion", "1.22.0"); + browserstackOptions.put("projectName", "First Java Project"); + browserstackOptions.put("buildName", "browserstack-build-1"); + browserstackOptions.put("sessionName", "local_test"); + + // Set the browserstack.local capability to true + browserstackOptions.put("local", "true"); + + // Passing browserstack capabilities inside bstack:options + capabilities.setCapability("bstack:options", browserstackOptions); // Set URL of the application under test capabilities.setCapability("app", "bs://"); @@ -46,14 +60,9 @@ public static void main(String[] args) throws Exception { capabilities.setCapability("platformName", "android"); capabilities.setCapability("platformVersion", "9.0"); - // Set other BrowserStack capabilities - capabilities.setCapability("project", "First Java Project"); - capabilities.setCapability("build", "browserstack-build-1"); - capabilities.setCapability("name", "local_test"); - // Initialise the remote Webdriver using BrowserStack remote URL // and desired capabilities defined above - RemoteWebDriver driver = new RemoteWebDriver( + AndroidDriver driver = new AndroidDriver( new URL("http://hub.browserstack.com/wd/hub"), capabilities ); diff --git a/src/test/java/ios/BrowserStackSample.java b/src/test/java/ios/BrowserStackSample.java index 6acc160..edf3cc8 100644 --- a/src/test/java/ios/BrowserStackSample.java +++ b/src/test/java/ios/BrowserStackSample.java @@ -1,13 +1,15 @@ package ios; import io.appium.java_client.AppiumBy; +import io.appium.java_client.ios.IOSDriver; + import java.net.MalformedURLException; import java.net.URL; import java.time.Duration; +import java.util.HashMap; import org.openqa.selenium.WebElement; import org.openqa.selenium.remote.DesiredCapabilities; -import org.openqa.selenium.remote.RemoteWebDriver; import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.WebDriverWait; @@ -16,10 +18,20 @@ public class BrowserStackSample { public static void main(String[] args) throws MalformedURLException, InterruptedException { DesiredCapabilities caps = new DesiredCapabilities(); - + HashMap browserstackOptions = new HashMap(); + // Set your access credentials - caps.setCapability("browserstack.user", "YOUR_USERNAME"); - caps.setCapability("browserstack.key", "YOUR_ACCESS_KEY"); + browserstackOptions.put("userName", "YOUR_USERNAME"); + browserstackOptions.put("accessKey", "YOUR_ACCESS_KEY"); + + // Set other BrowserStack capabilities + browserstackOptions.put("appiumVersion", "1.22.0"); + browserstackOptions.put("projectName", "First Java Project"); + browserstackOptions.put("buildName", "browserstack-build-1"); + browserstackOptions.put("sessionName", "first_test"); + + // Passing browserstack caspabilities inside bstack:options + caps.setCapability("bstack:options", browserstackOptions); // Set URL of the application under test caps.setCapability("app", "bs://"); @@ -28,16 +40,11 @@ public static void main(String[] args) caps.setCapability("deviceName", "iPhone 11 Pro"); caps.setCapability("platformName", "ios"); caps.setCapability("platformVersion", "13"); - - // Set other BrowserStack capabilities - caps.setCapability("project", "First Java Project"); - caps.setCapability("build", "browserstack-build-1"); - caps.setCapability("name", "first_test"); - + // Initialise the remote Webdriver using BrowserStack remote URL // and desired capabilities defined above - RemoteWebDriver driver = new RemoteWebDriver( - new URL("http://hub-cloud.browserstack.com/wd/hub"), + IOSDriver driver = new IOSDriver( + new URL("http://hub.browserstack.com/wd/hub"), caps ); diff --git a/src/test/java/ios/BrowserStackSampleLocal.java b/src/test/java/ios/BrowserStackSampleLocal.java index d1b1521..3ad93e3 100644 --- a/src/test/java/ios/BrowserStackSampleLocal.java +++ b/src/test/java/ios/BrowserStackSampleLocal.java @@ -2,6 +2,8 @@ import com.browserstack.local.Local; import io.appium.java_client.AppiumBy; +import io.appium.java_client.ios.IOSDriver; + import java.io.File; import java.net.URL; import java.time.Duration; @@ -11,7 +13,6 @@ import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.remote.*; -import org.openqa.selenium.remote.RemoteWebDriver; import org.openqa.selenium.support.ui.*; public class BrowserStackSampleLocal { @@ -37,30 +38,35 @@ public static void main(String[] args) throws Exception { setupLocal(); DesiredCapabilities capabilities = new DesiredCapabilities(); - + HashMap browserstackOptions = new HashMap(); + // Set your access credentials - capabilities.setCapability("browserstack.user", userName); - capabilities.setCapability("browserstack.key", accessKey); + browserstackOptions.put("userName", userName); + browserstackOptions.put("accessKey", accessKey); + + // Set other BrowserStack capabilities + browserstackOptions.put("appiumVersion", "1.22.0"); + browserstackOptions.put("projectName", "First Java Project"); + browserstackOptions.put("buildName", "browserstack-build-1"); + browserstackOptions.put("sessionName", "local_test"); + + // Set the browserstack.local capability to true + browserstackOptions.put("local", "true"); + + // Passing browserstack capabilities inside bstack:options + capabilities.setCapability("bstack:options", browserstackOptions); // Set URL of the application under test - capabilities.setCapability("app", ""); + capabilities.setCapability("app", "bs://"); // Specify device and os_version for testing capabilities.setCapability("deviceName", "iPhone 11 Pro"); capabilities.setCapability("platformName", "ios"); capabilities.setCapability("platformVersion", "13"); - // Set the browserstack.local capability to true - capabilities.setCapability("browserstack.local", true); - - // Set other BrowserStack capabilities - capabilities.setCapability("project", "First Java Project"); - capabilities.setCapability("build", "browserstack-build-1"); - capabilities.setCapability("name", "local_test"); - // Initialise the remote Webdriver using BrowserStack remote URL // and desired capabilities defined above - RemoteWebDriver driver = new RemoteWebDriver( + IOSDriver driver = new IOSDriver( new URL("http://hub.browserstack.com/wd/hub"), capabilities ); From 249f81877880942a359ccabed7e9c515cd505fb8 Mon Sep 17 00:00:00 2001 From: Abhishek Jha <21086203+innovater21@users.noreply.github.com> Date: Wed, 16 Mar 2022 11:08:22 +0530 Subject: [PATCH 37/53] lint --- src/test/java/android/BrowserStackSample.java | 18 ++++++++++----- .../java/android/BrowserStackSampleLocal.java | 3 +-- src/test/java/ios/BrowserStackSample.java | 23 ++++++++++++------- .../java/ios/BrowserStackSampleLocal.java | 3 +-- 4 files changed, 29 insertions(+), 18 deletions(-) diff --git a/src/test/java/android/BrowserStackSample.java b/src/test/java/android/BrowserStackSample.java index 6fdac68..5fe0588 100644 --- a/src/test/java/android/BrowserStackSample.java +++ b/src/test/java/android/BrowserStackSample.java @@ -18,7 +18,7 @@ public static void main(String[] args) throws MalformedURLException, InterruptedException { DesiredCapabilities caps = new DesiredCapabilities(); HashMap browserstackOptions = new HashMap(); - + // Set your access credentials browserstackOptions.put("userName", "YOUR_USERNAME"); browserstackOptions.put("accessKey", "YOUR_ACCESS_KEY"); @@ -28,13 +28,13 @@ public static void main(String[] args) browserstackOptions.put("projectName", "First Java Project"); browserstackOptions.put("buildName", "browserstack-build-1"); browserstackOptions.put("sessionName", "first_test"); - + // Passing browserstack caspabilities inside bstack:options caps.setCapability("bstack:options", browserstackOptions); - + // Set URL of the application under test caps.setCapability("app", "bs://"); - + // Specify deviceName and platformName for testing caps.setCapability("deviceName", "Google Pixel 3"); caps.setCapability("platformName", "android"); @@ -49,7 +49,10 @@ public static void main(String[] args) // Test case for the BrowserStack sample Android app. // If you have uploaded your app, update the test case here. - WebElement searchElement = (WebElement) new WebDriverWait(driver, Duration.ofSeconds(30)) + WebElement searchElement = (WebElement) new WebDriverWait( + driver, + Duration.ofSeconds(30) + ) .until( ExpectedConditions.elementToBeClickable( AppiumBy.accessibilityId("Search Wikipedia") @@ -57,7 +60,10 @@ public static void main(String[] args) ); searchElement.click(); - WebElement insertTextElement = (WebElement) new WebDriverWait(driver, Duration.ofSeconds(30)) + WebElement insertTextElement = (WebElement) new WebDriverWait( + driver, + Duration.ofSeconds(30) + ) .until( ExpectedConditions.elementToBeClickable( AppiumBy.id("org.wikipedia.alpha:id/search_src_text") diff --git a/src/test/java/android/BrowserStackSampleLocal.java b/src/test/java/android/BrowserStackSampleLocal.java index 53acf12..e765543 100644 --- a/src/test/java/android/BrowserStackSampleLocal.java +++ b/src/test/java/android/BrowserStackSampleLocal.java @@ -3,7 +3,6 @@ import com.browserstack.local.Local; import io.appium.java_client.AppiumBy; import io.appium.java_client.android.AndroidDriver; - import java.net.URL; import java.time.Duration; import java.util.*; @@ -35,7 +34,7 @@ public static void main(String[] args) throws Exception { DesiredCapabilities capabilities = new DesiredCapabilities(); HashMap browserstackOptions = new HashMap(); - + // Set your access credentials browserstackOptions.put("userName", userName); browserstackOptions.put("accessKey", accessKey); diff --git a/src/test/java/ios/BrowserStackSample.java b/src/test/java/ios/BrowserStackSample.java index edf3cc8..6449e25 100644 --- a/src/test/java/ios/BrowserStackSample.java +++ b/src/test/java/ios/BrowserStackSample.java @@ -2,12 +2,10 @@ import io.appium.java_client.AppiumBy; import io.appium.java_client.ios.IOSDriver; - import java.net.MalformedURLException; import java.net.URL; import java.time.Duration; import java.util.HashMap; - import org.openqa.selenium.WebElement; import org.openqa.selenium.remote.DesiredCapabilities; import org.openqa.selenium.support.ui.ExpectedConditions; @@ -19,7 +17,7 @@ public static void main(String[] args) throws MalformedURLException, InterruptedException { DesiredCapabilities caps = new DesiredCapabilities(); HashMap browserstackOptions = new HashMap(); - + // Set your access credentials browserstackOptions.put("userName", "YOUR_USERNAME"); browserstackOptions.put("accessKey", "YOUR_ACCESS_KEY"); @@ -29,7 +27,7 @@ public static void main(String[] args) browserstackOptions.put("projectName", "First Java Project"); browserstackOptions.put("buildName", "browserstack-build-1"); browserstackOptions.put("sessionName", "first_test"); - + // Passing browserstack caspabilities inside bstack:options caps.setCapability("bstack:options", browserstackOptions); @@ -40,7 +38,7 @@ public static void main(String[] args) caps.setCapability("deviceName", "iPhone 11 Pro"); caps.setCapability("platformName", "ios"); caps.setCapability("platformVersion", "13"); - + // Initialise the remote Webdriver using BrowserStack remote URL // and desired capabilities defined above IOSDriver driver = new IOSDriver( @@ -50,7 +48,10 @@ public static void main(String[] args) // Test case for the BrowserStack sample iOS app. // If you have uploaded your app, update the test case here. - WebElement textButton = (WebElement) new WebDriverWait(driver, Duration.ofSeconds(30)) + WebElement textButton = (WebElement) new WebDriverWait( + driver, + Duration.ofSeconds(30) + ) .until( ExpectedConditions.elementToBeClickable( AppiumBy.accessibilityId("Text Button") @@ -58,7 +59,10 @@ public static void main(String[] args) ); textButton.click(); - WebElement textInput = (WebElement) new WebDriverWait(driver, Duration.ofSeconds(30)) + WebElement textInput = (WebElement) new WebDriverWait( + driver, + Duration.ofSeconds(30) + ) .until( ExpectedConditions.elementToBeClickable( AppiumBy.accessibilityId("Text Input") @@ -67,7 +71,10 @@ public static void main(String[] args) textInput.sendKeys("hello@browserstack.com"); Thread.sleep(5000); - WebElement textOutput = (WebElement) new WebDriverWait(driver, Duration.ofSeconds(30)) + WebElement textOutput = (WebElement) new WebDriverWait( + driver, + Duration.ofSeconds(30) + ) .until( ExpectedConditions.elementToBeClickable( AppiumBy.accessibilityId("Text Output") diff --git a/src/test/java/ios/BrowserStackSampleLocal.java b/src/test/java/ios/BrowserStackSampleLocal.java index 3ad93e3..5ebf5a0 100644 --- a/src/test/java/ios/BrowserStackSampleLocal.java +++ b/src/test/java/ios/BrowserStackSampleLocal.java @@ -3,7 +3,6 @@ import com.browserstack.local.Local; import io.appium.java_client.AppiumBy; import io.appium.java_client.ios.IOSDriver; - import java.io.File; import java.net.URL; import java.time.Duration; @@ -39,7 +38,7 @@ public static void main(String[] args) throws Exception { DesiredCapabilities capabilities = new DesiredCapabilities(); HashMap browserstackOptions = new HashMap(); - + // Set your access credentials browserstackOptions.put("userName", userName); browserstackOptions.put("accessKey", accessKey); From 1316fea994620e548070c7b15e7ae33fbfcb124e Mon Sep 17 00:00:00 2001 From: Abhishek Jha <21086203+innovater21@users.noreply.github.com> Date: Wed, 16 Mar 2022 11:11:49 +0530 Subject: [PATCH 38/53] Update README.md --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e8e80e1..3a827be 100644 --- a/README.md +++ b/README.md @@ -29,8 +29,9 @@ mvn clean install Getting Started with Appium tests in Java on BrowserStack couldn't be easier! -For java-client 8.0.0 and above -NOTE : Any BrowserStack capability passed outside bstack:options will not be honoured. +### For java-client 8.0.0 and above + +NOTE : Any BrowserStack capability passed outside bstack:options will not be honoured \ [Browserstack Capability Builder](https://www.browserstack.com/app-automate/capabilities?tag=w3c) ### Run your first test : From 89317080f50ad42298ce2dad2cd24a0dcf8bbcd3 Mon Sep 17 00:00:00 2001 From: Abhishek Jha <21086203+innovater21@users.noreply.github.com> Date: Wed, 16 Mar 2022 11:13:40 +0530 Subject: [PATCH 39/53] typo fix --- src/test/java/android/BrowserStackSample.java | 2 +- src/test/java/ios/BrowserStackSample.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/android/BrowserStackSample.java b/src/test/java/android/BrowserStackSample.java index 5fe0588..c923568 100644 --- a/src/test/java/android/BrowserStackSample.java +++ b/src/test/java/android/BrowserStackSample.java @@ -29,7 +29,7 @@ public static void main(String[] args) browserstackOptions.put("buildName", "browserstack-build-1"); browserstackOptions.put("sessionName", "first_test"); - // Passing browserstack caspabilities inside bstack:options + // Passing browserstack capabilities inside bstack:options caps.setCapability("bstack:options", browserstackOptions); // Set URL of the application under test diff --git a/src/test/java/ios/BrowserStackSample.java b/src/test/java/ios/BrowserStackSample.java index 6449e25..3b5f864 100644 --- a/src/test/java/ios/BrowserStackSample.java +++ b/src/test/java/ios/BrowserStackSample.java @@ -28,7 +28,7 @@ public static void main(String[] args) browserstackOptions.put("buildName", "browserstack-build-1"); browserstackOptions.put("sessionName", "first_test"); - // Passing browserstack caspabilities inside bstack:options + // Passing browserstack capabilities inside bstack:options caps.setCapability("bstack:options", browserstackOptions); // Set URL of the application under test From 63478c05c0223b41da88528cffac5f04cddb6ca9 Mon Sep 17 00:00:00 2001 From: Abhishek Jha <21086203+innovater21@users.noreply.github.com> Date: Wed, 16 Mar 2022 11:52:59 +0530 Subject: [PATCH 40/53] Update README.md --- README.md | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3a827be..c84c95b 100644 --- a/README.md +++ b/README.md @@ -31,9 +31,30 @@ Getting Started with Appium tests in Java on BrowserStack couldn't be easier! ### For java-client 8.0.0 and above -NOTE : Any BrowserStack capability passed outside bstack:options will not be honoured \ +- Any BrowserStack capability passed outside bstack:options will not be honoured \ [Browserstack Capability Builder](https://www.browserstack.com/app-automate/capabilities?tag=w3c) +- AppiumBy is available with java-client 8.0.0 . For java-client < 8.0.0, MobileBy can be used. + +- WebDriverWait constructor requires time to be passed as a type Duration. So with java-client 8.0.0, pass wait time as a new Duration +- java-client v-7.0.0 + ``` + WebElement searchElement = (WebElement) new WebDriverWait( + driver, + 30 + ) + ``` + + java-client v-8.0.0 + ``` + WebElement searchElement = (WebElement) new WebDriverWait( + driver, + Duration.ofSeconds(30) + ) + ``` + + Refer this for tracking changes in java-client 8.0.0 documentation - [v7-to-v8-migration-guide](https://github.com/appium/java-client/blob/master/docs/v7-to-v8-migration-guide.md#mobileelement) + ### Run your first test : **1. Upload your Android or iOS App** From e2cf186e323047c4e5461c3d0eb187d03a565258 Mon Sep 17 00:00:00 2001 From: Abhishek Jha <21086203+innovater21@users.noreply.github.com> Date: Wed, 16 Mar 2022 12:00:55 +0530 Subject: [PATCH 41/53] Update README.md --- README.md | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index c84c95b..e4006a8 100644 --- a/README.md +++ b/README.md @@ -34,23 +34,18 @@ Getting Started with Appium tests in Java on BrowserStack couldn't be easier! - Any BrowserStack capability passed outside bstack:options will not be honoured \ [Browserstack Capability Builder](https://www.browserstack.com/app-automate/capabilities?tag=w3c) -- AppiumBy is available with java-client 8.0.0 . For java-client < 8.0.0, MobileBy can be used. +- AppiumBy is available with java-client 8.0.0 as MobileBy is depreceated . For java-client < 8.0.0, MobileBy can be used. - WebDriverWait constructor requires time to be passed as a type Duration. So with java-client 8.0.0, pass wait time as a new Duration -- java-client v-7.0.0 + **java-client v-7.0.0** ``` - WebElement searchElement = (WebElement) new WebDriverWait( - driver, - 30 - ) + WebElement searchElement = (WebElement) new WebDriverWait(driver, 30) ``` - java-client v-8.0.0 + **java-client v-8.0.0** ``` - WebElement searchElement = (WebElement) new WebDriverWait( - driver, - Duration.ofSeconds(30) - ) + import java.time.Duration; + WebElement searchElement = (WebElement) new WebDriverWait(driver, Duration.ofSeconds(30)) ``` Refer this for tracking changes in java-client 8.0.0 documentation - [v7-to-v8-migration-guide](https://github.com/appium/java-client/blob/master/docs/v7-to-v8-migration-guide.md#mobileelement) From f1cb7256aa5b81196f4c6abf021dc6ec59f3b2b7 Mon Sep 17 00:00:00 2001 From: Abhishek Jha <21086203+innovater21@users.noreply.github.com> Date: Wed, 16 Mar 2022 12:10:12 +0530 Subject: [PATCH 42/53] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index e4006a8..034d41d 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,8 @@ Getting Started with Appium tests in Java on BrowserStack couldn't be easier! - AppiumBy is available with java-client 8.0.0 as MobileBy is depreceated . For java-client < 8.0.0, MobileBy can be used. +- DefaultGenericMobileElement class has been removed completely together with its descendants (MobileElement, IOSElement, AndroidElement etc.). Use WebElement instead. + - WebDriverWait constructor requires time to be passed as a type Duration. So with java-client 8.0.0, pass wait time as a new Duration **java-client v-7.0.0** ``` From 3cf22bee30d9a87fc409d49863933d9b464619b4 Mon Sep 17 00:00:00 2001 From: Abhishek Jha <21086203+innovater21@users.noreply.github.com> Date: Thu, 17 Mar 2022 09:58:48 +0530 Subject: [PATCH 43/53] Updated README for initiating a local connection --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.md b/README.md index 034d41d..5597b8a 100644 --- a/README.md +++ b/README.md @@ -116,6 +116,15 @@ Ensure that @ symbol is prepended to the file path in the above request. Please **2. Configure and run your local test** +Local Testing is a BrowserStack feature that helps you test mobile apps that access resources hosted in development or testing environments during automated test execution + +To setup Local Testing connection - [Local testing reference](https://www.browserstack.com/docs/app-automate/appium/getting-started/java/local-testing) + +NOTE : If you're unable to run the LocalTesting Binary due to Apple permission issues, go to \ + ``` + System preferences -> Security and privacy -> General -> Allow app + ``` + Open `BrowserStackSampleLocal.java` file in the `android` or `ios` directory : - Replace `YOUR_USERNAME` & `YOUR_ACCESS_KEY` with your BrowserStack access credentials. Get your BrowserStack access credentials from [here](https://www.browserstack.com/accounts/settings) From ecb89782d114055d23fabd4ab819489966eaeaef Mon Sep 17 00:00:00 2001 From: Abhishek Jha <21086203+innovater21@users.noreply.github.com> Date: Thu, 17 Mar 2022 13:25:20 +0530 Subject: [PATCH 44/53] Added local testing link for local testing --- README.md | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 5597b8a..772c5e5 100644 --- a/README.md +++ b/README.md @@ -118,14 +118,22 @@ Ensure that @ symbol is prepended to the file path in the above request. Please Local Testing is a BrowserStack feature that helps you test mobile apps that access resources hosted in development or testing environments during automated test execution -To setup Local Testing connection - [Local testing reference](https://www.browserstack.com/docs/app-automate/appium/getting-started/java/local-testing) +**i. Setup Browserstack Local Testing connection :** -NOTE : If you're unable to run the LocalTesting Binary due to Apple permission issues, go to \ +Check the releases page to download the binary / native application [Browserstack Local Releases](https://www.browserstack.com/docs/local-testing/releases-and-downloads) + +- Option 1 + - Use Browserstack Local Binary - [Local Binary](https://www.browserstack.com/docs/app-automate/appium/getting-started/java/local-testing) +- Option 2 + - Use Browserstack native application - [Local Native App](https://www.browserstack.com/docs/local-testing/local-app-upgrade-guide) + + +NOTE : If you're unable to run the LocalTesting Binary / Native application due to Apple permission issues, go to \ ``` System preferences -> Security and privacy -> General -> Allow app ``` -Open `BrowserStackSampleLocal.java` file in the `android` or `ios` directory : +**ii. Open `BrowserStackSampleLocal.java` file in the `android` or `ios` directory :** - Replace `YOUR_USERNAME` & `YOUR_ACCESS_KEY` with your BrowserStack access credentials. Get your BrowserStack access credentials from [here](https://www.browserstack.com/accounts/settings) From f2baa82d56faa68d761c2004369c8aabbce96596 Mon Sep 17 00:00:00 2001 From: deepwired Date: Tue, 10 May 2022 09:14:17 +0530 Subject: [PATCH 45/53] created dedicated directories for java7 and java8 --- java_7/README.md | 132 +++++++++++++++ java_7/pom.xml | 160 ++++++++++++++++++ .../test/java/android/BrowserStackSample.java | 68 ++++++++ .../java/android/BrowserStackSampleLocal.java | 90 ++++++++++ .../src/test/java/ios/BrowserStackSample.java | 64 +++++++ .../java/ios/BrowserStackSampleLocal.java | 95 +++++++++++ README.md => java_8/README.md | 0 pom.xml => java_8/pom.xml | 0 .../test/java/android/BrowserStackSample.java | 0 .../java/android/BrowserStackSampleLocal.java | 0 .../test/java/ios/BrowserStackSample.java | 0 .../java/ios/BrowserStackSampleLocal.java | 0 12 files changed, 609 insertions(+) create mode 100644 java_7/README.md create mode 100644 java_7/pom.xml create mode 100644 java_7/src/test/java/android/BrowserStackSample.java create mode 100644 java_7/src/test/java/android/BrowserStackSampleLocal.java create mode 100644 java_7/src/test/java/ios/BrowserStackSample.java create mode 100644 java_7/src/test/java/ios/BrowserStackSampleLocal.java rename README.md => java_8/README.md (100%) rename pom.xml => java_8/pom.xml (100%) rename {src => java_8/src}/test/java/android/BrowserStackSample.java (100%) rename {src => java_8/src}/test/java/android/BrowserStackSampleLocal.java (100%) rename {src => java_8/src}/test/java/ios/BrowserStackSample.java (100%) rename {src => java_8/src}/test/java/ios/BrowserStackSampleLocal.java (100%) diff --git a/java_7/README.md b/java_7/README.md new file mode 100644 index 0000000..c8321a1 --- /dev/null +++ b/java_7/README.md @@ -0,0 +1,132 @@ +# java-appium-app-browserstack + +This repository demonstrates how to run Appium Java tests on BrowserStack App Automate. + +## Setup + +### Requirements + +1. Java 8+ + +- If Java is not installed, follow these instructions: + - For Windows, download latest java version from [here](https://java.com/en/download/) and run the installer executable + - For Mac and Linux, run `java -version` to see what java version is pre-installed. If you want a different version download from [here](https://java.com/en/download/) + +2. Maven + + - If Maven is not downloaded, download it from [here](https://maven.apache.org/download.cgi) + - For installation, follow the instructions [here](https://maven.apache.org/install.html) + +### Install the dependencies + +To install the dependencies, run the following command in the project's base folder + +```cmd +mvn clean install +``` + +## Getting Started + +Getting Started with Appium tests in Java on BrowserStack couldn't be easier! + +### Run your first test : + +**1. Upload your Android or iOS App** + +Upload your Android app (.apk or .aab file) or iOS app (.ipa file) to BrowserStack servers using our REST API. Here is an example cURL request : + +``` +curl -u "YOUR_USERNAME:YOUR_ACCESS_KEY" \ +-X POST "https://api-cloud.browserstack.com/app-automate/upload" \ +-F "file=@/path/to/apk/file" +``` + +Ensure that @ symbol is prepended to the file path in the above request. Please note the `app_url` value returned in the API response. We will use this to set the application under test while configuring the test later on. + +**Note**: If you do not have an .apk or .ipa file and are looking to simply try App Automate, you can download and test using our [sample Android app](https://www.browserstack.com/app-automate/sample-apps/android/WikipediaSample.apk) or [sample iOS app](https://www.browserstack.com/app-automate/sample-apps/ios/BStackSampleApp.ipa). + +**2. Configure and run your first test** + +Open `BrowserStackSample.java` file in the `android` directory or `ios` directory : + +- Replace `YOUR_USERNAME` & `YOUR_ACCESS_KEY` with your BrowserStack access credentials. Get your BrowserStack access credentials from [here](https://www.browserstack.com/accounts/settings) + +- Replace `bs://` with the URL obtained from app upload step + +- Set the device and OS version + +- If you have uploaded your own app update the test case + +- To run the test, use the following command in the base directory : + + - For Android test, run + + ```cmd + mvn test -P android-first-test + ``` + + - For iOS test, run + + ```cmd + mvn test -P ios-first-test + ``` + +- You can access the test execution results, and debugging information such as video recording, network logs on [App Automate dashboard](https://app-automate.browserstack.com/dashboard) + +--- + +### Use Local testing for apps that access resources hosted in development or testing environments : + +**1. Upoad your Android or iOS App** + +Upload your Android app (.apk or .aab file) or iOS app (.ipa file) that access resources hosted on your internal or test environments to BrowserStack servers using our REST API. Here is an example cURL request : + +``` +curl -u "YOUR_USERNAME:YOUR_ACCESS_KEY" \ +-X POST "https://api-cloud.browserstack.com/app-automate/upload" \ +-F "file=@/path/to/apk/file" +``` + +Ensure that @ symbol is prepended to the file path in the above request. Please note the `app_url` value returned in the API response. We will use this to set the application under test while configuring the test later on. + +**Note**: If you do not have an .apk or .ipa file and are looking to simply try App Automate, you can download and test using our [sample Android Local app](https://www.browserstack.com/app-automate/sample-apps/android/LocalSample.apk) or [sample iOS Local app](https://www.browserstack.com/app-automate/sample-apps/ios/LocalSample.ipa). + +**2. Configure and run your local test** + +Open `BrowserStackSampleLocal.java` file in the `android` or `ios` directory : + +- Replace `YOUR_USERNAME` & `YOUR_ACCESS_KEY` with your BrowserStack access credentials. Get your BrowserStack access credentials from [here](https://www.browserstack.com/accounts/settings) + +- Replace `bs://` with the URL obtained from app upload step + +- Set the device and OS version + +- Ensure that `browserstack.local` capability is set to `true`. Within the test script, there is code snippet that automatically establishes Local Testing connection to BrowserStack servers using Java binding for BrowserStack Local. + +- If you have uploaded your own app update the test case + +- To run the test, use the following command in the base directory : + + - For Android test, run + + ```cmd + mvn test -P android-local-test + ``` + + - For iOS test, run + + ```cmd + mvn test -P ios-local-test + ``` + +- You can access the test execution results, and debugging information such as video recording, network logs on [App Automate dashboard](https://app-automate.browserstack.com/dashboard) + + +## Integration with other Java frameworks + +- [JUnit](https://github.com/browserstack/junit-appium-app-browserstack) +- [TestNg](https://github.com/browserstack/testng-appium-app-browserstack) + +## Getting Help + +If you are running into any issues or have any queries, please check [Browserstack Support page](https://www.browserstack.com/support/app-automate) or [get in touch with us](https://www.browserstack.com/contact?ref=help). diff --git a/java_7/pom.xml b/java_7/pom.xml new file mode 100644 index 0000000..74fc8bd --- /dev/null +++ b/java_7/pom.xml @@ -0,0 +1,160 @@ + + 4.0.0 + com.browserstack + java-browserstack + 0.0.1-SNAPSHOT + java-browserstack + Java appium app browserstack + + + UTF-8 + 2.19.1 + + default + + + + + + commons-io + commons-io + 1.3.2 + + + io.appium + java-client + 7.0.0 + + + com.browserstack + browserstack-local-java + 1.0.3 + + + com.googlecode.json-simple + json-simple + 1.1.1 + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.22.2 + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + 1.8 + 1.8 + + + + + + + + android-first-test + + + + org.codehaus.mojo + exec-maven-plugin + 1.1.1 + + + test + + java + + + android.BrowserStackSample + test + + + + + + + + + android-local-test + + + + org.codehaus.mojo + exec-maven-plugin + 1.1.1 + + + test + + java + + + android.BrowserStackSampleLocal + test + + + + + + + + + ios-first-test + + + + org.codehaus.mojo + exec-maven-plugin + 1.1.1 + + + test + + java + + + ios.BrowserStackSample + test + + + + + + + + + ios-local-test + + + + org.codehaus.mojo + exec-maven-plugin + 1.1.1 + + + test + + java + + + ios.BrowserStackSampleLocal + test + + + + + + + + + + \ No newline at end of file diff --git a/java_7/src/test/java/android/BrowserStackSample.java b/java_7/src/test/java/android/BrowserStackSample.java new file mode 100644 index 0000000..136ee81 --- /dev/null +++ b/java_7/src/test/java/android/BrowserStackSample.java @@ -0,0 +1,68 @@ +package android; + +import java.net.URL; +import java.util.List; +import java.util.function.Function; +import java.net.MalformedURLException; + +import io.appium.java_client.MobileBy; +import io.appium.java_client.android.AndroidDriver; +import io.appium.java_client.android.AndroidElement; + +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.remote.DesiredCapabilities; + + +public class BrowserStackSample { + + public static void main(String[] args) throws MalformedURLException, InterruptedException { + + DesiredCapabilities caps = new DesiredCapabilities(); + + // Set your access credentials + caps.setCapability("browserstack.user", "YOUR_USERNAME"); + caps.setCapability("browserstack.key", "YOUR_ACCESS_KEY"); + + // Set URL of the application under test + caps.setCapability("app", "bs://"); + + // Specify device and os_version for testing + caps.setCapability("device", "Google Pixel 3"); + caps.setCapability("os_version", "9.0"); + + // Set other BrowserStack capabilities + caps.setCapability("project", "First Java Project"); + caps.setCapability("build", "browserstack-build-1"); + caps.setCapability("name", "first_test"); + + + // Initialise the remote Webdriver using BrowserStack remote URL + // and desired capabilities defined above + AndroidDriver driver = new AndroidDriver( + new URL("http://hub.browserstack.com/wd/hub"), caps); + + + // Test case for the BrowserStack sample Android app. + // If you have uploaded your app, update the test case here. + AndroidElement searchElement = (AndroidElement) new WebDriverWait(driver, 30).until( + ExpectedConditions.elementToBeClickable( + MobileBy.AccessibilityId("Search Wikipedia"))); + searchElement.click(); + AndroidElement insertTextElement = (AndroidElement) new WebDriverWait(driver, 30).until( + ExpectedConditions.elementToBeClickable( + MobileBy.id("org.wikipedia.alpha:id/search_src_text"))); + insertTextElement.sendKeys("BrowserStack"); + Thread.sleep(5000); + List allProductsName = driver.findElementsByClassName( + "android.widget.TextView"); + assert(allProductsName.size() > 0); + + + // Invoke driver.quit() after the test is done to indicate that the test is completed. + driver.quit(); + + } + +} diff --git a/java_7/src/test/java/android/BrowserStackSampleLocal.java b/java_7/src/test/java/android/BrowserStackSampleLocal.java new file mode 100644 index 0000000..0854db1 --- /dev/null +++ b/java_7/src/test/java/android/BrowserStackSampleLocal.java @@ -0,0 +1,90 @@ +package android; + +import com.browserstack.local.Local; +import java.net.URL; import java.util.*; +import io.appium.java_client.MobileBy; import io.appium.java_client.android.*; +import org.openqa.selenium.support.ui.*;import org.openqa.selenium.remote.*; + +public class BrowserStackSampleLocal { + + private static Local localInstance; + public static String userName = "YOUR_USERNAME"; + public static String accessKey = "YOUR_ACCESS_KEY"; + + + public static void setupLocal() throws Exception { + localInstance = new Local(); + Map options = new HashMap(); + options.put("key", accessKey); + localInstance.start(options); + } + + public static void tearDownLocal() throws Exception { + localInstance.stop(); + } + + public static void main(String[] args) throws Exception { + // Start the BrowserStack Local binary + setupLocal(); + + DesiredCapabilities capabilities = new DesiredCapabilities(); + + // Set your access credentials + capabilities.setCapability("browserstack.user", userName); + capabilities.setCapability("browserstack.key", accessKey); + + // Set URL of the application under test + capabilities.setCapability("app", "bs://"); + + // Specify device and os_version for testing + capabilities.setCapability("device", "Google Pixel 3"); + capabilities.setCapability("os_version", "9.0"); + + // Set the browserstack.local capability to true + capabilities.setCapability("browserstack.local", true); + + // Set other BrowserStack capabilities + capabilities.setCapability("project", "First Java Project"); + capabilities.setCapability("build", "browserstack-build-1"); + capabilities.setCapability("name", "local_test"); + + + // Initialise the remote Webdriver using BrowserStack remote URL + // and desired capabilities defined above + AndroidDriver driver = new AndroidDriver( + new URL("http://hub.browserstack.com/wd/hub"), capabilities); + + // Test case for the BrowserStack sample Android Local app. + // If you have uploaded your app, update the test case here. + AndroidElement searchElement = (AndroidElement) new WebDriverWait(driver, 30).until( + ExpectedConditions.elementToBeClickable(MobileBy.id("com.example.android.basicnetworking:id/test_action"))); + searchElement.click(); + AndroidElement insertTextElement = (AndroidElement) new WebDriverWait(driver, 30).until( + ExpectedConditions.elementToBeClickable(MobileBy.className("android.widget.TextView"))); + + AndroidElement testElement = null; + List allTextViewElements = driver.findElementsByClassName("android.widget.TextView"); + Thread.sleep(10); + for(AndroidElement textElement : allTextViewElements) { + if(textElement.getText().contains("The active connection is")) { + testElement = textElement; + } + } + + if(testElement == null) { + throw new Error("Cannot find the needed TextView element from app"); + } + String matchedString = testElement.getText(); + System.out.println(matchedString); + assert(matchedString.contains("The active connection is wifi")); + assert(matchedString.contains("Up and running")); + + // Invoke driver.quit() after the test is done to indicate that the test is completed. + driver.quit(); + + // Stop the BrowserStack Local binary + tearDownLocal(); + + } + +} diff --git a/java_7/src/test/java/ios/BrowserStackSample.java b/java_7/src/test/java/ios/BrowserStackSample.java new file mode 100644 index 0000000..6fd9eea --- /dev/null +++ b/java_7/src/test/java/ios/BrowserStackSample.java @@ -0,0 +1,64 @@ +package ios; + +import java.net.URL; +import java.util.List; +import java.net.MalformedURLException; + +import org.openqa.selenium.support.ui.WebDriverWait; +import org.openqa.selenium.remote.DesiredCapabilities; +import org.openqa.selenium.support.ui.ExpectedConditions; + +import io.appium.java_client.MobileBy; +import io.appium.java_client.ios.IOSDriver; +import io.appium.java_client.ios.IOSElement; + +public class BrowserStackSample { + + public static void main(String[] args) throws MalformedURLException, InterruptedException { + DesiredCapabilities caps = new DesiredCapabilities(); + + // Set your access credentials + caps.setCapability("browserstack.user", "YOUR_USERNAME"); + caps.setCapability("browserstack.key", "YOUR_ACCESS_KEY"); + + // Set URL of the application under test + caps.setCapability("app", "bs://"); + + // Specify device and os_version for testing + caps.setCapability("device", "iPhone 11 Pro"); + caps.setCapability("os_version", "13"); + + // Set other BrowserStack capabilities + caps.setCapability("project", "First Java Project"); + caps.setCapability("build", "browserstack-build-1"); + caps.setCapability("name", "first_test"); + + + // Initialise the remote Webdriver using BrowserStack remote URL + // and desired capabilities defined above + IOSDriver driver = new IOSDriver( + new URL("http://hub-cloud.browserstack.com/wd/hub"), caps); + + + // Test case for the BrowserStack sample iOS app. + // If you have uploaded your app, update the test case here. + IOSElement textButton = (IOSElement) new WebDriverWait(driver, 30).until( + ExpectedConditions.elementToBeClickable(MobileBy.AccessibilityId("Text Button"))); + textButton.click(); + IOSElement textInput = (IOSElement) new WebDriverWait(driver, 30).until( + ExpectedConditions.elementToBeClickable(MobileBy.AccessibilityId("Text Input"))); + textInput.sendKeys("hello@browserstack.com"); + Thread.sleep(5000); + IOSElement textOutput = (IOSElement) new WebDriverWait(driver, 30).until( + ExpectedConditions.elementToBeClickable(MobileBy.AccessibilityId("Text Output"))); + if(textOutput != null && textOutput.getText().equals("hello@browserstack.com")) + assert(true); + else + assert(false); + + // Invoke driver.quit() after the test is done to indicate that the test is completed. + driver.quit(); + + } + +} diff --git a/java_7/src/test/java/ios/BrowserStackSampleLocal.java b/java_7/src/test/java/ios/BrowserStackSampleLocal.java new file mode 100644 index 0000000..f278a07 --- /dev/null +++ b/java_7/src/test/java/ios/BrowserStackSampleLocal.java @@ -0,0 +1,95 @@ +package ios; + +import com.browserstack.local.Local; +import java.net.URL; import java.io.File; import java.util.*; +import org.apache.commons.io.FileUtils; +import io.appium.java_client.MobileBy; import io.appium.java_client.ios.*; +import org.openqa.selenium.*; +import org.openqa.selenium.support.ui.*;import org.openqa.selenium.remote.*; + +public class BrowserStackSampleLocal { + + private static Local localInstance; + public static String userName = "YOUR_USERNAME"; + public static String accessKey = "YOUR_ACCESS_KEY"; + + + public static void setupLocal() throws Exception { + localInstance = new Local(); + Map options = new HashMap(); + options.put("key", accessKey); + localInstance.start(options); + } + + public static void tearDownLocal() throws Exception { + localInstance.stop(); + } + + + public static void main(String[] args) throws Exception { + // Start the BrowserStack Local binary + setupLocal(); + + DesiredCapabilities capabilities = new DesiredCapabilities(); + + // Set your access credentials + capabilities.setCapability("browserstack.user", userName); + capabilities.setCapability("browserstack.key", accessKey); + + // Set URL of the application under test + capabilities.setCapability("app", "bs://"); + + // Specify device and os_version for testing + capabilities.setCapability("device", "iPhone 11 Pro"); + capabilities.setCapability("os_version", "13"); + + // Set the browserstack.local capability to true + capabilities.setCapability("browserstack.local", true); + + // Set other BrowserStack capabilities + capabilities.setCapability("project", "First Java Project"); + capabilities.setCapability("build", "browserstack-build-1"); + capabilities.setCapability("name", "local_test"); + + // Initialise the remote Webdriver using BrowserStack remote URL + // and desired capabilities defined above + IOSDriver driver = new IOSDriver( + new URL("http://hub.browserstack.com/wd/hub"), capabilities); + + // Test case for the BrowserStack sample iOS Local app. + // If you have uploaded your app, update the test case here. + IOSElement testButton = (IOSElement) new WebDriverWait(driver, 30).until( + ExpectedConditions.elementToBeClickable(MobileBy.AccessibilityId("TestBrowserStackLocal"))); + testButton.click(); + + WebDriverWait wait = new WebDriverWait(driver, 30); + wait.until(new ExpectedCondition() { + @Override + public Boolean apply(WebDriver d) { + String result = d.findElement(MobileBy.AccessibilityId("ResultBrowserStackLocal")).getAttribute("value"); + return result != null && result.length() > 0; + } + }); + IOSElement resultElement = (IOSElement) driver.findElement(MobileBy.AccessibilityId("ResultBrowserStackLocal")); + + String resultString = resultElement.getText().toLowerCase(); + System.out.println(resultString); + if(resultString.contains("not working")) { + File scrFile = (File) ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE); + FileUtils.copyFile(scrFile, new File(System.getProperty("user.dir") + "/screenshot.png")); + System.out.println("Screenshot stored at " + System.getProperty("user.dir") + "/screenshot.png"); + throw new Error("Unexpected BrowserStackLocal test result"); + } + + String expectedString = "Up and running"; + assert(resultString.contains(expectedString.toLowerCase())); + + // Invoke driver.quit() after the test is done to indicate that the test is completed. + driver.quit(); + + // Stop the BrowserStack Local binary + tearDownLocal(); + + } + +} diff --git a/README.md b/java_8/README.md similarity index 100% rename from README.md rename to java_8/README.md diff --git a/pom.xml b/java_8/pom.xml similarity index 100% rename from pom.xml rename to java_8/pom.xml diff --git a/src/test/java/android/BrowserStackSample.java b/java_8/src/test/java/android/BrowserStackSample.java similarity index 100% rename from src/test/java/android/BrowserStackSample.java rename to java_8/src/test/java/android/BrowserStackSample.java diff --git a/src/test/java/android/BrowserStackSampleLocal.java b/java_8/src/test/java/android/BrowserStackSampleLocal.java similarity index 100% rename from src/test/java/android/BrowserStackSampleLocal.java rename to java_8/src/test/java/android/BrowserStackSampleLocal.java diff --git a/src/test/java/ios/BrowserStackSample.java b/java_8/src/test/java/ios/BrowserStackSample.java similarity index 100% rename from src/test/java/ios/BrowserStackSample.java rename to java_8/src/test/java/ios/BrowserStackSample.java diff --git a/src/test/java/ios/BrowserStackSampleLocal.java b/java_8/src/test/java/ios/BrowserStackSampleLocal.java similarity index 100% rename from src/test/java/ios/BrowserStackSampleLocal.java rename to java_8/src/test/java/ios/BrowserStackSampleLocal.java From 7eb080f0690beeea5edd63b17bcec458664cb18e Mon Sep 17 00:00:00 2001 From: deepwired Date: Tue, 17 May 2022 09:10:19 +0530 Subject: [PATCH 46/53] updating readme.md file with links for java7 and java8 --- README.md | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..2a67f71 --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +| [Using Java 7 with MJSONWP protocol](./java_7/README.md) | [Using Java 8 with w3c protocol](./java_8/README.md) | +|--------------------------------------------------------- | ---------------------------------------------------- | \ No newline at end of file From 6b1f7cf4f6320fec4e5913627c25ef9ff91a8711 Mon Sep 17 00:00:00 2001 From: deepwired Date: Tue, 17 May 2022 09:15:19 +0530 Subject: [PATCH 47/53] adding tab navigation for both java/protocol versions --- java_7/README.md | 3 +++ java_8/README.md | 3 +++ 2 files changed, 6 insertions(+) diff --git a/java_7/README.md b/java_7/README.md index c8321a1..cfdda4b 100644 --- a/java_7/README.md +++ b/java_7/README.md @@ -1,3 +1,6 @@ +| Using Java 7 with MJSONWP protocol | [Using Java 8 with w3c protocol](./java_8/README.md) | +|----------------------------------- | ---------------------------------------------------- | + # java-appium-app-browserstack This repository demonstrates how to run Appium Java tests on BrowserStack App Automate. diff --git a/java_8/README.md b/java_8/README.md index 772c5e5..1fdff32 100644 --- a/java_8/README.md +++ b/java_8/README.md @@ -1,3 +1,6 @@ +| [Using Java 7 with MJSONWP protocol](./java_7/README.md) | Using Java 8 with w3c protocol | +|--------------------------------------------------------- | ------------------------------ | + # java-appium-app-browserstack This repository demonstrates how to run Appium Java tests on BrowserStack App Automate. From 92daf59439e9973e0a24581e919c9c63fcf027c7 Mon Sep 17 00:00:00 2001 From: deepwired Date: Tue, 17 May 2022 09:17:16 +0530 Subject: [PATCH 48/53] typo, missed a . in back links --- java_7/README.md | 2 +- java_8/README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/java_7/README.md b/java_7/README.md index cfdda4b..08bcba8 100644 --- a/java_7/README.md +++ b/java_7/README.md @@ -1,4 +1,4 @@ -| Using Java 7 with MJSONWP protocol | [Using Java 8 with w3c protocol](./java_8/README.md) | +| Using Java 7 with MJSONWP protocol | [Using Java 8 with w3c protocol](../java_8/README.md) | |----------------------------------- | ---------------------------------------------------- | # java-appium-app-browserstack diff --git a/java_8/README.md b/java_8/README.md index 1fdff32..3258241 100644 --- a/java_8/README.md +++ b/java_8/README.md @@ -1,4 +1,4 @@ -| [Using Java 7 with MJSONWP protocol](./java_7/README.md) | Using Java 8 with w3c protocol | +| [Using Java 7 with MJSONWP protocol](../java_7/README.md) | Using Java 8 with w3c protocol | |--------------------------------------------------------- | ------------------------------ | # java-appium-app-browserstack From 07080f9ef35329ad65e4ebb1385ff057354f156f Mon Sep 17 00:00:00 2001 From: deepwired Date: Tue, 17 May 2022 09:20:18 +0530 Subject: [PATCH 49/53] linking to repo instead of readme --- README.md | 4 ++-- java_7/README.md | 4 ++-- java_8/README.md | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 2a67f71..a8965f1 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,2 @@ -| [Using Java 7 with MJSONWP protocol](./java_7/README.md) | [Using Java 8 with w3c protocol](./java_8/README.md) | -|--------------------------------------------------------- | ---------------------------------------------------- | \ No newline at end of file +| [Using Java 7 with MJSONWP protocol](./java_7) | [Using Java 8 with w3c protocol](./java_8) | +|----------------------------------------------- | ------------------------------------------ | \ No newline at end of file diff --git a/java_7/README.md b/java_7/README.md index 08bcba8..84f4288 100644 --- a/java_7/README.md +++ b/java_7/README.md @@ -1,5 +1,5 @@ -| Using Java 7 with MJSONWP protocol | [Using Java 8 with w3c protocol](../java_8/README.md) | -|----------------------------------- | ---------------------------------------------------- | +| Using Java 7 with MJSONWP protocol | [Using Java 8 with w3c protocol](../java_8) | +|----------------------------------- | ------------------------------------------- | # java-appium-app-browserstack diff --git a/java_8/README.md b/java_8/README.md index 3258241..a800119 100644 --- a/java_8/README.md +++ b/java_8/README.md @@ -1,5 +1,5 @@ -| [Using Java 7 with MJSONWP protocol](../java_7/README.md) | Using Java 8 with w3c protocol | -|--------------------------------------------------------- | ------------------------------ | +| [Using Java 7 with MJSONWP protocol](../java_7) | Using Java 8 with w3c protocol | +|------------------------------------------------ | ------------------------------ | # java-appium-app-browserstack From b746acae175e89f22bdeea1c7a788ccac59d92af Mon Sep 17 00:00:00 2001 From: deepwired Date: Tue, 17 May 2022 11:25:44 +0530 Subject: [PATCH 50/53] small content updates --- README.md | 4 ++-- java_7/README.md | 6 +++--- java_8/README.md | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index a8965f1..ef3660d 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,2 @@ -| [Using Java 7 with MJSONWP protocol](./java_7) | [Using Java 8 with w3c protocol](./java_8) | -|----------------------------------------------- | ------------------------------------------ | \ No newline at end of file +| [Using Java 7 client with MJSONWP protocol](./java_7) | [Using Java 8 client with w3c protocol](./java_8) | +|------------------------------------------------------ | ------------------------------------------------- | \ No newline at end of file diff --git a/java_7/README.md b/java_7/README.md index 84f4288..91d90d7 100644 --- a/java_7/README.md +++ b/java_7/README.md @@ -1,5 +1,5 @@ -| Using Java 7 with MJSONWP protocol | [Using Java 8 with w3c protocol](../java_8) | -|----------------------------------- | ------------------------------------------- | +| Using Java 7 client with MJSONWP protocol | [Using Java 8 client with w3c protocol](../java_8) | +|------------------------------------------ | -------------------------------------------------- | # java-appium-app-browserstack @@ -9,7 +9,7 @@ This repository demonstrates how to run Appium Java tests on BrowserStack App Au ### Requirements -1. Java 8+ +1. Java 8+ (JDK) - If Java is not installed, follow these instructions: - For Windows, download latest java version from [here](https://java.com/en/download/) and run the installer executable diff --git a/java_8/README.md b/java_8/README.md index a800119..4afdc79 100644 --- a/java_8/README.md +++ b/java_8/README.md @@ -1,5 +1,5 @@ -| [Using Java 7 with MJSONWP protocol](../java_7) | Using Java 8 with w3c protocol | -|------------------------------------------------ | ------------------------------ | +| [Using Java 7 client with MJSONWP protocol](../java_7) | Using Java 8 client with w3c protocol | +|------------------------------------------------------- | ------------------------------------- | # java-appium-app-browserstack @@ -9,7 +9,7 @@ This repository demonstrates how to run Appium Java tests on BrowserStack App Au ### Requirements -1. Java 8+ +1. Java 8+ (JDK) - If Java is not installed, follow these instructions: - For Windows, download latest java version from [here](https://java.com/en/download/) and run the installer executable From dd073c2f293d236cf756dcaf98eb7f80f00963ca Mon Sep 17 00:00:00 2001 From: deepwired Date: Wed, 25 May 2022 13:24:57 +0530 Subject: [PATCH 51/53] updated ios device/os combo --- java_7/src/test/java/ios/BrowserStackSample.java | 4 ++-- java_7/src/test/java/ios/BrowserStackSampleLocal.java | 4 ++-- java_8/src/test/java/ios/BrowserStackSample.java | 4 ++-- java_8/src/test/java/ios/BrowserStackSampleLocal.java | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/java_7/src/test/java/ios/BrowserStackSample.java b/java_7/src/test/java/ios/BrowserStackSample.java index 6fd9eea..50a107b 100644 --- a/java_7/src/test/java/ios/BrowserStackSample.java +++ b/java_7/src/test/java/ios/BrowserStackSample.java @@ -25,8 +25,8 @@ public static void main(String[] args) throws MalformedURLException, Interrupted caps.setCapability("app", "bs://"); // Specify device and os_version for testing - caps.setCapability("device", "iPhone 11 Pro"); - caps.setCapability("os_version", "13"); + caps.setCapability("device", "iPhone X"); + caps.setCapability("os_version", "11"); // Set other BrowserStack capabilities caps.setCapability("project", "First Java Project"); diff --git a/java_7/src/test/java/ios/BrowserStackSampleLocal.java b/java_7/src/test/java/ios/BrowserStackSampleLocal.java index f278a07..f2961a8 100644 --- a/java_7/src/test/java/ios/BrowserStackSampleLocal.java +++ b/java_7/src/test/java/ios/BrowserStackSampleLocal.java @@ -40,8 +40,8 @@ public static void main(String[] args) throws Exception { capabilities.setCapability("app", "bs://"); // Specify device and os_version for testing - capabilities.setCapability("device", "iPhone 11 Pro"); - capabilities.setCapability("os_version", "13"); + capabilities.setCapability("device", "iPhone X"); + capabilities.setCapability("os_version", "11"); // Set the browserstack.local capability to true capabilities.setCapability("browserstack.local", true); diff --git a/java_8/src/test/java/ios/BrowserStackSample.java b/java_8/src/test/java/ios/BrowserStackSample.java index 3b5f864..39eb1b6 100644 --- a/java_8/src/test/java/ios/BrowserStackSample.java +++ b/java_8/src/test/java/ios/BrowserStackSample.java @@ -35,9 +35,9 @@ public static void main(String[] args) caps.setCapability("app", "bs://"); // Specify device and os_version for testing - caps.setCapability("deviceName", "iPhone 11 Pro"); + caps.setCapability("deviceName", "iPhone X"); caps.setCapability("platformName", "ios"); - caps.setCapability("platformVersion", "13"); + caps.setCapability("platformVersion", "11"); // Initialise the remote Webdriver using BrowserStack remote URL // and desired capabilities defined above diff --git a/java_8/src/test/java/ios/BrowserStackSampleLocal.java b/java_8/src/test/java/ios/BrowserStackSampleLocal.java index 5ebf5a0..bdb3fc3 100644 --- a/java_8/src/test/java/ios/BrowserStackSampleLocal.java +++ b/java_8/src/test/java/ios/BrowserStackSampleLocal.java @@ -59,9 +59,9 @@ public static void main(String[] args) throws Exception { capabilities.setCapability("app", "bs://"); // Specify device and os_version for testing - capabilities.setCapability("deviceName", "iPhone 11 Pro"); + capabilities.setCapability("deviceName", "iPhone X"); capabilities.setCapability("platformName", "ios"); - capabilities.setCapability("platformVersion", "13"); + capabilities.setCapability("platformVersion", "11"); // Initialise the remote Webdriver using BrowserStack remote URL // and desired capabilities defined above From 893203559eff97611283638dad6d0d15cfd1aa76 Mon Sep 17 00:00:00 2001 From: deepwired Date: Thu, 26 May 2022 08:38:11 +0530 Subject: [PATCH 52/53] iPhone 12 + iOS 13 --- java_7/src/test/java/ios/BrowserStackSample.java | 4 ++-- java_7/src/test/java/ios/BrowserStackSampleLocal.java | 4 ++-- java_8/src/test/java/ios/BrowserStackSample.java | 4 ++-- java_8/src/test/java/ios/BrowserStackSampleLocal.java | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/java_7/src/test/java/ios/BrowserStackSample.java b/java_7/src/test/java/ios/BrowserStackSample.java index 50a107b..ce5ab08 100644 --- a/java_7/src/test/java/ios/BrowserStackSample.java +++ b/java_7/src/test/java/ios/BrowserStackSample.java @@ -25,8 +25,8 @@ public static void main(String[] args) throws MalformedURLException, Interrupted caps.setCapability("app", "bs://"); // Specify device and os_version for testing - caps.setCapability("device", "iPhone X"); - caps.setCapability("os_version", "11"); + caps.setCapability("device", "iPhone 12"); + caps.setCapability("os_version", "13"); // Set other BrowserStack capabilities caps.setCapability("project", "First Java Project"); diff --git a/java_7/src/test/java/ios/BrowserStackSampleLocal.java b/java_7/src/test/java/ios/BrowserStackSampleLocal.java index f2961a8..a4af409 100644 --- a/java_7/src/test/java/ios/BrowserStackSampleLocal.java +++ b/java_7/src/test/java/ios/BrowserStackSampleLocal.java @@ -40,8 +40,8 @@ public static void main(String[] args) throws Exception { capabilities.setCapability("app", "bs://"); // Specify device and os_version for testing - capabilities.setCapability("device", "iPhone X"); - capabilities.setCapability("os_version", "11"); + capabilities.setCapability("device", "iPhone 12"); + capabilities.setCapability("os_version", "13"); // Set the browserstack.local capability to true capabilities.setCapability("browserstack.local", true); diff --git a/java_8/src/test/java/ios/BrowserStackSample.java b/java_8/src/test/java/ios/BrowserStackSample.java index 39eb1b6..09d2013 100644 --- a/java_8/src/test/java/ios/BrowserStackSample.java +++ b/java_8/src/test/java/ios/BrowserStackSample.java @@ -35,9 +35,9 @@ public static void main(String[] args) caps.setCapability("app", "bs://"); // Specify device and os_version for testing - caps.setCapability("deviceName", "iPhone X"); + caps.setCapability("deviceName", "iPhone 12"); caps.setCapability("platformName", "ios"); - caps.setCapability("platformVersion", "11"); + caps.setCapability("platformVersion", "13"); // Initialise the remote Webdriver using BrowserStack remote URL // and desired capabilities defined above diff --git a/java_8/src/test/java/ios/BrowserStackSampleLocal.java b/java_8/src/test/java/ios/BrowserStackSampleLocal.java index bdb3fc3..0493d13 100644 --- a/java_8/src/test/java/ios/BrowserStackSampleLocal.java +++ b/java_8/src/test/java/ios/BrowserStackSampleLocal.java @@ -59,9 +59,9 @@ public static void main(String[] args) throws Exception { capabilities.setCapability("app", "bs://"); // Specify device and os_version for testing - capabilities.setCapability("deviceName", "iPhone X"); + capabilities.setCapability("deviceName", "iPhone 12"); capabilities.setCapability("platformName", "ios"); - capabilities.setCapability("platformVersion", "11"); + capabilities.setCapability("platformVersion", "13"); // Initialise the remote Webdriver using BrowserStack remote URL // and desired capabilities defined above From e9ea53aef620df52799beac8b714ff5e2171288d Mon Sep 17 00:00:00 2001 From: JiGsaw_xs <79110820+8ll@users.noreply.github.com> Date: Mon, 30 Jan 2023 07:07:16 +0300 Subject: [PATCH 53/53] Update BrowserStackSample.java --- .../src/test/java/ios/BrowserStackSample.java | 36 ++++--------------- 1 file changed, 7 insertions(+), 29 deletions(-) diff --git a/java_7/src/test/java/ios/BrowserStackSample.java b/java_7/src/test/java/ios/BrowserStackSample.java index ce5ab08..1497bc3 100644 --- a/java_7/src/test/java/ios/BrowserStackSample.java +++ b/java_7/src/test/java/ios/BrowserStackSample.java @@ -1,32 +1,27 @@ package ios; - import java.net.URL; import java.util.List; import java.net.MalformedURLException; - import org.openqa.selenium.support.ui.WebDriverWait; import org.openqa.selenium.remote.DesiredCapabilities; import org.openqa.selenium.support.ui.ExpectedConditions; - import io.appium.java_client.MobileBy; import io.appium.java_client.ios.IOSDriver; import io.appium.java_client.ios.IOSElement; - public class BrowserStackSample { - public static void main(String[] args) throws MalformedURLException, InterruptedException { DesiredCapabilities caps = new DesiredCapabilities(); // Set your access credentials - caps.setCapability("browserstack.user", "YOUR_USERNAME"); - caps.setCapability("browserstack.key", "YOUR_ACCESS_KEY"); + caps.setCapability("browserstack.user", "abdullazizxs_M0W5GX"); + caps.setCapability("browserstack.key", "zS2Tit6YTbuhoCGgbB21"); // Set URL of the application under test - caps.setCapability("app", "bs://"); + caps.setCapability("app", "bs://ff266c82636fc47ee3a615747bc9a7b63857a03d"); // Specify device and os_version for testing - caps.setCapability("device", "iPhone 12"); - caps.setCapability("os_version", "13"); + caps.setCapability("device", "iPhone XS"); + caps.setCapability("os_version", "12"); // Set other BrowserStack capabilities caps.setCapability("project", "First Java Project"); @@ -38,27 +33,10 @@ public static void main(String[] args) throws MalformedURLException, Interrupted // and desired capabilities defined above IOSDriver driver = new IOSDriver( new URL("http://hub-cloud.browserstack.com/wd/hub"), caps); + + // Write your test case statements here - - // Test case for the BrowserStack sample iOS app. - // If you have uploaded your app, update the test case here. - IOSElement textButton = (IOSElement) new WebDriverWait(driver, 30).until( - ExpectedConditions.elementToBeClickable(MobileBy.AccessibilityId("Text Button"))); - textButton.click(); - IOSElement textInput = (IOSElement) new WebDriverWait(driver, 30).until( - ExpectedConditions.elementToBeClickable(MobileBy.AccessibilityId("Text Input"))); - textInput.sendKeys("hello@browserstack.com"); - Thread.sleep(5000); - IOSElement textOutput = (IOSElement) new WebDriverWait(driver, 30).until( - ExpectedConditions.elementToBeClickable(MobileBy.AccessibilityId("Text Output"))); - if(textOutput != null && textOutput.getText().equals("hello@browserstack.com")) - assert(true); - else - assert(false); - // Invoke driver.quit() after the test is done to indicate that the test is completed. driver.quit(); - } - }