ReferenceError: t is not defined - there is no JS error existing
ReferenceError: t is not defined - there is no JS error existing
我创建了一个简单的 'page objects' 示例。执行测试用例时出现以下错误消息:
- AssertionError:预期假为真
- 未处理的承诺拒绝
我使用了以下命令来执行我的测试:
npm run test:firefox
或
npm run test:firefox -e
我希望有人能告诉我我做错了什么。
// page object (navbar-page.js)
import { Selector } from 'testcafe'
class NavbarPage {
constructor() {
this.searchBox = Selector("#searchTerm")
}
async search(text) {
await t.typeText(this.searchBox, text, { paste: true, replace: true }).pressKey('enter')
}
}
export default NavbarPage
// Test case (search.test.js)
import { Selector } from 'testcafe'
import NavbarPage from '../page-objects/navbar-page';
const pageObject = new NavbarPage()
fixture`Search test`
.page`http://zero.webappsecurity.com/`
test('Search box should work', async t => {
const result_title = Selector('h2').withText("Search Results:")
pageObject.search('banking')
await t.expect(result_title.exists).ok()
})
我的期望:
- 测试用例应在搜索输入字段中插入术语 "banking"。
- 测试用例应按回车键搜索给定的术语。
- 结果页显示结果。
您的 NavbarPage 中不存在变量 t class。所以调用 t.typeText 会导致异常。
我创建了一个简单的 'page objects' 示例。执行测试用例时出现以下错误消息:
- AssertionError:预期假为真
- 未处理的承诺拒绝
我使用了以下命令来执行我的测试:
npm run test:firefox
或
npm run test:firefox -e
我希望有人能告诉我我做错了什么。
// page object (navbar-page.js)
import { Selector } from 'testcafe'
class NavbarPage {
constructor() {
this.searchBox = Selector("#searchTerm")
}
async search(text) {
await t.typeText(this.searchBox, text, { paste: true, replace: true }).pressKey('enter')
}
}
export default NavbarPage
// Test case (search.test.js)
import { Selector } from 'testcafe'
import NavbarPage from '../page-objects/navbar-page';
const pageObject = new NavbarPage()
fixture`Search test`
.page`http://zero.webappsecurity.com/`
test('Search box should work', async t => {
const result_title = Selector('h2').withText("Search Results:")
pageObject.search('banking')
await t.expect(result_title.exists).ok()
})
我的期望:
- 测试用例应在搜索输入字段中插入术语 "banking"。
- 测试用例应按回车键搜索给定的术语。
- 结果页显示结果。
您的 NavbarPage 中不存在变量 t class。所以调用 t.typeText 会导致异常。