I am currently using WebdriverIO along with Typescript for automating an Android app. Scenario:
- Go to the Training Page
- Get the Session name (This value changes dynamically)
- I want to store the retrieved session name in a variable and then later assert it
I have implemented the following code. However, it is not working as expected. Can someone please help me identify what I have done wrong here?
Thank you!!
training.ts
import BaseAppScreen from "./base-app.screen";
const SELECTORS = {
Training_Card_Session_Name: (`~trainingItemTitle0`), // This is the dynamic element
};
export default class TrainingScreen extends BaseAppScreen{
constructor() {
super();
$(SELECTORS.Training_Card_Session_Name).waitForDisplayed();
}
getSessionNameOfTrainingCard(): string{
var trainingSessionName = $(SELECTORS.Training_Card_Session_Name).getText();
return trainingSessionName;
}
}
training.spec.ts
import TrainingScreen from '../screenobjects/training.screen';
describe('Training Sessions', () => {
let trainingScreen: TrainingScreen;
let trainingSessionName: string;
beforeAll(() => {
loginScreen = new LoginScreen();
});
it(`Select a Training Card`, () => {
trainingScreen.getSessionNameOfTrainingCard();
expect(trainingScreen.getSessionHeaderTitle()).toEqual(trainingSessionName); // Assertion of stored text value
});
});