Javascript 预期条件是量角器中的投掷错误

Javascript 预期条件是量角器中的投掷错误,javascript,selenium-webdriver,protractor,cucumberjs,Javascript,Selenium Webdriver,Protractor,Cucumberjs,我想在我的框架中实现ExpectedConditions,但它抛出了一些我无法理解的错误。有人能帮我吗 步骤定义 页面对象 错误日志 我正在使用的应用程序是非角度应用程序。。我查看了其他问题中提供的解决方案,他们说需要使用browser.ignoreSynchronization=true,但我同时尝试了browser.waitForAngularEnabled()和browser.ignoreSynchronization=true都不工作。是否尝试将定位器定义从函数更改为变量? 此外,您不必

我想在我的框架中实现ExpectedConditions,但它抛出了一些我无法理解的错误。有人能帮我吗

步骤定义 页面对象 错误日志
我正在使用的应用程序是非角度应用程序。。我查看了其他问题中提供的解决方案,他们说需要使用
browser.ignoreSynchronization=true
,但我同时尝试了
browser.waitForAngularEnabled()
browser.ignoreSynchronization=true
都不工作。

是否尝试将定位器定义从函数更改为变量?
此外,您不必在“预期条件”行中使用“等待两次”。
请尝试以下操作:

页面对象

// You should specify the index if using .all (with .get(index); at the end)
this.optyList = element.all(by.xpath("//a/ancestor::th[@scope='row']"));
Spec(在这里您可以尝试使用
的可视性
的存在性

visibilityOf()
accept
ElementFinder
,而不是
ElmentFinderArray
,您不应该传递到元素数组中

this.Then(/^Select Any Opty and click on New button$/, async () => {
    cmBrowser.sleep(10000);
    await cmBrowser.wait(EC.visibilityOf(await loginPO.optyList().first()),20000);
    var list=await loginPO.optyList();
});

您好,Joaquin,实际上在我的测试应用程序中存在一些页面加载问题,因此当我使用此预期条件时,我会收到此错误,并且
browser.sleep
也不会暂停执行。我一定会查看您提出的建议,并让您知道。。但是,如果您的解决方案不起作用,请提供。另外,请不要忘记,
browser.sleep()
也需要在它的sure Joaquin面前等待。。你的代码可能会导致很多错误。正如我在前面的一个问题中提到的,所有浏览器方法都返回承诺,并要求
等待
在承诺得到解决之前停止执行。您的
.sleep()
函数在此上下文中不起任何作用。与此相反,第一个参数
.wait()
采用的是返回承诺的函数,不需要
wait
。由于这些小事情,您的代码会产生不可预测的结果浏览本页,看看每个方法是如何工作的,否则情况会变得更糟,因为您正在构建非常复杂的框架。最终你会达到极限,无法扩展它,因为你会一直保持它time@Sergey,您所说的“所有浏览器方法都返回承诺,并要求在承诺得到解决之前等待停止执行”。。你能不能给我添加一些类似的答案,让我看看。。我对量角器黄瓜不太熟悉。。这对我很有帮助。你是说返回元素的页面对象吗?JavaScript方法是包含函数定义的对象的属性。因为
browser
是一个对象。您针对它调用的所有对象都是方法(对象的函数)。因此
browser.wait()
browser.sleep()
browser.waitForAngularEnabled()
等都是
浏览器的方法。所以,他们所有人,不仅仅是回报承诺。在
async/await
之前,您应该使用
处理它们。然后使用
语法。否则,JS会安排您的承诺并在不等待其解决的情况下转到下一行
 TypeError: Cannot read property 'bind' of undefined
    at ProtractorExpectedConditions.presenceOf (C:\Users\srongala\AppData\Roaming\npm\node_modules\protractor\built\expectedConditions.js:341:40)
    at ProtractorExpectedConditions.visibilityOf (C:\Users\srongala\AppData\Roaming\npm\node_modules\protractor\built\expectedConditions.js:381:30)
    at World.(anonymous) (C:\Users\srongala\Documents\My Received Files\Automation\Proc\Test_modules\step_definitions\PGS_ES.js:47:39)
    at runMicrotasks ((anonymous))
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
// You should specify the index if using .all (with .get(index); at the end)
this.optyList = element.all(by.xpath("//a/ancestor::th[@scope='row']"));
this.Then(/^Select Any Opty and click on New button$/,async ()=>{
    await cmBrowser.wait(EC.presenceOf(loginPO.optyList),20000);
    // or:
    await cmBrowser.wait(EC.visibilityOf(loginPO.optyList),20000);
});
this.Then(/^Select Any Opty and click on New button$/, async () => {
    cmBrowser.sleep(10000);
    await cmBrowser.wait(EC.visibilityOf(await loginPO.optyList().first()),20000);
    var list=await loginPO.optyList();
});