加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularjs – 无法使量角器等待现有元素可点击(condition.elemen

发布时间:2020-12-17 17:08:53 所属栏目:安全 来源:网络整理
导读:我们有一个Angular 1.5应用程序,它有一个登录屏幕,在应用程序代码和我们的测试中没有任何改变.我们使用量角器(与grunt-protractor等…) 版本: "dependencies": { "async": "^0.9.0","chalk": "^1.1.1","fs-extra": "^0.24.0","grunt": "~0.4.5","grunt-cont
我们有一个Angular 1.5应用程序,它有一个登录屏幕,在应用程序代码和我们的测试中没有任何改变.我们使用量角器(与grunt-protractor等…)
版本:

"dependencies": {
    "async": "^0.9.0","chalk": "^1.1.1","fs-extra": "^0.24.0","grunt": "~0.4.5","grunt-contrib-jshint": "^0.10.0","grunt-protractor-runner": "^4.0.0","grunt-protractor-webdriver": "^0.2.5","jshint-stylish": "^1.0.0","load-grunt-tasks": "~3.1.0","lodash": "^2.4.1","log4js": "^0.6.21","protractor": "^4.0.11","selenium-webdriver": "^3.0.1"
  }

我们所有的测试都采用以下格式:

>登录应用程序并睡觉
>测试(它).每个它都获得done()函数,该函数在测试结束时从browser.sleep(‘1000’)调用.然后(完成)promise(jasmine语法).

describe('login',function () {
    browser.get('/');
    components.login.loginDefault();
    console.log('done login');
    browser.driver.manage().window().maximize(); // just in case the driver wont reach the '.add-new-type' button 
    browser.sleep(1000);
});

describe('post login',function () {
    it('just a test for after user loged in',function (done) {
        console.log('post login');
        const ec = protractor.ExpectedConditions;
        const getStarted = element(by.css('.add-new-type')); // just a button appears on the next page
        console.log('getStarted ' + JSON.stringify(getStarted));
        browser.wait(ec.elementToBeClickable(getStarted),5000);
        console.log('post wait');
        browser.sleep(5000).then(done);
   })});

我们没有更改依赖项版本或在我们的环境中没有任何内容,突然没有任何工作,测试只通过登录阶段然后失败,因为没有找到元素(我猜)并且卡住直到jasmine抛出超时异常

Session created: count=1,browserName=chrome,chromeOptions={args=[--no-sandbox,--test-type=browser,--disable-extensions],prefs={download={default_directory=./e2e/tmp,prompt_for_download=false}}}
node path changed
done login
Started
post login
F

登录后测试只是一个例子,我们尝试了其他方法让驱动程序等待“ExpectedConditions”.
如果我在控制台调试器(chrome)中查找元素,我将正确地获取元素…
我们还试图调试和打印repl模式

element(by.css('.add-new-type')).getText()

行为是一样的 – 没有/没有回应

请问有什么帮助!

解决方法

你有没有尝试过等待元素和网址?

'use strict';

var WaitUtils = function () {

    this.waitElement = function (element,timeout) {
        timeout = timeout || browser.params.time.long;
        var expected = protractor.ExpectedConditions;
        return browser.wait(expected.visibilityOf(element),timeout,"Element not found");
    };

    this.waitUrl = function (url,timeout) {
        timeout = timeout || browser.params.time.long;
        var expected = protractor.ExpectedConditions;
        return browser.wait(expected.urlContains(url),"URL has not contains "+url);
    };
};

module.exports = WaitUtils;

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读