4

I created a simple 'page objects' example. I get the following error messages when executing the test case:

  1. AssertionError: expected false to be truthy
  2. Unhandled promise rejection

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 test case shall insert the term "banking" within the search input field.
  • Test case shall press enter to search for the given term.
  • Result page shall display the results.
Alex Skorkin
  • 4,264
  • 3
  • 25
  • 47

1 Answers1

4

the variable t doesn't exist in your NavbarPage class. So calling t.typeText causes an exception.

cmpickle
  • 810
  • 11
  • 10
  • 3
    I would also recommend checking the https://devexpress.github.io/testcafe/documentation/recipes/extract-reusable-test-code/use-page-model.html#step-7---add-actions-to-the-page-model article to see how to import the `t` variable correctly – Alex Kamaev Jun 05 '19 at 07:37