Javascript 条件测试
在我的测试中,我想根据当前的墙纸更改背景。为此,我使用条件测试:Javascript 条件测试,javascript,css,cypress,Javascript,Css,Cypress,在我的测试中,我想根据当前的墙纸更改背景。为此,我使用条件测试: it(“更改壁纸”,()=>{ if(wallpaperPage.backgroundImage()应该('have.css','background','rgb(38167223)url('https://url.com/ck/img/common/wallpapers/wallpaper_1.png)重复滚动0%0%/120px填充框(边框框){ wallpapage.purpleColorButton()。单击({forc
it(“更改壁纸”,()=>{
if(wallpaperPage.backgroundImage()应该('have.css','background','rgb(38167223)url('https://url.com/ck/img/common/wallpapers/wallpaper_1.png)重复滚动0%0%/120px填充框(边框框){
wallpapage.purpleColorButton()。单击({force:true});
cloudsButton()。单击({force:true});
wallpapage.backgroundImage()应该('have.css','background color','rgb(143,40,140)');
WallpapPage.backgroundImage()应该('have.css','backgroundImage','url('https://url.com/ck/img/common/wallpapers/wallpaper_2.png")');
}否则{
blueColorButton()。单击({force:true});
WallpapPage.watermelonsButton()。单击({force:true});
wallpapage.backgroundImage()应该('have.css','background color','rgb(38167223));
WallpapPage.backgroundImage()应该('have.css','backgroundImage','url('https://url.com/ck/img/common/wallpapers/wallpaper_1.png")');
}
})
首先,您需要提取“背景”值进行比较。在下面的代码段中,$el
是一个jquery(cypress自动包含jquery)实例,用于获取“背景”值
it("change the wallpaper", () => {
wallpaperPage.backgroundImage().then($el => {
const background = $el.css('background');
if (background === 'rgb(38, 167, 223) url("https://url.com/ck/img/common/wallpapers/wallpaper_1.png") repeat scroll 0% 0% / 120px padding-box border-box') {
wallpaperPage.purpleColorButton().click({force: true});
wallpaperPage.cloudsButton().click({force: true});
wallpaperPage.backgroundImage().should('have.css', 'background-color', 'rgb(143, 40, 140)');
wallpaperPage.backgroundImage().should('have.css', 'background-image', 'url("https://url.com/ck/img/common/wallpapers/wallpaper_2.png")');
} else {
wallpaperPage.blueColorButton().click({force: true});
wallpaperPage.watermelonsButton().click({force: true});
wallpaperPage.backgroundImage().should('have.css', 'background-color', 'rgb(38, 167, 223)');
wallpaperPage.backgroundImage().should('have.css', 'background-image', 'url("https://url.com/ck/img/common/wallpapers/wallpaper_1.png")');
}
});
})
首先,您需要提取“背景”值进行比较。在下面的代码段中,
$el
是一个jquery(cypress自动包含jquery)实例,用于获取“背景”值
it("change the wallpaper", () => {
wallpaperPage.backgroundImage().then($el => {
const background = $el.css('background');
if (background === 'rgb(38, 167, 223) url("https://url.com/ck/img/common/wallpapers/wallpaper_1.png") repeat scroll 0% 0% / 120px padding-box border-box') {
wallpaperPage.purpleColorButton().click({force: true});
wallpaperPage.cloudsButton().click({force: true});
wallpaperPage.backgroundImage().should('have.css', 'background-color', 'rgb(143, 40, 140)');
wallpaperPage.backgroundImage().should('have.css', 'background-image', 'url("https://url.com/ck/img/common/wallpapers/wallpaper_2.png")');
} else {
wallpaperPage.blueColorButton().click({force: true});
wallpaperPage.watermelonsButton().click({force: true});
wallpaperPage.backgroundImage().should('have.css', 'background-color', 'rgb(38, 167, 223)');
wallpaperPage.backgroundImage().should('have.css', 'background-image', 'url("https://url.com/ck/img/common/wallpapers/wallpaper_1.png")');
}
});
})
尝试粘贴所有html代码尝试粘贴所有html代码