From d4912b67392a93f97d4ec1fa0ffe321ffbb4a425 Mon Sep 17 00:00:00 2001 From: Rahul Singh Date: Mon, 5 Jan 2026 14:04:13 +0530 Subject: [PATCH] add diverse tests for ios and android --- android/testng-examples/browserstack.yml | 6 +- .../java/com/browserstack/AppiumTest.java | 14 ++- .../src/test/java/com/browserstack/Retry.java | 24 ++++++ .../com/browserstack/modulea/DemoTest.java | 85 ++++++++++++++++++ .../com/browserstack/moduleb/DemoTest.java | 85 ++++++++++++++++++ .../com/browserstack/modulec/DemoTest.java | 85 ++++++++++++++++++ .../com/browserstack/sample-test.testng.xml | 4 +- ios/testng-examples/browserstack.yml | 14 +-- .../java/com/browserstack/AppiumTest.java | 14 ++- .../src/test/java/com/browserstack/Retry.java | 24 ++++++ .../com/browserstack/modulea/DemoTest.java | 86 +++++++++++++++++++ .../com/browserstack/moduleb/DemoTest.java | 85 ++++++++++++++++++ .../com/browserstack/modulec/DemoTest.java | 85 ++++++++++++++++++ .../com/browserstack/sample-test.testng.xml | 4 +- 14 files changed, 603 insertions(+), 12 deletions(-) create mode 100644 android/testng-examples/src/test/java/com/browserstack/Retry.java create mode 100644 android/testng-examples/src/test/java/com/browserstack/modulea/DemoTest.java create mode 100644 android/testng-examples/src/test/java/com/browserstack/moduleb/DemoTest.java create mode 100644 android/testng-examples/src/test/java/com/browserstack/modulec/DemoTest.java create mode 100644 ios/testng-examples/src/test/java/com/browserstack/Retry.java create mode 100644 ios/testng-examples/src/test/java/com/browserstack/modulea/DemoTest.java create mode 100644 ios/testng-examples/src/test/java/com/browserstack/moduleb/DemoTest.java create mode 100644 ios/testng-examples/src/test/java/com/browserstack/modulec/DemoTest.java diff --git a/android/testng-examples/browserstack.yml b/android/testng-examples/browserstack.yml index 7975029..9f50a94 100644 --- a/android/testng-examples/browserstack.yml +++ b/android/testng-examples/browserstack.yml @@ -29,6 +29,8 @@ source: testng:appium-sample-sdk:v1.1 app: ./WikipediaSample.apk #app: ./LocalSample.apk #For running local tests +CUSTOM_TAG_1: bstack_sample + # ======================================= # Platforms (Browsers / Devices to test) # ======================================= @@ -55,7 +57,7 @@ platforms: # Example 1 - If you have configured 3 platforms and set `parallelsPerPlatform` as 2, a total of 6 (2 * 3) parallel threads will be used on BrowserStack # # Example 2 - If you have configured 1 platform and set `parallelsPerPlatform` as 5, a total of 5 (1 * 5) parallel threads will be used on BrowserStack -parallelsPerPlatform: 1 +parallelsPerPlatform: 2 # ========================================== # BrowserStack Local @@ -70,6 +72,8 @@ browserstackLocal: true # (Default false) # forceLocal: true # (Default: false) Set to true if you need to resolve all your traffic via BrowserStack Local tunnel. # Entire list of arguments available here -> https://www.browserstack.com/docs/automate/selenium/manage-incoming-connections +testObservability: true + # =================== # Debugging features # =================== diff --git a/android/testng-examples/src/test/java/com/browserstack/AppiumTest.java b/android/testng-examples/src/test/java/com/browserstack/AppiumTest.java index 72708fc..3c32b12 100644 --- a/android/testng-examples/src/test/java/com/browserstack/AppiumTest.java +++ b/android/testng-examples/src/test/java/com/browserstack/AppiumTest.java @@ -1,9 +1,16 @@ package com.browserstack; import java.net.URL; +import java.time.Duration; +import io.appium.java_client.AppiumBy; import org.openqa.selenium.MutableCapabilities; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; +import org.testng.annotations.AfterClass; import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeMethod; import io.appium.java_client.android.AndroidDriver; @@ -14,13 +21,16 @@ public class AppiumTest { public AndroidDriver driver; - @BeforeMethod(alwaysRun=true) + @BeforeClass(alwaysRun=true) public void setUp() throws Exception { MutableCapabilities capabilities = new UiAutomator2Options(); driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"),capabilities); + WebElement skipButton = (WebElement) new WebDriverWait(driver, Duration.ofSeconds(30)).until( + ExpectedConditions.presenceOfElementLocated(AppiumBy.id("org.wikipedia.alpha:id/fragment_onboarding_skip_button"))); + skipButton.click(); } - @AfterMethod(alwaysRun=true) + @AfterClass(alwaysRun=true) public void tearDown() throws Exception { driver.quit(); } diff --git a/android/testng-examples/src/test/java/com/browserstack/Retry.java b/android/testng-examples/src/test/java/com/browserstack/Retry.java new file mode 100644 index 0000000..4306d38 --- /dev/null +++ b/android/testng-examples/src/test/java/com/browserstack/Retry.java @@ -0,0 +1,24 @@ +package com.browserstack; + +import org.testng.IRetryAnalyzer; +import org.testng.ITestResult; + +public class Retry implements IRetryAnalyzer { + private int count = 0; + private static int maxTry = 2; + @Override + public boolean retry(ITestResult iTestResult) { + if (!iTestResult.isSuccess()) { + if (count < maxTry) { + count++; + iTestResult.setStatus(ITestResult.FAILURE); + return true; + } else { + iTestResult.setStatus(ITestResult.FAILURE); + } + } else { + iTestResult.setStatus(ITestResult.SUCCESS); + } + return false; + } +} diff --git a/android/testng-examples/src/test/java/com/browserstack/modulea/DemoTest.java b/android/testng-examples/src/test/java/com/browserstack/modulea/DemoTest.java new file mode 100644 index 0000000..8ba70f2 --- /dev/null +++ b/android/testng-examples/src/test/java/com/browserstack/modulea/DemoTest.java @@ -0,0 +1,85 @@ +package com.browserstack.modulea; + +import com.browserstack.AppiumTest; +import com.browserstack.Retry; +import io.appium.java_client.AppiumBy; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; +import org.testng.Assert; +import org.testng.annotations.Test; + +import java.time.Duration; +import java.util.List; + +public class DemoTest extends AppiumTest { + + @Test(groups = {"regression"}) + public void flakyTest_intermittentlyPassesAndFails() throws Exception { + WebElement searchElement = (WebElement) new WebDriverWait(driver, Duration.ofSeconds(30)).until( + ExpectedConditions.elementToBeClickable(AppiumBy.accessibilityId("Search Wikipedia"))); + + searchElement.click(); + WebElement insertTextElement = (WebElement) new WebDriverWait(driver, Duration.ofSeconds(30)).until( + ExpectedConditions.elementToBeClickable(AppiumBy.id("org.wikipedia.alpha:id/search_src_text"))); + String searchText = Math.random() > 0.7 ? "BrowserStack" : "sldkjlksljlksjlfs"; + insertTextElement.sendKeys(searchText); + Thread.sleep(5000); + + List allProductsName = driver.findElements(AppiumBy.className("android.widget.TextView")); + Assert.assertTrue(allProductsName.size() > 0); + } + + @Test(groups = {"regression"}) + public void alwaysFailingTest_missingElement1() throws Exception { + WebElement missingElement = (WebElement) new WebDriverWait(driver, Duration.ofSeconds(30)).until( + ExpectedConditions.elementToBeClickable(AppiumBy.id("org.wikipedia.alpha:id/missing_element"))); + missingElement.click(); + } + + @Test + public void alwaysFailingTest_sameStacktrace1() throws Exception { + WebElement missingElement = (WebElement) new WebDriverWait(driver, Duration.ofSeconds(30)).until( + ExpectedConditions.elementToBeClickable(AppiumBy.id("org.wikipedia.alpha:id/common_incorrect_element"))); + missingElement.click(); + } + + @Test + public void alwaysFailingTest_sameStacktrace2() throws Exception { + WebElement missingElement = (WebElement) new WebDriverWait(driver, Duration.ofSeconds(30)).until( + ExpectedConditions.elementToBeClickable(AppiumBy.id("org.wikipedia.alpha:id/common_incorrect_element"))); + missingElement.click(); + } + + @Test(retryAnalyzer = Retry.class) + public void testWithFrameworkLevelRetry_2RetriesConfigured() { + Integer result = Math.random() > 0.7 ? 6 : 9; + Assert.assertEquals((int) result, 6 + 3); + } + + @Test(retryAnalyzer = Retry.class) + public void anotherTestWithFrameworkLevelRetry_2RetriesConfigured() { + Integer result = Math.random() > 0.7 ? 6 : 9; + Assert.assertEquals((int) result, 3 + 3); + } + + @Test(groups = {"regression", "must_pass"}) + public void alwaysPassingTest_exampleA() { + Assert.assertTrue(true); + } + + @Test + public void alwaysPassingTest_exampleB() { + Assert.assertTrue(true); + } + + @Test + public void alwaysPassingTest_exampleC() { + Assert.assertTrue(true); + } + + @Test + public void alwaysPassingTest_exampleD() { + Assert.assertTrue(true); + } +} diff --git a/android/testng-examples/src/test/java/com/browserstack/moduleb/DemoTest.java b/android/testng-examples/src/test/java/com/browserstack/moduleb/DemoTest.java new file mode 100644 index 0000000..e8928d1 --- /dev/null +++ b/android/testng-examples/src/test/java/com/browserstack/moduleb/DemoTest.java @@ -0,0 +1,85 @@ +package com.browserstack.moduleb; + +import com.browserstack.AppiumTest; +import com.browserstack.Retry; +import io.appium.java_client.AppiumBy; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; +import org.testng.Assert; +import org.testng.annotations.Test; + +import java.time.Duration; +import java.util.List; + +public class DemoTest extends AppiumTest { + + @Test + public void flakyTest_intermittentlyPassesAndFails() throws Exception { + WebElement searchElement = (WebElement) new WebDriverWait(driver, Duration.ofSeconds(30)).until( + ExpectedConditions.elementToBeClickable(AppiumBy.accessibilityId("Search Wikipedia"))); + + searchElement.click(); + WebElement insertTextElement = (WebElement) new WebDriverWait(driver, Duration.ofSeconds(30)).until( + ExpectedConditions.elementToBeClickable(AppiumBy.id("org.wikipedia.alpha:id/search_src_text"))); + String searchText = Math.random() > 0.7 ? "BrowserStack" : "sldkjlksljlksjlfs"; + insertTextElement.sendKeys(searchText); + Thread.sleep(5000); + + List allProductsName = driver.findElements(AppiumBy.className("android.widget.TextView")); + Assert.assertTrue(allProductsName.size() > 0); + } + + @Test + public void alwaysFailingTest_missingElement1() throws Exception { + WebElement missingElement = (WebElement) new WebDriverWait(driver, Duration.ofSeconds(30)).until( + ExpectedConditions.elementToBeClickable(AppiumBy.id("org.wikipedia.alpha:id/missing_element"))); + missingElement.click(); + } + + @Test + public void alwaysFailingTest_sameStacktrace1() throws Exception { + WebElement missingElement = (WebElement) new WebDriverWait(driver, Duration.ofSeconds(30)).until( + ExpectedConditions.elementToBeClickable(AppiumBy.id("org.wikipedia.alpha:id/common_incorrect_element"))); + missingElement.click(); + } + + @Test + public void alwaysFailingTest_sameStacktrace2() throws Exception { + WebElement missingElement = (WebElement) new WebDriverWait(driver, Duration.ofSeconds(30)).until( + ExpectedConditions.elementToBeClickable(AppiumBy.id("org.wikipedia.alpha:id/common_incorrect_element"))); + missingElement.click(); + } + + @Test(retryAnalyzer = Retry.class) + public void testWithFrameworkLevelRetry_2RetriesConfigured() { + Integer result = Math.random() > 0.7 ? 6 : 9; + Assert.assertEquals((int) result, 6 + 3); + } + + @Test(retryAnalyzer = Retry.class) + public void anotherTestWithFrameworkLevelRetry_2RetriesConfigured() { + Integer result = Math.random() > 0.7 ? 6 : 9; + Assert.assertEquals((int) result, 3 + 3); + } + + @Test + public void alwaysPassingTest_exampleA() { + Assert.assertTrue(true); + } + + @Test + public void alwaysPassingTest_exampleB() { + Assert.assertTrue(true); + } + + @Test(groups = {"regression", "must_pass"}) + public void alwaysPassingTest_exampleC() { + Assert.assertTrue(true); + } + + @Test + public void alwaysPassingTest_exampleD() { + Assert.assertTrue(true); + } +} diff --git a/android/testng-examples/src/test/java/com/browserstack/modulec/DemoTest.java b/android/testng-examples/src/test/java/com/browserstack/modulec/DemoTest.java new file mode 100644 index 0000000..96f42bc --- /dev/null +++ b/android/testng-examples/src/test/java/com/browserstack/modulec/DemoTest.java @@ -0,0 +1,85 @@ +package com.browserstack.modulec; + +import com.browserstack.AppiumTest; +import com.browserstack.Retry; +import io.appium.java_client.AppiumBy; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; +import org.testng.Assert; +import org.testng.annotations.Test; + +import java.time.Duration; +import java.util.List; + +public class DemoTest extends AppiumTest { + + @Test(groups = {"regression"}) + public void flakyTest_intermittentlyPassesAndFails() throws Exception { + WebElement searchElement = (WebElement) new WebDriverWait(driver, Duration.ofSeconds(30)).until( + ExpectedConditions.elementToBeClickable(AppiumBy.accessibilityId("Search Wikipedia"))); + + searchElement.click(); + WebElement insertTextElement = (WebElement) new WebDriverWait(driver, Duration.ofSeconds(30)).until( + ExpectedConditions.elementToBeClickable(AppiumBy.id("org.wikipedia.alpha:id/search_src_text"))); + String searchText = Math.random() > 0.7 ? "BrowserStack" : "sldkjlksljlksjlfs"; + insertTextElement.sendKeys(searchText); + Thread.sleep(5000); + + List allProductsName = driver.findElements(AppiumBy.className("android.widget.TextView")); + Assert.assertTrue(allProductsName.size() > 0); + } + + @Test + public void alwaysFailingTest_missingElement1() throws Exception { + WebElement missingElement = (WebElement) new WebDriverWait(driver, Duration.ofSeconds(30)).until( + ExpectedConditions.elementToBeClickable(AppiumBy.id("org.wikipedia.alpha:id/missing_element"))); + missingElement.click(); + } + + @Test(groups = {"p1"}) + public void alwaysFailingTest_sameStacktrace1() throws Exception { + WebElement missingElement = (WebElement) new WebDriverWait(driver, Duration.ofSeconds(30)).until( + ExpectedConditions.elementToBeClickable(AppiumBy.id("org.wikipedia.alpha:id/common_incorrect_element"))); + missingElement.click(); + } + + @Test(groups = {"regression", "p1"}) + public void alwaysFailingTest_sameStacktrace2() throws Exception { + WebElement missingElement = (WebElement) new WebDriverWait(driver, Duration.ofSeconds(30)).until( + ExpectedConditions.elementToBeClickable(AppiumBy.id("org.wikipedia.alpha:id/common_incorrect_element"))); + missingElement.click(); + } + + @Test(retryAnalyzer = Retry.class) + public void testWithFrameworkLevelRetry_2RetriesConfigured() { + Integer result = Math.random() > 0.7 ? 6 : 9; + Assert.assertEquals((int) result, 6 + 3); + } + + @Test(retryAnalyzer = Retry.class) + public void anotherTestWithFrameworkLevelRetry_2RetriesConfigured() { + Integer result = Math.random() > 0.7 ? 6 : 9; + Assert.assertEquals((int) result, 3 + 3); + } + + @Test + public void alwaysPassingTest_exampleA() { + Assert.assertTrue(true); + } + + @Test(groups = {"regression", "must_pass"}) + public void alwaysPassingTest_exampleB() { + Assert.assertTrue(true); + } + + @Test + public void alwaysPassingTest_exampleC() { + Assert.assertTrue(true); + } + + @Test + public void alwaysPassingTest_exampleD() { + Assert.assertTrue(true); + } +} diff --git a/android/testng-examples/src/test/resources/com/browserstack/sample-test.testng.xml b/android/testng-examples/src/test/resources/com/browserstack/sample-test.testng.xml index e5ee774..aa202ff 100644 --- a/android/testng-examples/src/test/resources/com/browserstack/sample-test.testng.xml +++ b/android/testng-examples/src/test/resources/com/browserstack/sample-test.testng.xml @@ -3,7 +3,9 @@ - + + + diff --git a/ios/testng-examples/browserstack.yml b/ios/testng-examples/browserstack.yml index 9d40e19..9ee69c8 100644 --- a/ios/testng-examples/browserstack.yml +++ b/ios/testng-examples/browserstack.yml @@ -36,11 +36,11 @@ app: ./BStackSampleApp.ipa # Entire list available here -> (https://www.browserstack.com/list-of-browsers-and-platforms/automate) platforms: - - deviceName: iPhone 14 Pro Max - osVersion: 16 + - deviceName: iPhone 15 Pro + osVersion: 17 platformName: ios - - deviceName: iPhone XR - osVersion: 15 + - deviceName: iPhone 16 + osVersion: 18 platformName: ios - deviceName: iPhone 15 osVersion: 17 @@ -55,7 +55,11 @@ platforms: # Example 1 - If you have configured 3 platforms and set `parallelsPerPlatform` as 2, a total of 6 (2 * 3) parallel threads will be used on BrowserStack # # Example 2 - If you have configured 1 platform and set `parallelsPerPlatform` as 5, a total of 5 (1 * 5) parallel threads will be used on BrowserStack -parallelsPerPlatform: 1 +parallelsPerPlatform: 2 + +CUSTOM_TAG_1: bstack_sample + +testObservability: true # ========================================== # BrowserStack Local diff --git a/ios/testng-examples/src/test/java/com/browserstack/AppiumTest.java b/ios/testng-examples/src/test/java/com/browserstack/AppiumTest.java index 7101fca..c8c191e 100644 --- a/ios/testng-examples/src/test/java/com/browserstack/AppiumTest.java +++ b/ios/testng-examples/src/test/java/com/browserstack/AppiumTest.java @@ -1,9 +1,16 @@ package com.browserstack; import java.net.URL; +import java.time.Duration; +import io.appium.java_client.AppiumBy; import org.openqa.selenium.MutableCapabilities; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; +import org.testng.annotations.AfterClass; import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeMethod; import io.appium.java_client.ios.IOSDriver; @@ -14,13 +21,16 @@ public class AppiumTest { public IOSDriver driver; - @BeforeMethod(alwaysRun=true) + @BeforeClass(alwaysRun=true) public void setUp() throws Exception { MutableCapabilities options = new XCUITestOptions(); driver = new IOSDriver(new URL("http://127.0.0.1:4723/wd/hub"),options); + WebElement textButton = (WebElement) new WebDriverWait(driver, Duration.ofSeconds(30)).until( + ExpectedConditions.elementToBeClickable(AppiumBy.accessibilityId("Text Button"))); + textButton.click(); } - @AfterMethod(alwaysRun=true) + @AfterClass(alwaysRun=true) public void tearDown() throws Exception { driver.quit(); } diff --git a/ios/testng-examples/src/test/java/com/browserstack/Retry.java b/ios/testng-examples/src/test/java/com/browserstack/Retry.java new file mode 100644 index 0000000..4306d38 --- /dev/null +++ b/ios/testng-examples/src/test/java/com/browserstack/Retry.java @@ -0,0 +1,24 @@ +package com.browserstack; + +import org.testng.IRetryAnalyzer; +import org.testng.ITestResult; + +public class Retry implements IRetryAnalyzer { + private int count = 0; + private static int maxTry = 2; + @Override + public boolean retry(ITestResult iTestResult) { + if (!iTestResult.isSuccess()) { + if (count < maxTry) { + count++; + iTestResult.setStatus(ITestResult.FAILURE); + return true; + } else { + iTestResult.setStatus(ITestResult.FAILURE); + } + } else { + iTestResult.setStatus(ITestResult.SUCCESS); + } + return false; + } +} diff --git a/ios/testng-examples/src/test/java/com/browserstack/modulea/DemoTest.java b/ios/testng-examples/src/test/java/com/browserstack/modulea/DemoTest.java new file mode 100644 index 0000000..5297168 --- /dev/null +++ b/ios/testng-examples/src/test/java/com/browserstack/modulea/DemoTest.java @@ -0,0 +1,86 @@ +package com.browserstack.modulea; + +import com.browserstack.AppiumTest; +import com.browserstack.Retry; +import io.appium.java_client.AppiumBy; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; +import org.testng.Assert; +import org.testng.annotations.Test; + +import java.time.Duration; +import java.util.List; + +public class DemoTest extends AppiumTest { + + @Test(groups = {"regression", "p1"}) + public void flakyTest_intermittentlyPassesAndFails() throws Exception { + WebElement textInput = (WebElement) new WebDriverWait(driver, Duration.ofSeconds(30)).until( + ExpectedConditions.elementToBeClickable(AppiumBy.accessibilityId("Text Input"))); + String inputText = Math.random() > 0.7 ? "hello@browserstack.com" : "dlsjfkjlskjd"; + textInput.sendKeys(inputText+"\n"); + + Thread.sleep(5000); + + WebElement textOutput = (WebElement) new WebDriverWait(driver, Duration.ofSeconds(30)).until( + ExpectedConditions.elementToBeClickable(AppiumBy.accessibilityId("Text Output"))); + + Assert.assertEquals(textOutput.getText(),"hello@browserstack.com"); + } + + @Test + public void alwaysFailingTest_missingElement1() throws Exception { + throw new Exception("CustomException: Unable to locate element id xyz in app"); + } + + @Test + public void alwaysFailingTest_sameStacktrace1() throws Exception { + throw new Exception("InvalidParamsException: Received method signature does not match expected signature"); + } + + @Test + public void alwaysFailingTest_sameStacktrace2() throws Exception { + throw new Exception("InvalidParamsException: Received method signature does not match expected signature"); + } + + @Test(retryAnalyzer = Retry.class) + public void testWithFrameworkLevelRetry_2RetriesConfigured() { + Integer result = Math.random() > 0.7 ? 6 : 9; + try { + Assert.assertEquals((int) result, 6 + 3); + } catch (Exception e) { + throw new RuntimeException("Test failed. Will retry if more retries are configured, else will mark test as failed."); + } + } + + @Test(retryAnalyzer = Retry.class) + public void anotherTestWithFrameworkLevelRetry_2RetriesConfigured() { + Integer result = Math.random() > 0.7 ? 6 : 9; + try { + Assert.assertEquals((int) result, 3 + 3); + } catch (Exception e) { + throw new RuntimeException("Test failed. Will retry if more retries are configured, else will mark test as failed."); + } + } + + @Test + public void alwaysPassingTest_exampleA() { + Assert.assertTrue(true); + } + + @Test(groups = {"p1"}) + public void alwaysPassingTest_exampleB() { + Assert.assertTrue(true); + } + + @Test(groups = {"regression", "must_pass"}) + public void alwaysPassingTest_exampleC() { + Assert.assertTrue(true); + } + + @Test + public void alwaysPassingTest_exampleD() { + Assert.assertTrue(true); + } +} diff --git a/ios/testng-examples/src/test/java/com/browserstack/moduleb/DemoTest.java b/ios/testng-examples/src/test/java/com/browserstack/moduleb/DemoTest.java new file mode 100644 index 0000000..fa54278 --- /dev/null +++ b/ios/testng-examples/src/test/java/com/browserstack/moduleb/DemoTest.java @@ -0,0 +1,85 @@ +package com.browserstack.moduleb; + +import com.browserstack.AppiumTest; +import com.browserstack.Retry; +import io.appium.java_client.AppiumBy; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; +import org.testng.Assert; +import org.testng.annotations.Test; + +import java.time.Duration; + +public class DemoTest extends AppiumTest { + + @Test(groups = {"regression"}) + public void flakyTest_intermittentlyPassesAndFails() throws Exception { + WebElement textInput = (WebElement) new WebDriverWait(driver, Duration.ofSeconds(30)).until( + ExpectedConditions.elementToBeClickable(AppiumBy.accessibilityId("Text Input"))); + String inputText = Math.random() > 0.7 ? "hello@browserstack.com" : "dlsjfkjlskjd"; + textInput.sendKeys(inputText+"\n"); + + Thread.sleep(5000); + + WebElement textOutput = (WebElement) new WebDriverWait(driver, Duration.ofSeconds(30)).until( + ExpectedConditions.elementToBeClickable(AppiumBy.accessibilityId("Text Output"))); + + Assert.assertEquals(textOutput.getText(),"hello@browserstack.com"); + } + + @Test + public void alwaysFailingTest_missingElement1() throws Exception { + throw new Exception("CustomException: Unable to locate element id xyz in app"); + } + + @Test(groups = {"regression", "p1"}) + public void alwaysFailingTest_sameStacktrace1() throws Exception { + throw new Exception("InvalidParamsException: Received method signature does not match expected signature"); + } + + @Test + public void alwaysFailingTest_sameStacktrace2() throws Exception { + throw new Exception("InvalidParamsException: Received method signature does not match expected signature"); + } + + @Test(retryAnalyzer = Retry.class) + public void testWithFrameworkLevelRetry_2RetriesConfigured() { + Integer result = Math.random() > 0.7 ? 6 : 9; + try { + Assert.assertEquals((int) result, 6 + 3); + } catch (Exception e) { + throw new RuntimeException("Test failed. Will retry if more retries are configured, else will mark test as failed."); + } + } + + @Test(retryAnalyzer = Retry.class) + public void anotherTestWithFrameworkLevelRetry_2RetriesConfigured() { + Integer result = Math.random() > 0.7 ? 6 : 9; + try { + Assert.assertEquals((int) result, 3 + 3); + } catch (Exception e) { + throw new RuntimeException("Test failed. Will retry if more retries are configured, else will mark test as failed."); + } + } + + @Test + public void alwaysPassingTest_exampleA() { + Assert.assertTrue(true); + } + + @Test + public void alwaysPassingTest_exampleB() { + Assert.assertTrue(true); + } + + @Test + public void alwaysPassingTest_exampleC() { + Assert.assertTrue(true); + } + + @Test + public void alwaysPassingTest_exampleD() { + Assert.assertTrue(true); + } +} diff --git a/ios/testng-examples/src/test/java/com/browserstack/modulec/DemoTest.java b/ios/testng-examples/src/test/java/com/browserstack/modulec/DemoTest.java new file mode 100644 index 0000000..9b11f19 --- /dev/null +++ b/ios/testng-examples/src/test/java/com/browserstack/modulec/DemoTest.java @@ -0,0 +1,85 @@ +package com.browserstack.modulec; + +import com.browserstack.AppiumTest; +import com.browserstack.Retry; +import io.appium.java_client.AppiumBy; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; +import org.testng.Assert; +import org.testng.annotations.Test; + +import java.time.Duration; + +public class DemoTest extends AppiumTest { + + @Test + public void flakyTest_intermittentlyPassesAndFails() throws Exception { + WebElement textInput = (WebElement) new WebDriverWait(driver, Duration.ofSeconds(30)).until( + ExpectedConditions.elementToBeClickable(AppiumBy.accessibilityId("Text Input"))); + String inputText = Math.random() < 0.7 ? "hello@browserstack.com" : "dlsjfkjlskjd"; + textInput.sendKeys(inputText+"\n"); + + Thread.sleep(5000); + + WebElement textOutput = (WebElement) new WebDriverWait(driver, Duration.ofSeconds(30)).until( + ExpectedConditions.elementToBeClickable(AppiumBy.accessibilityId("Text Output"))); + + Assert.assertEquals(textOutput.getText(),"hello@browserstack.com"); + } + + @Test + public void alwaysFailingTest_missingElement1() throws Exception { + throw new Exception("CustomException: Unable to locate element id xyz in app"); + } + + @Test + public void alwaysFailingTest_sameStacktrace1() throws Exception { + throw new Exception("InvalidParamsException: Received method signature does not match expected signature"); + } + + @Test + public void alwaysFailingTest_sameStacktrace2() throws Exception { + throw new Exception("InvalidParamsException: Received method signature does not match expected signature"); + } + + @Test(retryAnalyzer = Retry.class) + public void testWithFrameworkLevelRetry_2RetriesConfigured() { + Integer result = Math.random() > 0.7 ? 6 : 9; + try { + Assert.assertEquals((int) result, 6 + 3); + } catch (Exception e) { + throw new RuntimeException("Test failed. Will retry if more retries are configured, else will mark test as failed."); + } + } + + @Test(retryAnalyzer = Retry.class) + public void anotherTestWithFrameworkLevelRetry_2RetriesConfigured() { + Integer result = Math.random() > 0.7 ? 6 : 9; + try { + Assert.assertEquals((int) result, 3 + 3); + } catch (Exception e) { + throw new RuntimeException("Test failed. Will retry if more retries are configured, else will mark test as failed."); + } + } + + @Test + public void alwaysPassingTest_exampleA() { + Assert.assertTrue(true); + } + + @Test + public void alwaysPassingTest_exampleB() { + Assert.assertTrue(true); + } + + @Test + public void alwaysPassingTest_exampleC() { + Assert.assertTrue(true); + } + + @Test + public void alwaysPassingTest_exampleD() { + Assert.assertTrue(true); + } +} diff --git a/ios/testng-examples/src/test/resources/com/browserstack/sample-test.testng.xml b/ios/testng-examples/src/test/resources/com/browserstack/sample-test.testng.xml index e5ee774..aa202ff 100644 --- a/ios/testng-examples/src/test/resources/com/browserstack/sample-test.testng.xml +++ b/ios/testng-examples/src/test/resources/com/browserstack/sample-test.testng.xml @@ -3,7 +3,9 @@ - + + +