Answer the question
In order to leave comments, you need to log in
How to solve the page navigation problem in e2e testing?
Good day,
I am writing e2e tests for a project, I have problems with logging in.
Entrance:
browser.get('/login');
element(by.css('input[formControlName=email]')).sendKeys('blablabla');
element(by.css('input[formControlName=password]')).sendKeys('blablabla');
element(by.id('login')).click();
describe('Project Test', () => {
let page: TestPage;
let auth: Auth();
beforeEach(() => {
page = new TestPage();
auth = new Auth();
});
if('should test', () => {
auth.login();
// далее идет переход на страницу и клик по элементу который видимо еще не существует и тест падает
});
});
Answer the question
In order to leave comments, you need to log in
At the moment I have implemented everything as follows. The e2e directory contains the following directories:
- /+page1 - tests for page 1
- /+page2 - tests for page 2
- /+page3 - tests for page 3
- /shared - for general solutions /shared contains
auth.ts with the following content :
const DEFAULT_LINK: string = '/';
const EMAIL: string = 'blablabla';
const PASSWORD: string = 'blablabla';
export class Auth {
constructor() {
browser.driver.manage().window().maximize();
browser.get(DEFAULT_LINK);
this.login();
}
login() {
browser.sleep(1000);
const email = element(by.css('input[formControlName=email]'));
const pass = element(by.css('input[formControlName=password]'));
const button = element(by.id('login'));
email.sendKeys(EMAIL);
pass.sendKeys(PASSWORD);
button.click();
browser.ignoreSynchronization = true;
browser.sleep(1000);
}
logout() {
browser.sleep(1000);
const buttonLogin = element(by.xpath('путь до кнопки выхода'));
const buttonConfirm = element(by.xpath('путь до кнопки подтверждения выхода'));
buttonLogout.click();
buttonConfirm.click();
browser.ignoreSynchronization = true;
browser.sleep(1000);
}
}
// imports
describe('Page test1', () => {
let auth: Auth;
let page: Page1;
beforeEach(() => {
auth = new Auth();
page = new Page1();
});
afterEach(() => {
auth.logout(); // Проверяем каждую страницу отдельно, поэтому после завершения теста страницы - разлогиниваемся
});
it('Test 1...', () => {
// некие тесты
});
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question