我正在测试中运行一些断言,由于某些原因,在第一个断言之后我的测试会失败。仅当我在Electron78或CI上运行测试时。使用Chrome 79执行这些测试时,我通过了这些测试。
我正在使用Cypress V3.8.2,节点v12.10.0。
我修改了原始测试并在此处粘贴了副本:
SmokeTests.js
import PortalPages from "./Pages/PortalPages.js"
import Config from"./Actions/TestConfig.js";
const testFixture = Config.TestConfig.testFixture;
const test = Config.TestConfig.test;
const oneTimeSetup = Config.TestConfig.oneTimeSetup;
const TEST_PORTAL = Config.PORTAL.TEST_PORTAL;
testFixture('Smoke Tests', () => {
oneTimeSetup(TEST_PORTAL);
test('QaClickAcademy Portal is reachable',async ()=>{
let homePage=new PortalPages.Dashboard;
assert.equal("Featured CoursesWhat Our Students Say",await homePage.pageContent);
assert.equal("Featured CoursesWhat Our Students Say",await homePage.pageContent);
});
});
PortalPages.js
import Page from './Page.js'
class PortalPages extends Page {
constructor(){
super();
}
get pageContent() { return Page.getText( cy.get('h2'));}
}
class Dashboard extends PortalPages {
constructor(){
super();
this.path =Page.testPortal+"/Dashboard";
}
}
module.exports =
{
Dashboard:Dashboard
}
TestConfig.js
import Page from "../Pages/Page.js"
const PORTAL={
TEST_PORTAL : 'PORTAL'
}
class TestConfig{
static oneTimeSetup(aPortal){
switch (aPortal){
case PORTAL.TEST_PORTAL:
TestConfig.clearExistingCookiesLoginAndPreserveNewCookies(aPortal,"__smToken",
Page.testPortal);
}
}
static clearExistingCookiesLoginAndPreserveNewCookies(aPortal,cookie,url){
before('Clear cookies and visit login page.', () => {
cy.clearCookies();
cy.visit(url);
});
beforeEach('Preserve Session Before Each Testcase.', () => {
Cypress.Cookies.preserveOnce(cookie);
});
}
static testFixture = (description, func) => {
describe(description, () => {
func();
});
}
static test = (description, func) => {
it(description, func);
}
};
module.exports =
{
PORTAL: PORTAL,
TestConfig: TestConfig
}
Page.js
class Page{
goto(url)
{
cy.visit(url);
}
static getText(htmlElement){
return new Cypress.Promise((resolve) => {
htmlElement.then(($el)=> {
cy.wrap($el);
let message=$el.text();
resolve(message);
});
});
}
}
Page.testPortal="http://www.qaclickacademy.com"
module.exports =Page;
在此方面,我将不胜感激。谢谢