I'm currently working on an Appium automation framework that is typescript based. The element locator strategy used in this framework is async due to the nature of the plugin I am using, which requires the use of await. However, I encountered some errors when trying to access the settings_button value in the methods.
Visual code indicates that findElementByText should return a promise with the following signature: (method) AppiumDriver.findElementByText(text: string, match?: SearchOptions, waitForElement?: number): Promise
export class HomeScreen extends BasePage {
settings_button = this._driver.findElementByText('Settings',10);
async isDisplayedSettings(){
await (await this.settings_button).isDisplayed();
}
async openSettings(){
await (await this.settings_button).click();
}
}
This setup is utilized within the mocha test framework as shown below.
describe("Firmware Update", () => {
let scanDevices: ScanDevices, genFunc: GenericFunctions, settings: SettingsScreen, homeScreen: HomeScreen;
const defaultWaitTime = 5000;
let driver: AppiumDriver;
before(async () => {
driver = await createDriver();
scanDevices = new ScanDevices(driver);
homeScreen = new HomeScreen(driver);
settings = new SettingsScreen(driver);
genFunc = new GenericFunctions();
await genFunc.timeDelay(10000); //Delay for the headset scan
await scanDevices.clickHeadset();
});
after(async () => {
await driver.quit();
console.log("Quit driver!");
});
afterEach(async function () {
if (this.currentTest.state === "failed") {
await driver.logScreenshot(this.currentTest.title);
}
});
it("should display settings option", async () => {
assert.isTrue(await homeScreen.isDisplayedSettings(),"Option should be displayed");
});
it("should tap settings option", async () => {
await homeScreen.openSettings();
assert.isTrue(await settings.isDisplayeUpdatebutton(),"Expecting Settings screen to open");
});