【问题标题】:Protractor- async/await- for non angular page量角器-异步/等待-非角度页面
【发布时间】:2020-05-14 11:54:04
【问题描述】:

我们的登录屏幕是非 Angular 的,登录后它会重定向到 Angular 应用程序。我们在 conf.js 中使用以下脚本登录。这是完美的工作,没有任何问题。突然之间,相同的脚本开始失败。

onPrepare: async function() {
    browser.ignoreSynchronization = true
        await browser.waitForAngularEnabled(false);
        await browser.get('http://abc.dev.xyz.com');
        await element(By.id('userName')).sendKeys('abcd');
        await element(By.className('btn btn-primary')).click();
        await element(By.id('password')).sendKeys('xyz@123');
        await element(By.className('btn btn-primary')).click();
        await browser.waitForAngularEnabled(true);
    browser.manage().window().maximize();
    jasmine.getEnv().addReporter(new HtmlReporter({
      baseDirectory: 'target/screenshots',
      preserveDirectory: false,
      takeScreenShotsOnlyForFailedSpecs: true,
      docTitle: 'UI Automation Test Report'
   }).getJasmine2Reporter());
  }	 

运行时它只是打开浏览器并启动 URL。之后立即关闭浏览器。早些时候,它用于等待登录页面加载并继续。现在它根本不等到页面加载。所以找不到用户名字段。我不想在这里使用硬编码等待。知道为什么它开始失败了吗?我试过更新 webdiver-manager 。没有任何效果

【问题讨论】:

    标签: selenium-webdriver async-await protractor


    【解决方案1】:

    这是因为在 DOM 中加载 username 元素需要一些时间。尝试调用以下行后等待await browser.get('http://abc.dev.xyz.com');

    首先你需要导入

    import { browser, protractor } from 'protractor';
    const { ExpectedConditions: until } = protractor
    

    await browser.get('http://abc.dev.xyz.com');之后添加如下代码

        await browser.wait(until.presenceOf(element(By.id('userName'))), 60000, 'Taking more time');
    

    60000-> 加载特定组件所用的最大时间(设置时间限制)。

    最终解决方案

    import { browser, protractor } from 'protractor';
    const { ExpectedConditions: until } = protractor
    
    onPrepare: async function() {
        browser.ignoreSynchronization = true
            await browser.waitForAngularEnabled(false);
            await browser.get('http://abc.dev.xyz.com');
            await browser.wait(until.presenceOf(element(By.id('userName'))), 60000, 'Taking more time');
            await element(By.id('userName')).sendKeys('abcd');
            await element(By.className('btn btn-primary')).click();
            await element(By.id('password')).sendKeys('xyz@123');
            await element(By.className('btn btn-primary')).click();
            await browser.waitForAngularEnabled(true);
        browser.manage().window().maximize();
        jasmine.getEnv().addReporter(new HtmlReporter({
          baseDirectory: 'target/screenshots',
          preserveDirectory: false,
          takeScreenShotsOnlyForFailedSpecs: true,
          docTitle: 'UI Automation Test Report'
       }).getJasmine2Reporter());
      }
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-05-16
    • 1970-01-01
    • 2018-07-08
    • 2017-08-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多