自动化测试在 teamcity 上失败,但当我在本地 运行 它们时通过

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

所以,当我在本地 运行 我的自动化测试套件时,它们都通过了。当我通过 teamcity 运行 他们时,2 个测试失败。我使用黄瓜和量角器,并使用 chai 进行断言。 正在测试的页面包含 2 个 table,其中包含元素,可以通过单击复选框来 select 编辑元素。 2个测试的功能:

场景 1 的堆栈跟踪: (我将只提供其中一个测试失败的堆栈跟踪,我相当确定如果我能找到解决方案,我也会找到另一个解决方案)。

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\work06fcb8518a4d99\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)

请注意,这是我试图 select 在第二页上的第三个元素。

而且我绝对一无所知,当我 运行 在本地找到这些元素时,100% 的时间怎么可能找到这些元素,但当我 运行 在 teamcity 上找到时却从来没有。

步骤定义:

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

});

函数:

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();
    }
}

我尝试过的事情:

我的怀疑: 该功能看起来像“select 元素 1,select 元素 2,转到下一页,select 元素 3,select 元素 4。 测试在步骤 select 元素 3 上失败,从未在 select 元素 1 或 2 上失败。每次转到下一页时,table 的内容都会从 dom,并加载新元素。看起来很有可能,当我转到下一页时,用于元素 1 和 2 的 selector im 在元素 3 和 4 上不再有效。但是,我想我应该得到一个陈旧的元素例外。并且没有解释为什么它在本地工作,而通过 teamcity 失败。

Teamity 运行s 测试在与我本地相同的服务器上,我检查过。 任何建议将不胜感激,如果您需要更多信息,请告诉我,我会尽力提供。

对于任何想知道解决方案的人,运行 测试的代理没有使用与我本地 运行 相同的窗口大小,所以表格的大小不同,当我想waitForElement(),超时,因为元素在下一页。