Created
February 20, 2024 13:07
-
-
Save nadvolod/eacafbdc9baab9b5799b0c9a942e8ad5 to your computer and use it in GitHub Desktop.
Test ordering problem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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