在端到端测试中检查凭据后无法在仪表板中导航
unable to navigate in dashboard after checking credential in e2e testing
我是端到端测试的新手。我正在为 angular 登录页面编写测试用例,它在登录中工作,但在检查登录凭据后我无法导航到主页
我在控制台中得到这个。
- 它将路由到主页当用户名密码正确时,然后转到主页
- 失败:使用定位器未找到元素:By(css 选择器,应用程序主页 h1)
- 登录成功后登录是否生效 — 他应该重定向到默认主页页面
- 失败:使用定位器未找到元素:By(css 选择器,应用程序主页 h1)
这是我的规范文件
import { LoginPage } from './login.po';
import { HomePage } from '../HomePgE2E/home.po';
describe('should Login work', () => {
let page: LoginPage;
let homePage:HomePage;
const wrongCredentias = {
username: '',
password: ''
};
beforeEach(() => {
page = new LoginPage();
homePage= new HomePage();
});
it('when user trying to login with wrong credentials he should stay on “login” page', () => {
page.navigateTo();
page.fillCredentials(wrongCredentias);
expect(page.getPageTitleText()).toEqual('Sign in to your account');
expect(page.getErrorMessage()).toEqual('Email cannot be empty.');
});
it('when login is successful — he should redirect to default home page page ', () => {
page.navigateTo();
page.fillCredentials();
homePage.navigateTo();
expect(homePage.getPageTitleText()).toEqual('welcome');
});
});
此欢迎文字来自
import { browser, by, element } from 'protractor';
export class HomePage {
navigateTo() {
return browser.get('/home');
}
getPageTitleText() {
return element(by.css('app-homepage h1')).getText();
}
}
下面的代码应该可以工作
import { LoginPage } from './login.po';
import { HomePage } from '../HomePgE2E/home.po';
describe('should Login work', () => {
let page: LoginPage;
let homePage:HomePage;
const wrongCredentias = {
username: '',
password: ''
};
beforeEach(async async () => {
page = await new LoginPage();
homePage=await new HomePage();
});
it('when user trying to login with wrong credentials he should stay on “login” page', async () => {
await page.navigateTo();
await page.fillCredentials(wrongCredentias);
expect(page.getPageTitleText()).toEqual('Sign in to your account');
expect(page.getErrorMessage()).toEqual('Email cannot be empty.');
});
it('when login is successful — he should redirect to default home page page ', () => {
await page.navigateTo();
await page.fillCredentials();
await homePage.navigateTo();
expect(homePage.getPageTitleText()).toEqual('welcome');
});
});
我是端到端测试的新手。我正在为 angular 登录页面编写测试用例,它在登录中工作,但在检查登录凭据后我无法导航到主页 我在控制台中得到这个。
- 它将路由到主页当用户名密码正确时,然后转到主页
- 失败:使用定位器未找到元素:By(css 选择器,应用程序主页 h1)
- 登录成功后登录是否生效 — 他应该重定向到默认主页页面
- 失败:使用定位器未找到元素:By(css 选择器,应用程序主页 h1)
这是我的规范文件
import { LoginPage } from './login.po';
import { HomePage } from '../HomePgE2E/home.po';
describe('should Login work', () => {
let page: LoginPage;
let homePage:HomePage;
const wrongCredentias = {
username: '',
password: ''
};
beforeEach(() => {
page = new LoginPage();
homePage= new HomePage();
});
it('when user trying to login with wrong credentials he should stay on “login” page', () => {
page.navigateTo();
page.fillCredentials(wrongCredentias);
expect(page.getPageTitleText()).toEqual('Sign in to your account');
expect(page.getErrorMessage()).toEqual('Email cannot be empty.');
});
it('when login is successful — he should redirect to default home page page ', () => {
page.navigateTo();
page.fillCredentials();
homePage.navigateTo();
expect(homePage.getPageTitleText()).toEqual('welcome');
});
});
此欢迎文字来自
import { browser, by, element } from 'protractor';
export class HomePage {
navigateTo() {
return browser.get('/home');
}
getPageTitleText() {
return element(by.css('app-homepage h1')).getText();
}
}
下面的代码应该可以工作
import { LoginPage } from './login.po';
import { HomePage } from '../HomePgE2E/home.po';
describe('should Login work', () => {
let page: LoginPage;
let homePage:HomePage;
const wrongCredentias = {
username: '',
password: ''
};
beforeEach(async async () => {
page = await new LoginPage();
homePage=await new HomePage();
});
it('when user trying to login with wrong credentials he should stay on “login” page', async () => {
await page.navigateTo();
await page.fillCredentials(wrongCredentias);
expect(page.getPageTitleText()).toEqual('Sign in to your account');
expect(page.getErrorMessage()).toEqual('Email cannot be empty.');
});
it('when login is successful — he should redirect to default home page page ', () => {
await page.navigateTo();
await page.fillCredentials();
await homePage.navigateTo();
expect(homePage.getPageTitleText()).toEqual('welcome');
});
});