[英]Protractor not finding h1 element
我正在用量角器创建我的第一个 Cucumber 测试。 当浏览器启动并导航到/login
,它应该找到h1
标签并获取文本。 这似乎不起作用。 从视觉上看,浏览器启动并转到登录页面,但它似乎在加载该路由的组件之前就关闭了。 然后我得到以下错误:
1) Scenario: Login Page # e2e/src/features/login-page.feature:3
✔ Before # e2e/src/steps/login-page.steps.ts:9
✔ Given I am on the login page # e2e/src/steps/login-page.steps.ts:13
✖ Then I should see the login title # e2e/src/steps/login-page.steps.ts:17
NoSuchElementError: No element found using locator: By(css selector, h1)
我的功能如下所示:
Feature: Go to the login page
@Regression
Scenario: Login Page
Given I am on the login page
Then I should see the login title
我的步骤如下所示:
import { expect } from 'chai';
import { Before, Given, Then } from 'cucumber';
import { browser, by, element } from 'protractor';
import { LoginPage } from '../pages/login-page.po';
Given('I am on the login page', async () => {
await browser.get('/login');
});
Then('I should see the login title', async () => {
expect(await element(by.css('h1')).getText()).to.equal('Login');
});
当仅通过<tag>
定位元素时,您应该使用by.tagName()
定位器
expect(await element(by.tagName('h1')).getText()).to.equal('Login');
对我来说修复似乎是修改 onPrepare 来做一些额外的等待(我在旧的github 评论中找到了)
onPrepare() {
browser.manage().timeouts().pageLoadTimeout(40000)
browser.manage().timeouts().implicitlyWait(25000)
// If you need to navigate to a page which does not use Angular,
// you can turn off waiting for Angular
browser.ignoreSynchronization = true
browser.get('https://localhost:4200')
browser.waitForAngular()
require('ts-node').register({
project: path.join(__dirname, './tsconfig.e2e.json')
})
},
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.