【发布时间】:2019-05-14 23:27:17
【问题描述】:
我在一个规范文件中有 2 个描述块。 首先,describe 访问 xyz.com,其次,describe 访问 abc.com
我只需要在一个规范中描述这 2 个。我看到的有线行为是它顺利运行测试,但是在从 2nd describe 访问 abc.com 后,它又开始运行 1st describe。无限循环的测试
var signedOutArtifactID = null;
describe('WEB APP E2E tests', function() {
var token = null;
before(function() {
cy.visit('/');
// Login
cy.get('#username')
.type(auth.geneticist.username);
cy.get('#password')
.type(auth.geneticist.password);
cy.get('button')
.contains('Login')
.click()
.should(function() {
token = localStorage.getItem('token');
expect(token).not.to.be.null;
});
});
beforeEach(function() {
localStorage.setItem('token', token);
cy.contains('Logout')
.should('exist');
expect(localStorage.getItem('token'));
});
it('should land on home page', function() {
cy.url()
.should('include', '/home');
});
it('should save and generate and end up on signout page', function() {
cy.contains('Save and Generate Report')
.click();
cy.url()
.should('include', '/sign-out');
});
it('should signout and send successfully', function() {
cy.url()
.should(function(currentURL) {
signedOutArtifactID = currentURL.match(/2-([0-9]+)/)[0];
expect(signedOutArtifactID).not.to.be.null;
});
// Make sure interpretation was updated
cy.get('.card-body pre')
.should('contain', 'test interpretation added by cypress');
cy.contains('Sign Out and Send')
.click();
cy.contains('Yes, sign out and send')
.click();
});
});
describe('2nd WEB APP E2E tests', function() {
before(function () {
cy.visit({
url:`https://webappurl.com/search?scope=All&query=${signedOutArtifactID}`,
failOnStatusCode: false
})
})
it('Review Completed step in clarity', async () => {
cy.get('#username').type(auth.clarity_creds.username)
cy.get('#password').type(auth.clarity_creds.password)
cy.get('#sign-in').click()
cy.get('.result-name').click()
cy.get('.view-work-link').contains('QWERTYU-IDS').click()
cy.get('.download-file-link ')
.should(($downloads) => {
expect($downloads).to.have.length(2)
})
});
});
【问题讨论】:
-
见:How To Create MCVE。没有代码很难帮助你。
-
@alfasin 不确定代码 sn-p 是否有帮助,但我已经更新了问题
-
为什么同一个文件的根目录有两个不同的描述?如果它们不相关,请将它们放在单独的文件中。如果它们是相关的,则将它们都嵌套在一个附加的描述中,并添加一个描述您将在此文件中测试的内容的字符串。 WDYT?
-
@alfasin 我尝试将它们放在单独的文件中,也尝试在一个文件中包含 2 个描述,但它不起作用(面临同样的问题)。我需要在
should signout and send successfully测试中生成的signedOutArtifactID。两种描述都针对不同的网络应用程序 -
如果你把它们放在不同的文件中 - 为什么它们都被调用了?