gpt4 book ai didi

angularjs - 无法让 Protractor 等待现有元素可点击(condition.elementToBeClickable)

转载 作者:行者123 更新时间:2023-12-01 04:50:36 24 4
gpt4 key购买 nike

我们有一个 Angular 1.5 应用程序,它有一个登录屏幕,应用程序代码和我们的测试中没有任何变化。我们使用 Protractor (使用 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"
}

我们所有的测试都采用以下格式:
  • 登录应用程序并休眠
  • 测试(它)。每个它都会从 browser.sleep('1000').then(done) promise ( Jasmine 语法)获取在测试结束时调用的 done() 函数。
    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), timeout, "URL has not contains "+url);
    };
    };

    module.exports = WaitUtils;

    关于angularjs - 无法让 Protractor 等待现有元素可点击(condition.elementToBeClickable),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41459841/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com