我在 Protractor 中运行多个测试时遇到问题:60010 秒后等待异步脚本结果超时
紧接登录脚本后执行的教程脚本代码:
这是我在来自 A Code proposed in another question 的配置文件中使用的代码但它没有解决我的问题!
onPrepare: function() {
return browser.getProcessedConfig().then(function(config) {
var browserName = config.capabilities.browserName;
browser.manage().timeouts().setScriptTimeout(60000);
});
PS:即使我为元素放置了不正确的位置,我也会出现超时错误,而不是找不到此元素!好像那行代码“点击进入教程按钮”从未执行过
这是我的 html 代码:
</div></md-card-content> </md-card><!-- end ngIf: !expandChart --> </div> </div> </div></md-content> </div></div> <!-- Google Analytics: change UA-XXXXX-X to be your site's ID --> <!--<script>--> <!--!function(A,n,g,u,l,a,r){A.GoogleAnalyticsObject=l,A[l]=A[l]||function(){--> <!--(A[l].q=A[l].q||[]).push(arguments)},A[l].l=+new Date,a=n.createElement(g),--> <!--r=n.getElementsByTagName(g)[0],a.src=u,r.parentNode.insertBefore(a,r)--> <!--}(window,document,'script','https://www.google-analytics.com/analytics.js','ga');--> <!--ga('create', 'UA-XXXXX-X');--> <!--ga('send', 'pageview');--> <!--</script>--> <script src="scripts/vendor.js"></script> <script src="cordova.js"></script> <script src="scripts/scripts.js"></script> <script src="https://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/sha1.js"></script> <script src="https://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/sha256.js"></script> <script src="https://crypto-js.googlecode.com/svn/tags/3.1.2/build/components/enc-base64-min.js"></script> <div class="introjs-overlay" style="top: 0;bottom: 0; left: 0;right: 0;position: fixed;opacity: 0.8;"></div><div class="introjs-helperLayer " style="width: 538px; height:366px; top:64px;left: 195px;"></div><div class="introjs-tooltipReferenceLayer" style="width: 538px; height:366px; top:64px;left: 195px;"><div class="introjs-tooltip" style="left: 546px;"><div class="introjs-tooltiptext">Watchlist view. Swipe the row in the grid to the left to show the delete action.</div><div class="introjs-bullets"><ul><li><a class="active" href="javascript:void(0);" data-stepnumber="1"> </a></li><li><a href="javascript:void(0);" data-stepnumber="2"> </a></li><li><a href="javascript:void(0);" data-stepnumber="3"> </a></li><li><a href="javascript:void(0);" data-stepnumber="4"> </a></li><li><a href="javascript:void(0);" data-stepnumber="5"> </a></li><li><a href="javascript:void(0);" data-stepnumber="6"> </a></li><li><a href="javascript:void(0);" data-stepnumber="7"> </a></li><li><a href="javascript:void(0);" data-stepnumber="8"> </a></li></ul></div><div class="introjs-progress" style="display: none;"><div class="introjs-progressbar" style="width:12.5%;"></div></div><div class="introjs-arrow left" style="display: inherit;"></div><div class="introjs-tooltipbuttons"><a class="introjs-button introjs-skipbutton" href="javascript:void(0);">Don't show it again!</a><a href="javascript:void(0);" class="introjs-button introjs-prevbutton introjs-disabled" tabindex="-1">Previous</a><a href="javascript:void(0);" class="introjs-button introjs-nextbutton">Next</a></div></div></div></body></html>
最佳答案
1.关于路由查询
如果在第一个规范之后,用户登录并且路由改变。确保在执行任何测试之前导航所有内容。
expect(browser.getCurrentUrl()).toContain('#/the_route_of_logged_in');
// '#/' is just illustration. You can remove it to make it shorter
// => like this ...toContain('the_route_of_logged_in');
2.关于点击教程
browser.wait(EC.elementToBeClickable(tutorial), 10000);
做
browser.wait
在尝试单击它之前使用 EC 用于可单击的按钮(看起来你在这里有很好的方法)=> 总结 你可以试试这个:
'user strict';
var EC = protractor.ExpectedConditions;
describe('tutorials', function () {
it('should make click into tutorial button', function () {
expect(browser.getCurrentUrl()).toContain('the_route_of_logged_in');
var tutorial = $('.introjs-nextbutton');
browser.wait(EC.elementToBeClickable(tutorial), 8000, 'Timed out');
tutorial.click();
browser.sleep(8080); // regardless we are not reaching this point. But I will suggest to reduce this sleep time like 1000 (1s).
});
});
3.(可选)如果以上2点没有帮助
在您的所有规范中
login-spec.js
和 tutorial-spec.js
.添加 process.nextTick(done);
在 afterAll()
阻止以确保在规范之后是否没有任何 Jasmine Reporters 被卡住。describe('foo', function(){
afterAll(function(done){
process.nextTick(done);
});
it('should bar...', function() {});
}
附言请注意,我完全不知道我的建议/方法是否有帮助。由于使用 e2e-test 进行调试总是很痛苦……因为我们总是可能不知道“错误来自哪里”。所以我能做的就是给你建议。
(有时我花了几个小时来观察浏览器的行为来识别 e2e-test 的问题)
和 请勿复制粘贴 我的代码变成了你的代码。我用你提供的图片输入了它,我可以在那里打一些错字。
关于ajax - 使用 appium 执行 Protractor 脚本时等待异步脚本结果超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37070680/