Search code examples
typescriptprotractorautomated-testscucumberteamcity

automated tests fail on teamcity, but pass when i run them locally


So, when i run my automated test suite locally, all of them pass. When i run them via teamcity, 2 tests fail. I use cucumber and protractor, and chai for assertions. The page im testing contains 2 tables, with elements in them, and elements can be selected by clicking a checkbox. The function of the 2 tests:

    1. If i select 2 elements on the first page, and i go to the next page, the selected elements remain selected.
    1. If i select 50 elements, I cant select any more elements and the remaining checkboxe are disabled.

the stacktrace for scenario 1: (I'll just provide the stacktrace for one of the test fails, im fairly certain if I can find a solution to this, I'll find a solution to the other one too).

TimeoutError: Element(By(xpath, //table//td[text() = ' MyTd22 ']/preceding-sibling::td//mat-checkbox)) not found 23:05:45 Wait timed out after 10004ms 23:05:45 at C:\TeamCity\BuildAgent\work\9106fcb8518a4d99\node_modules\selenium-webdriver\lib\promise.js:2201:17 23:05:45 at runMicrotasks () 23:05:45 at processTicksAndRejections (internal/process/task_queues.js:94:5)

Note that this is the 3rd element im trying to select, on the 2nd page.

And I'm absolutely clueless, how is it possible that these elements are found when i run it locally, 100% of the time, but never when i run it on teamcity.

The step definition:

When(/^I select the '(.*)' application$/, async (applicationName: string) => {
await page.selectApplicationByName(applicationName);

});

The function:

public async selectApplicationByName(applicationName: string) {
    const checkedAttributerName = "my-xpath-selector";
    const elementCheckbox = element(by.xpath("//table//td[text() = ' " + applicationName + " ']/preceding-sibling::td//mat-checkbox"));
    await waitForElement(by.xpath("//table//td[text() = ' " + applicationName + " ']/preceding-sibling::td//mat-checkbox"));

    if (await elementCheckbox.getAttribute("class") !== checkedAttributerName) {
    await element(by.xpath("//table//td[text() = ' " + applicationName + " ']")).click();
    }
}

Things that I tried:

  • I tried to play around with the waitForElement() commands, but if i remove them, the tests fail locally too.
  • Putting browser.sleep() commands to various places, but that neither helped, nor would i like to use sleep if i can avoid it

My suspicions: the feature looks like " select element 1, select element 2, go to next page, select element 3, select element 4. The test fails on the step select element 3, never on select element 1 or 2. Everytime you go to the next page, the contents of the table are removed from the dom, and new elements are loaded. It would seem very likely, that when i go to the next page, the selector im using for element 1 and 2 is no longer valid on element 3 and 4. But then, i think i should get a stale element exception. And doesn't explain why is it working locally, and failing via teamcity.

Teamity runs the test on the same server as my local, I checked that. Any suggestions would be greatly appriciated, If you need any more info let me know, I'll try to provide it.


Solution

  • For anyone wondering the solution, the agent that ran the test didn't use the same windowsize as my local run, so the size of the tables differed, and when i wanted to waitForElement(), it timed out because the element was on the next page.