我正在为健康网站的注册过程编写e2e测试。在注册之前,有一个试验注册过程,用于将用户排除或纳入研究。我必须编写一个测试用例,其中将用户排除在研究范围之外,然后浏览器重新启动,并且用户再次填写所有调查表并纳入研究范围。由于用户必须回答相同的问题,因此测试是相同的。因此,有没有一种方法可以重定向驱动程序以重新启动所有测试。
protractor.conf.js
const { SpecReporter } = require('jasmine-spec-reporter');
exports.config = {
allScriptsTimeout: 11000,
specs: [
'./src/**/*.e2e-spec.ts'
],
multiCapabilities: [
{
'browserName': 'chrome',
'chromeOptions': {
'prefs': {
'profile.managed_default_content_settings.notifications': 1}
}
}
],
directConnect: true,
baseUrl: 'http://localhost:4200/',
framework: 'jasmine',
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 30000,
print: function() {}
},
onPrepare() {
require('ts-node').register({
project: require('path').join(__dirname, './tsconfig.e2e.json')
});
jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } }));
}
};
app.e2e-spec.ts
describe('workspace-project App', () => {
let page: AppPage;
beforeEach(() => {
page = new AppPage();
});
it('should show login dialog', () => {
page.navigateTo();
browser.waitForAngularEnabled(false);
browser.sleep(1000);
page.clickBurgerBtn();
browser.sleep(3500);
page.clickLoginLink();
browser.sleep(2500);
expect(page.getTextOnLoginDialog()).toEqual('Not a member yet? Join the study');
});
it('should click on study and fill trial registration form', () => {
page.clickSignupLink();
browser.sleep(1500);
page.fillSignupForm();
browser.sleep(2000);
page.fillTrialRegForm();
//user gets excluded
browser.restart();
// restart tests
// user gets included
});
您只需将其放入for循环中以执行两次。
describe('workspace-project App', () => {
let page: AppPage;
beforeEach(() => {
page = new AppPage();
});
for(let i=0;i<2;i++) {
describe('Execute block of code twice', function() {
it('should show login dialog', () => {
page.navigateTo();
browser.waitForAngularEnabled(false);
browser.sleep(1000);
page.clickBurgerBtn();
browser.sleep(3500);
page.clickLoginLink();
browser.sleep(2500);
expect(page.getTextOnLoginDialog()).toEqual('Not a member yet? Join the study');
});
it('should click on study and fill trial registration form', () => {
page.clickSignupLink();
browser.sleep(1500);
page.fillSignupForm();
browser.sleep(2000);
page.fillTrialRegForm();
//user gets excluded
browser.restart();
// restart tests
// user gets included
});
});
}
});