KnowledgeExpert / selenidejs

User-oriented Web UI browser tests in JavaScript (Selenide port to JS)
Apache License 2.0
58 stars 10 forks source link

should have texts fails with unclear message in case of "empty list" found by browser.all #98

Open yashaka opened 5 years ago

yashaka commented 5 years ago
import { Browser, have, perform } from 'selenidejs';

let browser: Browser;

describe('TodoMVC', () => {

    beforeAll(async () => {
        browser = Browser.chrome();
        jasmine.DEFAULT_TIMEOUT_INTERVAL = 100000;
    });

    afterAll(async () => {
        await browser.quit();
    });

    it('completes task', async () => {

        await browser.open("http://todomvc.com/examples/emberjs/");

        await browser.element('//*[@id="new-todo"]').type('a').then(perform.pressEnter);
        await browser.element('//*[@id="new-todo"]').type('b').then(perform.pressEnter);
        await browser.element('//*[@id="new-todo"]').type('c').then(perform.pressEnter);
        await browser.all('//*[@id="new-todo"]//li').should(have.exactTexts('a', 'b', 'c'));
    });
});

fails with:

1) TodoMVC completes task
  Message:
    Error: 
        Timed out after 4000ms, while waiting for:
        browser.all(By(xpath, //*[@id="new-todo"]//li)).has exact texts a,b,c
    Reason:
        Cannot read property 'includes' of undefined
  Stack:
    Error: 
        Timed out after 4000ms, while waiting for:
        browser.all(By(xpath, //*[@id="new-todo"]//li)).has exact texts a,b,c
    Reason:
        Cannot read property 'includes' of undefined
        at <Jasmine>
        at processTicksAndRejections (internal/process/next_tick.js:81:5)

1 spec, 1 failure
Finished in 8.89 seconds

It should fail actually, because the //*[@id="new-todo"]//li selector is wrong (should be todo-list instead of new-todo), but the error is unclear...

maybe the reason is somewhere here: https://github.com/KnowledgeExpert/selenidejs/blob/master/lib/utils/predicates.ts#L25

the fix is needed:)

reproduced in branch: https://github.com/KnowledgeExpert/selenidejs/tree/new-not-syntax-for-conditions

alex-popov-tech commented 5 years ago

as far as I see, query.text returns empty array, which is fine, and I wasn't able to figure out how compare actually works, so please take this one @yashaka