Reputation: 2647
I have following test in TestCafe:
import { Selector } from 'testcafe';
const TEST_URL = process.env.TEST_URL;
fixture('/').page(`${TEST_URL}/`);
test(`users should be able to view the '/' page`, async (t) => {
await t
.navigateTo(TEST_URL)
.expect(Selector('H1').withText('All Users').exists).ok()
});
And this test fail:
/
✖ users should be able to view the '/' page
1) AssertionError: expected false to be truthy
Browser: Chrome 59.0.3071 / Mac OS X 10.12.5
5 |fixture('/').page(`${TEST_URL}/`);
6 |
7 |test(`users should be able to view the '/' page`, async (t) => {
8 | await t
9 | .navigateTo(TEST_URL)
> 10 | .expect(Selector('H1').withText('All Users').exists).ok()
11 |});
12 |
Problem is that page don't fully load and there is no h1 tag (which is rendered from React component) but I don't know how to tell TestCafe to wait for page to load.
I tried this:
import { Selector } from 'testcafe';
const TEST_URL = process.env.TEST_URL;
fixture('/').page(`${TEST_URL}/`);
test(`users should be able to view the '/' page`, async (t) => {
await t.expect(Selector('H1').withText('All Users').exists).ok()
});
which works but I need for some test to use navigateTo so I would like to know what to change so that version of test with navigateTo also works.
I tried to set await for every line like this:
import { Selector } from 'testcafe';
const TEST_URL = process.env.TEST_URL;
fixture('/').page(`${TEST_URL}/`);
test(`users should be able to view the '/' page`, async (t) => {
await t.navigateTo(TEST_URL)
await t.expect(Selector('H1').withText('All Users').exists).ok()
});
but that error is same.
Upvotes: 3
Views: 1957
Reputation: 1036
The problem is in the TEST_URL
variable. If it contains bare IP address (e.g., 'xxx.xx.x.xxx'
), navigateTo
will redirect the browser to 'http://xxx.xx.x.xxx/xxx.xx.x.xxx'
because the navigateTo
action treats this string as a relative path.
To solve the problem, include the protocol in the TEST_URL
string, e.g. 'http://xxx.xx.x.xxx'
.
Upvotes: 4