Hi All,
I hope you are well.
I have a maven project currently running on Appium, Cucumber and I use Junit.
When I run the tests individually, they work as they should. For example, If I run feature 1 alone, it works as normal. I noticed that when I run the entire test suite, Only the first one passes and the rest of the tests fails Giving an error such as: cannot locate element.
Note: The tests are independent, so they don’t depend on another test or state
I have checked a couple of resources online, but haven’t seen any direct solution.
I have added some code snippets below.
This is my DriverManagerTest Class
public class DriverManagerTest {
private AppiumDriver driver;
public AppiumDriver getDriver() {
if (driver == null) {
throw new IllegalStateException("Driver not initialized. Call androidLaunch() or iosLaunch() first.");
}
return driver;
}
public void iosLaunch () throws MalformedURLException, URISyntaxException {
XCUITestOptions options = new XCUITestOptions();
options.setDeviceName("iPhone 15");
options.setPlatformVersion("17.2");
options.setApp(System.getProperty("user.dir")+"/src/test/resources/app/App.zip");
options.setCapability("automationName", "XCUITest");
options.setCapability("autoAcceptAlerts", true); // Automatically accept system alerts
driver = new IOSDriver(new URI("http://127.0.0.1:4723").toURL(), options);
}
public void quitDriver() {
if (driver != null) {
driver.quit();
}
}
This is my Step Definition for the Wishlist below:
public class Wishlist {
AppiumDriver driver;
DriverManagerTest driverManagerTest;
WishlistPage wishlistPage;
@Before
public void setupDriver() throws MalformedURLException, URISyntaxException {
driverManagerTest = new DriverManagerTest();
// Set up the iOS driver
driverManagerTest.iosLaunch();
driver = driverManagerTest.getDriver();
wishlistPage = new WishlistPage(driver);
}
@After
public void tearDownDriver() {
driverManagerTest.quitDriver();
}
// i have some steps below with @When etc...
This is my step definition for Checkout
public class Checkout {
AppiumDriver driver;
DriverManagerTest driverManagerTest;
CheckoutPage checkoutPage;
@Before
public void setupDriver() throws MalformedURLException, URISyntaxException {
driverManagerTest = new DriverManagerTest();
// Set up the iOS driver
driverManagerTest.iosLaunch();
driver = driverManagerTest.getDriver();
checkoutPage = new CheckoutPage(driver);
}
@After
public void tearDownDriver() {
driverManagerTest.quitDriver();
}
Note: I use page object model. Simulator Device: iOS 15 v17.2
Any idea how to make the entire test suite run? When I run them individually, they work normal, but running the entire test suite, only the first test / feature file passes, the rest fails.
Thank you.