Javascript 如何解决量角器测试无限期挂起的问题?
我遇到了一个问题,我以前运行的测试用例,我知道它正在工作,现在在执行时被无限期地卡住了。每次测试单击特定元素时都会发生这种情况。测试刚刚挂起,无法继续使用脚本。除超时错误外,不会发生任何错误。运行测试时,我会收到常规提示:Javascript 如何解决量角器测试无限期挂起的问题?,javascript,selenium,jasmine,protractor,Javascript,Selenium,Jasmine,Protractor,我遇到了一个问题,我以前运行的测试用例,我知道它正在工作,现在在执行时被无限期地卡住了。每次测试单击特定元素时都会发生这种情况。测试刚刚挂起,无法继续使用脚本。除超时错误外,不会发生任何错误。运行测试时,我会收到常规提示: [11:58:20] I/direct - Using ChromeDriver directly... [11:58:20] I/launcher - Running 1 instances of WebDriver Started A Jasmine spec timed
[11:58:20] I/direct - Using ChromeDriver directly...
[11:58:20] I/launcher - Running 1 instances of WebDriver
Started
A Jasmine spec timed out. Resetting the Webdriver Control Flow.
F
Failures:
1) clicks menu buttons
Message:
Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.
Stack:
Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.
at Timer.listOnTimeout (timers.js:92:15)
1 spec, 1 failure
Finished in 3000.147 seconds
[12:48:47] I/launcher - 0 instance(s) of Webdriver still running
[12:48:47] I/launcher - chrome #01 failed 1 test(s)
[12:48:47] I/launcher - overall: 1 failed spec(s)
[12:48:47] E/launcher - Process exited with error code 1
然后它就挂在那里,直到它达到我设置的超时。下面是配置的副本和我正在使用的测试脚本的一部分
config.js
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',
directConnect: true,
//getPageTimeout: timeout_in_millis
// Capabilities to be passed to the webdriver instance.
capabilities: {
'browserName': 'chrome'
//'browserName': 'firefox'
},
//suites:{},
specs: ['basic_testing.js'],
allScriptsTimeout: 3000000,
//framework: 'jasmine2',
onPrepare: function() {
browser.driver.manage().window().maximize();
var jasmineReporters = require('jasmine-reporters');
jasmine.getEnv().addReporter(new jasmineReporters.JUnitXmlReporter({
consolidateAll: true,
savePath: 'testresults',
filePrefix: new Date().toJSON().substring(0,10).replace(/-/g , "") + '_xmloutput'
}))
},
//Options to be passed to Jasmine.
jasmineNodeOpts: {
defaultTimeoutInterval: 3000000
}
};
basic_testing.js
describe('menu page', function()
{
it('clicks menu buttons', function()
{
element(by.id("nav-group-ServiceOrders")).click();
element(by.id("nav-item-Dashboard")).click();
//This element is clicked but then the test hangs here
element(by.id("nav-item-OrdersConsole")).click();
element(by.id("nav-item-PersonnelConsole")).click();
element(by.id("nav-item-PriorityPoints")).click();
});
});
若你们已经探索过,但仍然面临问题,那个么 使用
browser.executeScript('window.stop();')代码>如果单击第一个元素后生成的页面加载了要单击的第二个元素,但加载页面中的所有元素需要时间,则停止进一步加载元素并继续单击第二个元素。您的代码如下所示
var EC = protractor.ExpectedConditions;
1stElement.click();
browser.wait(EC.presenceOf(2ndElement), 5000);
browser.wait(EC.visibilityOf(2ndElement), 5000);
browser.executeScript('window.stop();');
2ndElement.click();
你能在问题中包括你的规范文件和配置文件吗。在目前的情况下,很难确定根本原因及其影响vague@J.当selenium服务器窗口挂起时,您会看到什么?它是否显示任何错误或任何其他信息?@AdityaReddy我添加了配置和测试的副本case@user1207289除了超时之外,没有弹出的错误。我可以编辑该文件,并在当前运行时显示它的其他内容。为什么要对ID元素调用.all()
?不应该只有一个吗?还有,为什么要使用browser()
作为单击的方式?只需调用。在您创建的输入变量上单击()