【问题标题】:Protractor locators does not work in PageObjectModel structure量角器定位器在 PageObjectModel 结构中不起作用
【发布时间】:2020-05-01 17:46:52
【问题描述】:

框架:Appium + Protractor + Cucumber + Typescript 使用 POM 模型

  • 我有在POM结构中设计的appium量角器框架
    • 应用的初始页面将识别在不同 ts 文件中调用的定位器以及在不同 ts 文件中调用它的 tap、isDisplayed 等函数。
    • 但是一旦它通过了应用程序中的初始页面,比如 3 页。没有识别出正在调用其他函数的定位器,但是当它们被直接传递时它们被识别出来(比如 driver.findelements(by.css('')).click )这是有效的。
    • 问题是我不能总是在步骤定义 .ts 文件中传递这样的代码,因为它不是一个好的结构

注意:顺便说一下,这个脚本之前运行良好。 尝试使用不同的解决方法进行测试,例如再次构建二进制文件,尝试在 android 和 ios 应用程序上运行,降级或升级节点包。但没有什么能解决问题。有没有人遇到过这种问题。请问有什么建议或解决办法吗?

有效的代码:(直接在函数中传递定位器,而不是从 onboarding.ts 文件中传递将起作用)

Then(/^VIC should be selected from the state or territory drop down$/, async () => {
await browser.driver.findElement(by.css('button[sp-automation-id=\'select-state-toggle\']')).click();
await browser.driver.findElement(by.css('page-action-sheet label[sp-automation-id=\'action-sheet-option-VIC\']')).click(); });

不起作用的代码:(Onboarding.ts 文件包含为 State 和 VIC 定义的定位器,与上述代码块相同。但从那里读取它不起作用。)

Then(/^VIC should be selected from the state or territory drop down$/, async () => {
await AutomationAction.tap(Onboarding.State);
await AutomationAction.tap(Onboarding.VIC); });

有效的代码(下面的代码在上面的代码块之前调用,它是在调用上面的页面之前的一个页面)

Then(/^I enter the mobile number and tap next button on the your mobile number screen$/, async () => {
 MobileNo = AutomationAction.getMobileNumber("mobileNumber");
 SameMobileNo = MobileNo;
 await AutomationAction.sendKeyText(Onboarding.InputMobileNo,MobileNo);
 await AutomationAction.tap(Onboarding.Next_BTN_YourMobileNumber);

});

【问题讨论】:

  • 我发现很难想象您描述的代码。您能否提供一个页面对象函数的示例以及如何调用它(包括一个有效的调用和一个无效的调用)
  • @DublinDev 感谢您的 cmets,我已使用有效和无效的代码示例更新了摘要。如果您需要更多信息,请告诉我。期待一些cmets/help/建议

标签: android typescript protractor appium


【解决方案1】:

由于失败的页面,自动化将其视为非角度页面,并且定位器在其他函数中调用它时会失败或无法定位它们。当我引入 browser.ignoreSycnhronization=true 为非角度应用程序/页面进行角度同步时,它起作用了。

【讨论】:

    猜你喜欢
    • 2019-03-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多