Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion browserstack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ 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

source: testng:sample-master:v1.1

Expand Down
4 changes: 3 additions & 1 deletion config/sample-test.testng.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
<suite name="Cross-Platform">
<test name="BStackDemo">
<classes>
<class name="com.browserstack.BStackDemoTest" />
<class name="com.browserstack.modulea.BStackTest" />
<class name="com.browserstack.moduleb.BStackTest" />
<class name="com.browserstack.modulec.BStackTest" />
</classes>
</test>
</suite>
24 changes: 24 additions & 0 deletions src/test/java/com/browserstack/Retry.java
Original file line number Diff line number Diff line change
@@ -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()) { //Check if test not succeed
if (count < maxTry) { //Check if maxtry count is reached
count++; //Increase the maxTry count by 1
iTestResult.setStatus(ITestResult.FAILURE); //Mark test as failed
return true; //Tells TestNG to re-run the test
} else {
iTestResult.setStatus(ITestResult.FAILURE); //If maxCount reached,test marked as failed
}
} else {
iTestResult.setStatus(ITestResult.SUCCESS); //If test passes, TestNG marks it as passed
}
return false;
}
}
9 changes: 5 additions & 4 deletions src/test/java/com/browserstack/SeleniumTest.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
package com.browserstack;

import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;

public class SeleniumTest {
public WebDriver driver;

@BeforeMethod(alwaysRun = true)
@BeforeClass(alwaysRun = true)
@SuppressWarnings("unchecked")
public void setUp() throws Exception {
ChromeOptions options = new ChromeOptions();
options.addArguments("start-maximized");
driver = new ChromeDriver(options);
driver.get("https://www.bstackdemo.com");
}

@AfterMethod(alwaysRun = true)
@AfterClass(alwaysRun = true)
public void tearDown() throws Exception {
driver.quit();
}
Expand Down
73 changes: 73 additions & 0 deletions src/test/java/com/browserstack/modulea/BStackTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package com.browserstack.modulea;

import org.openqa.selenium.By;
import org.testng.Assert;
import org.testng.annotations.Test;

import com.browserstack.Retry;
import com.browserstack.SeleniumTest;

public class BStackTest extends SeleniumTest {
@Test
public void flakyTest_intermittentlyPassesAndFails() throws Exception {
String titleText = Math.random() < 0.5 ? "StackDemo" : "incorrect title";
Assert.assertTrue(driver.getTitle().matches(titleText));
}

@Test
public void alwaysPassingTest_exampleF() {
Assert.assertTrue(true);
}

@Test
public void alwaysPassingTest_exampleG() {
Assert.assertTrue(true);
}

@Test
public void alwaysPassingTest_exampleH() {
Assert.assertTrue(true);
}

@Test
public void alwaysPassingTest_exampleI() {
Assert.assertTrue(true);
}

@Test(groups = "regression")
public void alwaysPassingTest_exampleA() {
Assert.assertTrue(true);
}

@Test
public void alwaysFailingTest_missingElement1() {
driver.findElement(By.xpath("//*[@id=\"missing\"]/div[4]")).click();
}

@Test(groups = "regression")
public void alwaysFailingTest_sameStacktrace1() {
driver.findElement(By.xpath("//*[@id=\"same-stacktrace\"]/div[4]")).click();
}

@Test
public void alwaysFailingTest_sameStacktrace2() {
driver.findElement(By.xpath("//*[@id=\"same-stacktrace\"]/div[4]")).click();
}

@Test
public void passingTest_verifyPageTitle() {
Assert.assertEquals(driver.getTitle(), "StackDemo");
}

@Test(retryAnalyzer = Retry.class)
public void testWithFrameworkLevelRetry_2RetriesConfigured() {
String titleText = Math.random() > 0.7 ? "StackDemo" : "incorrect title";
Assert.assertTrue(driver.getTitle().matches(titleText));
}

@Test(retryAnalyzer = Retry.class)
public void anotherTestWithFrameworkLevelRetry_2RetriesConfigured() {
String titleText = Math.random() > 0.7 ? "StackDemo" : "incorrect title";
Assert.assertTrue(driver.getTitle().matches(titleText));
}
}
88 changes: 88 additions & 0 deletions src/test/java/com/browserstack/moduleb/BStackTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package com.browserstack.moduleb;

import org.openqa.selenium.By;
import org.testng.Assert;
import org.testng.annotations.Test;

import com.browserstack.Retry;
import com.browserstack.SeleniumTest;

public class BStackTest extends SeleniumTest {
@Test(groups = "regression")
public void flakyTest_intermittentlyPassesAndFails() throws Exception {
String titleText = Math.random() < 0.5 ? "StackDemo" : "incorrect title";
Assert.assertTrue(driver.getTitle().matches(titleText));
}

@Test
public void alwaysFailingTest_sameStacktrace1() {
driver.findElement(By.xpath("//*[@id=\"same-stacktrace\"]/div[4]")).click();
}

@Test
public void alwaysFailingTest_sameStacktrace2() {
driver.findElement(By.xpath("//*[@id=\"same-stacktrace\"]/div[4]")).click();
}

@Test
public void alwaysPassingTest_exampleF() {
Assert.assertTrue(true);
}

@Test(groups = "must_pass")
public void alwaysPassingTest_exampleG() {
Assert.assertTrue(true);
}

@Test
public void alwaysPassingTest_exampleH() {
Assert.assertTrue(true);
}

@Test
public void alwaysPassingTest_exampleI() {
Assert.assertTrue(true);
}

@Test
public void alwaysPassingTest_verifyPageTitle() {
Assert.assertEquals(driver.getTitle(), "StackDemo");
}

@Test
public void alwaysPassingTest() {
Assert.assertTrue(6 + 3 == 9);
}

@Test
public void alwaysPassingTest_exampleB() {
Assert.assertTrue(true);
}

@Test
public void alwaysPassingTest_exampleC() {
Assert.assertTrue(true);
}

@Test(groups = {"regression", "p1"})
public void alwaysPassingTest_exampleD() {
Assert.assertTrue(true);
}

@Test
public void alwaysPassingTest_exampleE() {
Assert.assertTrue(true);
}

@Test(retryAnalyzer = Retry.class)
public void testWithFrameworkLevelRetry_2RetriesConfigured() {
String titleText = Math.random() > 0.7 ? "StackDemo" : "incorrect title";
Assert.assertTrue(driver.getTitle().matches(titleText));
}

@Test(retryAnalyzer = Retry.class)
public void anotherTestWithFrameworkLevelRetry_2RetriesConfigured() {
String titleText = Math.random() > 0.7 ? "StackDemo" : "incorrect title";
Assert.assertTrue(driver.getTitle().matches(titleText));
}
}
68 changes: 68 additions & 0 deletions src/test/java/com/browserstack/modulec/BStackTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package com.browserstack.modulec;

import org.openqa.selenium.By;
import org.testng.Assert;
import org.testng.annotations.Test;

import com.browserstack.Retry;
import com.browserstack.SeleniumTest;

public class BStackTest extends SeleniumTest {
@Test(groups = "regression")
public void flakyTest_intermittentlyPassesAndFails() throws Exception {
String titleText = Math.random() < 0.5 ? "StackDemo" : "incorrect title";
Assert.assertTrue(driver.getTitle().matches(titleText));
}

@Test
public void alwaysFailingTest_missingElement1() {
driver.findElement(By.xpath("//*[@id=\"missing\"]/div[4]")).click();
}

@Test
public void alwaysFailingTest_sameStacktrace1() {
driver.findElement(By.xpath("//*[@id=\"same-stacktrace\"]/div[4]")).click();
}

@Test
public void alwaysFailingTest_sameStacktrace2() {
driver.findElement(By.xpath("//*[@id=\"same-stacktrace\"]/div[4]")).click();
}

@Test
public void alwaysPassingTest_exampleF() {
Assert.assertTrue(true);
}

@Test
public void alwaysPassingTest_exampleG() {
Assert.assertTrue(true);
}

@Test(groups = {"p1", "must_pass"})
public void alwaysPassingTest_exampleH() {
Assert.assertTrue(true);
}

@Test
public void alwaysPassingTest_exampleI() {
Assert.assertTrue(true);
}

@Test
public void alwaysPassingTest_verifyPageTitle() {
Assert.assertEquals(driver.getTitle(), "StackDemo");
}

@Test(retryAnalyzer = Retry.class)
public void testWithFrameworkLevelRetry_2RetriesConfigured() {
String titleText = Math.random() > 0.7 ? "StackDemo" : "incorrect title";
Assert.assertTrue(driver.getTitle().matches(titleText));
}

@Test(retryAnalyzer = Retry.class)
public void anotherTestWithFrameworkLevelRetry_2RetriesConfigured() {
String titleText = Math.random() > 0.7 ? "StackDemo" : "incorrect title";
Assert.assertTrue(driver.getTitle().matches(titleText));
}
}