I created a simple 'page objects' example. I get the following error messages when executing the test case:
I used the following commands to execute my test:
npm run test:firefox
or
npm run test:firefox -e
I hope someone can tell me what I'm doing wrong.
// 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()
})
My expectation:
the variable t doesn't exist in your NavbarPage class. So calling t.typeText causes an exception.