我正在使用Protractor来测试Angular Web应用程序的自动化。我的测试套件大约有37个测试用例。每个测试用例在单独运行时都可以成功运行。当我运行整个测试套件时,我得到
ScriptTimeoutError:脚本超时...................................................来自:任务:Protractor.waitForAngular()-定位器:By(xpath,/ html / body / app-root / app-home / div / div / div [2] / as-split / as-split-area [2] / app-tabhost / app-tab [1] / div / app-files / div / div [2] / ag-grid-angular / div / div [2] / div [1] / div [3] / div [ 2] / div / div / div [12] / div [1]])
大部分时间。
我遵循的解决方案很少,但是没有用。
我已经发布了相关的代码片段以了解此问题。有什么事吗
Component_spec.js
var LoginModule = require("./LoginModule.js");
var ComponentModule = require("./ComponentModule.js");
describe('Component Spec', function () {
var componentModule = new ComponentModule();
beforeAll(async function () {
console.log("===Loading home page");
browser.driver.sleep(8000);
});
beforeEach(async function () {
browser.get(LoginModule.homeUrl);
browser.driver.sleep(8000);
});
it('editinput', async function () {
var AlertMessage = element(by.cssContainingText('.col-sm-11', 'underline'));
componentModule.editinput("value");
expect(AlertMessage.isPresent()).toBe(false);
browser.driver.sleep(5000);
});
});
ComponentModule.js
this.editinput = async function (value) {
let selectCheckbox2 = element(by.xpath('/html/body/app-root/app-home/div/div/div[2]/as-split/as-split-area[2]/app-tabhost/app-tab[1]/div/app-files/div/div[2]/ag-grid-angular/div/div[2]/div[1]/div[3]/div[2]/div/div/div[12]/div[1]'));
await selectCheckbox2.click();
await browser.driver.sleep(5000);
browser.ignoreSynchronization = true;
let selectNext = element(by.xpath('//*[@id="next"]'));
await selectNext.click();
await browser.driver.sleep(5000);
browser.ignoreSynchronization = true;
let input = element(by.xpath('/html/body/app-root/app-home/div/div/div[2]/as-split/as-split-area[2]/app-tabhost/app-tab[2]/div/div[2]/div[1]/button[2]'))
await input.click();
let right = element(by.className("right_button"));
await right.click();
await browser.driver.sleep(2000);
let edit = element(by.className("edit_box"));
await edit.sendKeys(value);
await browser.driver.sleep(5000);
let saveBtn = element(by.xpath('/html/body/app-root/app-home/div/div/div[2]/as-split/as-split-area[2]/app-tabhost/app-tab[2]/div/app-procedure/div/div[2]/div[1]/button[3]/i'));
await saveBtn.click();
await browser.driver.sleep(8000);
browser.ignoreSynchronization = false;
};
conf.js
exports.config = {
framework: 'jasmine',
seleniumAddress: 'http://localhost:4444/wd/hub',
capabilities: {
browserName: 'chrome',
acceptSslCerts: true,
shardTestFiles: false,
maxInstances: 1
},
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 100000,
},
onPrepare: () => {
browser.manage().window().maximize();
browser.manage().timeouts().implicitlyWait(10000);
browser.ignoreSynchronization = true;
}
}
尝试一下!
在每个步骤之后都使用browser.driver.sleep(5000);
并不是一种好的自动化测试实践。因此,请尝试从beforeAll,beforeEach和单击element之后删除browser.driver.sleep(5000);
。如果需要,请始终尝试尽量减少睡眠。
使用预期条件[在这里]:https://www.protractortest.org/#/api?view=ProtractorExpectedConditions而不是使用睡眠。
conf.js更改。
directConnect: true,
allScriptsTimeout: 50000,
检查[此处]:https://www.protractortest.org/#/server-setup
隐式使用最小值等待
browser.manage().timeouts().implicitlyWait(500);