The multiverse – one test, two environments
The advantage is that these IfExist()
methods will not stop the test if the object doesn’t exist. Our tests can now be executed in a test environment where new functionality exists, as well as a production environment where the functionality is yet to be pushed. For example, a page may ask for a month to be selected from a list on a long survey navigation path. In the staging environment, this requires the Next button to be explicitly clicked to move to the page. However, in QA, the Next button is removed and the page implicitly moves on once the user selects an item from the list:
Helpers.clickIfExists(await this.btnNext);
There are two approaches to this implementation. First, we could enhance the clickadv()
method with an optional property:
export async function clickAdv(element: WebdriverIO.Element, ifExists: boolean = false) { // isExist code branch here ... }
However, this leads to code that is less clear about...