- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我是 Protractor 的新手,我正在尝试运行我的脚本。
describe('Navigator homepage', function() {
it('should proceed to login', function() {
browser.get('url');
});
it('Clicks the proceed button', function() {
const proceedButton = element(by.id('auth-login-page-button'));
proceedButton.click();
});
});
但每当我运行它时,浏览器都会打开并继续访问该网站,然后等待 20 秒,然后我收到错误:ScriptTimeoutError:异步脚本超时:20 秒内未收到结果
。该元素显然在那里并且可以单击,但不适用于 Protractor 。难道我做错了什么?配置文件如下所示:
// An example configuration file.
exports.config = {
directConnect: true,
// Capabilities to be passed to the webdriver instance.
capabilities: {
'browserName': 'chrome'
},
// Framework to use. Jasmine is recommended.
framework: 'jasmine',
// Spec patterns are relative to the current working directory when
// protractor is called.
specs: ['login_spec.js'],
allScriptsTimeout: 20000,
getPageTimeout: 15000,
framework: 'jasmine',
jasmineNodeOpts: {
isVerbose: false,
showColors: true,
includeStackTrace: false,
defaultTimeoutInterval: 40000
}
};
最佳答案
考虑到您添加的错误消息(请参阅评论),原因似乎是不断轮询 $timeout
,这让 promise 无限期未解决,因此导致 Protractor 异步超时(see details here) .
解决方案
正确的解决方案是避免使用$timeout
,而是使用$interval
。这样 Protractor 就可以继续控制 ControlFlow,管理您的异步任务。所以这是一种软件错误,而不是 Protractor 错误。
您的错误信息:
失败:WAITING异步 Angular 任务在 20 秒后完成时超时。这可能是因为当前页面不是 Angular 应用程序。有关详细信息,请参阅常见问题解答:https://github.com/angular/protractor/blob/master/docs/timeo uts.md#waiting-for-a ngular 在使用定位器等待元素时 - 定位器:By( css 选择器,md-raised md-primary md-button md-ink-ripple)。
*以下任务待处理:- $timeout: function (){return _this.getVersion()}*
解决方法
不太好的解决方法是通过设置 browser.waitForAngularEnabled(false);
(在 beforeEach 中或直接在规范中。
但这也意味着,在测试规范本身中手动处理 controlFlow。这需要使用大量的 .then()
和 ExpectedConditions
,失去 Protractor 的主要优势之一。
调试可能性
检查描述 here for potential causes and workarounds 。具体尝试 browser.waitForAngularEnabled(false);
排除 Angular Protractor 问题。
如果找不到原因,则可能是时间问题(不太可能,但此时值得检查)。
您可以尝试添加日志消息来缩小有效执行顺序:
describe('Navigator homepage', function() {
it('should proceed to login', function() {
browser.get('url').then(function(){
console.log("Page is fully loaded");
});
});
it('Clicks the proceed button',function() {
console.log("Start 2nd Test");
const proceedButton = element(by.id('auth-login-page-button'));
proceedButton.click();
});
});
或者你把 Action 放在同一个测试用例中,使用 then()
来同步执行它们:
describe('Navigator homepage', function() {
it('should proceed to login', function() {
browser.get('url').then(function(){
const proceedButton = element(by.id('auth-login-page-button'));
proceedButton.click();
});
});
在 onPrepare
中打开主页
作为一个很好的旁白:如果你总是首先加载主页,只需将它放入你的 conf.js 的 onPrepare-part 并且它总是在你的测试开始之前执行一次:
onPrepare: function () {
browser.driver.manage().window().maximize();
browser.get('url');
},
关于javascript - Protractor -ScriptTimeoutError : asynchronous script timeout: result was not received in 20 seconds,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46527912/
我有一个表,其中包含3行数据和3个删除按钮。我想删除所有数据行,因此想在我的页面对象中编写一个方法来做到这一点……这应该很简单,但我无法使其正常工作。我正在这样尝试: this.rows = elem
我们有一个应用程序,在本地进行测试会显示无效的SSL证书警告。通常,我只添加一个异常并继续处理。但是, Protractor 有无视这一点吗? 我已经看到了 Selenium 中的一些功能,其中可以忽
我有一个关于我的代码和不同行为的问题,具体取决于使用的 Protractor 版本。 我的测试使用 Protractor 版本 2.5.1。但要从最新发展中获得所有好处,我 试图移动到版本 3.x。
我有一个项目已经运行了很长时间。 最近(几周)系统测试失败了。 经过大量调查,我们得出结论, Protractor 无法识别和关闭警报。 曾经工作的代码 exports.removeFaq = fun
我能够成功运行 Protractor 脚本。下面是我用来运行 Protractor 脚本的 protractor.config.js 文件。 var Jasmine2Reporter = requir
在 Protractor 中,如何处理重复的内容,比如一张表格?例如,给定以下代码,它会踢出一个包含 3 列的表:Index , Name和 Delete-Button在每一行中: {{$in
我为 Protractor 编写了一个自定义定位器,可以找到 anchor元素由他们 ui-sref值(value)。在我的规范中,我刚刚使用了 by.addLocator添加自定义定位器,但我认为发
我遇到过 Protractor 的页面对象的不同类型的语法,我想知道它们的背景是什么以及建议采用哪种方式。 这是 Protractor 教程中的官方 PageObject 语法。我最喜欢它,因为它清晰
Protractor 中有两个 it() 测试用例 it('it1',function(){ }); it('it2',function(){ }); 完成 it1 后, Protractor 中的驱
我目前正在运行一套 Protractor 测试。我有一个 config.js 仅设置为运行具有“功能”的 Chrome。见下文。 capabilities: { } browserNa
我试图断言名称显示在表的列中。我写了一个 inResults将遍历列的文本以查看名称是否存在的函数。这是我正在尝试的: 页面对象: this.names = element.all(by.repeat
我可以使用检索浏览器日志 browser.manage().logs().get('browser').then(function(browserLog) { logger.info('log:
我按照文档中有关如何安装 Protractor 和 Selenium 的说明进行操作,但无法启动。 install -g protractor webdriver-manager update 之后我
我在 Protractor 中使用 --suites config 运行多个案例。我必须为每种情况重新启动我的 web 应用程序,但我的应用程序有一个警报,每当页面重新加载或关闭时,都会弹出该警报以进
我想知道如何在测试套件中按顺序运行测试用例。 例如,加载 URL、登录系统等。 最佳答案 检查 protractor.conf.js example . 您可以指定一个按字母顺序加载文件的 glob,
row1Col1 row1Col2 row1Co
如何从包含特定文本的转发器中搜索元素? 我试过这样的事情: element(by.repeater('item in array')).all(by.cssContainingText('.xyz',
只是想知道是否可以将 cli args 指定为 Protractor --multiCapabilities.0.browserName chrome --multiCapabilities.1.br
是否可以在 Protractor 中的任何套件运行之前运行一些测试或逻辑流程? 例如,我想将我的 Protractor 测试分解成一系列套件来测试我的应用程序的不同方面。假设 Jenkins 将在部署
我是 Protractor 的新手,我正在尝试使用 Protractor 设置单选按钮值。我在互联网和 SO 上搜索了徒劳的答案。 html: No Yes
我是一名优秀的程序员,十分优秀!