我有一个简单的赛普拉斯测试:
describe('My First Test', () => {
it('Go to login page', () => {
cy.visit('http://localhost:3000')
cy.contains('Log in').click()
})
it('Login with local account', () => {
cy.get('input[type=email]').type('123@123.com')
cy.get('input[type=password]').type('asd123')
cy.contains('Log in').type('{enter}')
})
})
Run Code Online (Sandbox Code Playgroud)
第一个断言检查是否存在带有 text 的元素Log in
,然后单击它。第二个断言尝试登录。
我已将按钮中的文本更改Log in
为Assertion Failed
。所以现在第一个断言失败了,但它仍然运行第二个断言,即使我没有重定向到登录页面。
当断言失败时,有没有办法取消正在运行的规范?
我已将赛普拉斯从更新3.0.3
为3.1.3
。我正在使用必须与文档相关的ES6导入/导出模块。但是我undefined
在终端中出现一行并且在GUI中出现以下错误:
<root_dir>/node_modules/@babel/runtime/helpers/esm/defineProperty.js:1
export default function _defineProperty(obj, key, value) {
^
ParseError: 'import' and 'export' may appear only with 'sourceType: module'
Run Code Online (Sandbox Code Playgroud)
我的测试使用的是普通JS,没有TS os CoffeeScript。我陷入困境,在3.0.3
它工作正常。
如果 URL 包含“xyz”,如何有条件地跳过测试?在 QA 环境“abc”中运行的某些测试不应在生产“xyz”环境中运行。
我还没有找到有条件地检查环境以触发测试的好例子。需要动态检查 baseURL,并且最好在 beforeEach 中跳过测试。
运行赛普拉斯 6.2.0
beforeEach(() => {
login.loginByUser('TomJones');
cy.visit(`${environment.getBaseUrl()}${route}`);
});
it('test page', function () {
if environment.getBaseUrl().contains("xyz")
then *skip test*
else
cy.intercept('GET', '**/some-api/v1/test*').as('Test'););
cy.get('#submitButton').click();
})
Run Code Online (Sandbox Code Playgroud)
潜在的解决方案(经过测试并成功尝试):我通过 CLI 使用了过滤(分组)和文件夹结构的组合,我设置了文件夹 /integrations/smokeTest/QA 和 /integrations/smokeTest/Prod/
1.QA Test Run:
npm run *cy:filter:qa* --spec "cypresss/integration/smokeTests/QA/*-spec.ts"
2.Run All (both QA and PROD tests)
npm run cypress:open --spec "cypresss/integration/smokeTests/*/*-spec.ts"
3. Prod Test Run:
npm run cy:filter:prod --spec "cypresss/integration/smokeTests/PROD*/*-spec.ts"
Run Code Online (Sandbox Code Playgroud)