量角器-异步/等待-非角度页面

问题描述 投票:0回答:1

我们的登录屏幕是非角度的,登录后将其重定向到角度应用程序。我们正在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。什么都没做

enter image description here

selenium-webdriver async-await protractor
1个回答
0
投票

这是因为在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');

6000->加载特定组件所花费的时间。

最终解决方案

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());
  }
© www.soinside.com 2019 - 2024. All rights reserved.