I am trying to run two automated tests for an app with the same function but with different outcomes (on an Android app but will be using iOS in a few months). One is to turn on notifications in the app and the other test is to skip app notifications.
When these tests individually they pass however when I run sequentially the second test fails every single time.
I am getting this error message:
Error in "1: Given I can tap the first next button for the My Garden app"
Error: Can't call click on element with selector "~Next" because element wasn't found
at async CarouselPage.tapOnNextButton (/Users/xxx/Documents/project_wdio-3/features/screens/carouselPages.js:12:9)
at async World.<anonymous> (/Users/xxx/Documents/project_wdio-3/features/step-definitions/carouselPages_steps.js:7:2)
I know it’s a hooks issue however I totally stuck and I need some feedback regarding how to fix this issue. Plus I will be integrating iOS so I hoping it won’t occur testing that app (if that makes sense)
Here’s the code:
Feature file:
Feature: notifications
@regressionTest @notifications
Scenario: As a brand new user I can turn on notifications
Given I can tap the first next button for the My Garden app
And I tap the second next button on the second page of the onbarding carousel
And I can view the next button on the final page of the onboarding carousel to view the sign up page
And I tap the I have an account button
And I enter my registered email
When I enter my registered password
And I tap the sign in button to view my signed in page
Then I tap the turn on notfications button
@regressionTest @notifications
Scenario: As a brand new user I can skip notifications
Given I can tap the first next button for the My Garden app
And I tap the second next button on the second page of the onboarding carousel
And I can view the next button on the final page of the onboarding carousel to view the sign up page
And I tap the I have an account button
And I enter my registered email
When I enter my registered password
Then I tap the skip icon to ignore notifications
Screen Objects
class notifcations {
get notificationButton () {
return $('~Okay');
}
get skipNotifcations () {
return $('~Skip');
}
}
module.exports = new notifcations();
Step definition file
const { When, Then } = require ('@wdio/cucumber-framework');
const RhsNofications = require ('../screens/notifications')
Then(/^I tap the turn on notfications button$/,async() => {
await driver.switchContext("NATIVE_APP");
RhsNofications.notificationButton.click();
await driver.pause(15000);
});
Then(/^I tap the skip icon to ignore notfications$/,async () => {
await driver.switchContext("NATIVE_APP");
RhsNofications.skipNotifcations.click();
await driver.pause(5000);
});
Hooks
Here’s a hooks solution I tried in the Wdio file. It didn’t work.
2
Answers
I had a chat with the developer of webdriverIO and he recommended the following in this instance Reload Session. Here's the documentation
https://webdriver.io/docs/api/browser/reloadSession/
I also want to add this. Add this to end of the WDIO config.js file. I will the app to start with a fresh slate every single time.