【问题标题】:Protractor - Failed: Error while running testForAngular: A script did not complete before its timeout expired量角器 - 失败:运行 testForAngular 时出错:脚本在超时到期之前未完成
【发布时间】:2017-12-22 13:51:51
【问题描述】:

在使用 Protractor 对 Angular 应用程序运行端到端回归测试时,我无法克服这些失败。当我对 Chrome 和 Firefox 运行相同的测试时,两者总是通过。但是,当针对 Safari 或 Safari Technology Preview 运行时……我遇到了同样的堆栈故障。这是一个 Angular 应用程序,所以我不能只是“关闭”或“禁用”等待 Angular。

节点 8.0.0、量角器 5.1.1、npm 5.0.4、Selenium 3.4.0.jar、macOS Sierra 10.12.5

Safari - 10.1.1 (12603.2.4)

Safari 技术预览版 - 第 35 版(Safari 11.0、WebKit 12604.1.29)

*允许启用远程自动化

Safari 堆栈:

NoSuchWindowError: A request to use a window could not be satisfied because the window could not be found.

Failed: Error while running testForAngular: A script did not complete before its timeout expired.

Safari 技术预览栈:

Failed: Error while running testForAngular: A script did not complete before its timeout expired.

Command duration or timeout: 20.01 seconds

Build info: version: '3.4.0', revision: 'unknown', time: 'unknown'
System info: os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.12.5', java.version: '1.8.0_60'
Driver info: org.openqa.selenium.safari.SafariDriver
Capabilities [{applicationCacheEnabled=true, rotatable=false, databaseEnabled=true, handlesAlerts=true, version=12604.1.29, cleanSession=true, platform=MAC, nativeEvents=true,
locationContextEnabled=false, webStorageEnabled=true, browserName=safari, javascriptEnabled=true, platformName=macOS, cssSelectorsEnabled=true}]

量角器配置文件

"use strict";

exports.config = {
    framework: 'jasmine2',
    capabilities: {
    browserName: 'safari',
    'safari.options': {technologyPreview: true },
    }

    jasmineNodeOpts: {
    showColors: true,
    defaultTimeoutInterval: 500000,
    includeStackTrace : true
    },
    onPrepare: functionI() {
        browser.driver.manage().window().setSize(1600, 1200);
    },
    getPageTimeout: 500000,

    allScriptsTimeout: 20000,

    seleniumAddress: 'http://localhost:4444/wd/hub',

    specs:['10ALMWspec.js', '11ALMWspec.js']
};

JavaScript 规范文件

"use strict";

var loginPage = require('../pages/mobileWebLoginPage.js');
var homePage = require('../pages/mobileWebHomePage.js');

describe('10ALMWspec', function() {
    it('Should validate login and logout functionality', function() {
        loginPage.getDEV();
        loginPage.mobileWebValidLogin();
        expect(homePage.contactName.isDisplayed()).toBe(true);
        expect(homePage.clickToSelectTeamAnchor.isDisplayed()).toBe(true);
        expect(homePage.logOutBtn.isDisplayed()).toBe(true);
        homePage.logOutBtn.click(); 
    });
});

JavaScript 页面文件

'use strict';

var MobileWebLoginPage = function()
{
    this.testUserLoginInputBox = element(by.css('[data-qa-id="loginALMWUserIdInput"]'));
    this.testUserPasswordInputBox = element(by.css('[data-qa-id="passwordALMWInput"]'));
    this.loginBtn = element(by.css('[data-qa-id="loginALMWBtn"]'));
    this.popUpMessage = element(by.css('[class="popup-body"] span'));
    this.popUpMessageOkBtn = element(by.css('[class="popup-buttons"] button'));

    this.getDEV = function()
    {
      browser.get('https://foo/mobile-app/', 500000);
    };
    this.getUAT = function()
    {
      browser.get('https://bar/mobile-app/', 500000);
    };
    this.mobileWebValidLogin = function()
    {
      this.testUserLoginInputBox.sendKeys('testuser');
      this.testUserPasswordInputBox.sendKeys('testpassword');
      this.loginBtn.click();
    };
    this.mobileWebInvalidLogin = function()
    {
      this.testUserLoginInputBox.sendKeys('testuser2');
      this.testUserPasswordInputBox.sendKeys('test2password');
      this.loginBtn.click();
    };
};

module.exports = new MobileWebLoginPage();

【问题讨论】:

    标签: javascript angular selenium-webdriver safari protractor


    【解决方案1】:

    据我了解,问题的根源不是 Angular 等待功能。出现是因为有错误NoSuchWindowError: A request to use a window could not be satisfied because the window could not be found.。 看看issue on the SeleniumHQ github

    【讨论】:

    • Oleksii,我已经查看了您链接到的页面。这就是为什么在阅读了该页面上的所有 cmets 之后,我安装了 STP 并尝试在 Safari 和 Safari Technology Preview 上运行我的测试。他们提供的解决方案声称可以工作,但我可以确认(请参阅上面的 STP 堆栈跟踪)它显然不起作用。窗口大小调整是固定的,但我的测试不会运行。正确的页面呈现在正确的 URL,但 WebDriver 无法驱动浏览器。页面呈现后不执行任何命令。
    • 为什么不能关闭 Angular 等待?您可以添加自己的预期条件。
    • 因为它是一个 Angular 应用程序。所有页面都在 Angular 中。您不能在 Angular 应用程序上关闭 Angular 等待。 “如果您需要导航到不使用 Angular 的页面,您可以关闭等待 Angular”。 [链接]github.com/angular/protractor/blob/master/docs/timeouts.md
    • 您的 Angular 应用程序无法使用 Java 或 Python 进行测试吗? :) Angular 等待它只是很好的帮助功能,仅此而已。我知道这不是您问题的根源,而是首先打开您的大脑)。对不起,我帮不了你。
    猜你喜欢
    • 2018-06-14
    • 1970-01-01
    • 2019-11-11
    • 1970-01-01
    • 1970-01-01
    • 2019-07-09
    • 1970-01-01
    • 1970-01-01
    • 2020-12-10
    相关资源
    最近更新 更多