Skip to content

Instantly share code, notes, and snippets.

@nadvolod
Created February 20, 2024 13:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nadvolod/eacafbdc9baab9b5799b0c9a942e8ad5 to your computer and use it in GitHub Desktop.
Save nadvolod/eacafbdc9baab9b5799b0c9a942e8ad5 to your computer and use it in GitHub Desktop.
Test ordering problem
// Problem: Test order dependency
@FixMethodOrder(MethodSorters.NAME_ASCENDING) // This ensures the test methods are executed in lexicographical order by their names
public class TestOrderDependency {
private static WebDriver driver;
@BeforeClass
public static void setUpClass() throws Exception {
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability("browserName", "chrome");
// Additional Sauce Labs configuration
driver = new RemoteWebDriver(new URL("http://ondemand.saucelabs.com:80/wd/hub"), caps);
}
@Test
public void test1_NavigateToExample() {
driver.navigate().to("https://example.com");
// Actions for first part of a dependent test sequence
}
@Test
public void test2_PerformNextAction() {
// Assumes test1_NavigateToExample has already run
// Further actions that depend on the outcome of test1
}
}
// Solution: Independent tests
public class IndependentTestsSolution {
private WebDriver driver;
@Before
public void setUp() throws Exception {
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability("browserName", "chrome");
// Additional Sauce Labs configuration
driver = new RemoteWebDriver(new URL("xyz"), caps);
}
@Test
public void testNavigateToExample() {
driver.navigate().to("https://example.com");
// Independent test action
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment