Protractor 量角器-打开浏览器,等待,运行测试
我正在学习量角器,它看起来很棒。但是我想在一个页面上运行两个规范。我怎样才能做到这一点?我的问题是,我页面上的很多东西都是通过ajax加载的,有些是通过cascade加载的 目前,我使用Protractor 量角器-打开浏览器,等待,运行测试,protractor,Protractor,我正在学习量角器,它看起来很棒。但是我想在一个页面上运行两个规范。我怎样才能做到这一点?我的问题是,我页面上的很多东西都是通过ajax加载的,有些是通过cascade加载的 目前,我使用wait和beforeach运行规范。代码如下: const br = browser; const url = 'http://localhost:3000'; br.ignoreSynchronization = true; describe('Component', () => { be
wait
和beforeach
运行规范。代码如下:
const br = browser;
const url = 'http://localhost:3000';
br.ignoreSynchronization = true;
describe('Component', () => {
beforeEach(() => { br.get(url); });
it ('should be present', () => {
expect(element(by.className('news-list__wrapper')).isPresent()).toBe(true);
});
it ('should render children', () => {
br.wait(() => {
return element(by.className('news-block')).isPresent();
}, 2500).then((r) => { if (r) { console.log('\n ✓ Component renders children') } });
});
it ('should render images', () => {
br.wait(() => {
return element.all(by.className('news-block__img')).first().isPresent();
}, 2500).then((r) => { if (r) { console.log('\n ✓ Component renders images') } });
});
it ('should load images', () => {
br.wait(() => {
return element(by.className('news-block__image--loaded')).isPresent();
}, 2500).then((r) => { if (r) { console.log('\n ✓ Component loads images') } });
})
})
我能做什么?在
browser.wait()
中使用ExpectedConditions
进行此类ajax调用-
有关这方面的更多详细信息,请参阅API文档-
设置
browser.ignoreSynchronization=false
并使用browser.waitForAngular()
使脚本等待所有ajax调用完成。量角器的功能是,它将等待页面发出的所有异步调用完成,然后只有它将执行下一行代码
const br = browser;
const url = 'http://localhost:3000';
const EC = protractor.ExpectedConditions;
br.ignoreSynchronization = true;
describe('Component', () => {
beforeEach(() => { br.get(url); });
it ('should be present', () => {
expect(element(by.className('news-list__wrapper')).isPresent()).toBe(true);
});
it ('should render children', () => {
br.wait(EC.presenceOf(element(by.className('news-block'))), 2500).then((r) => { if (r) { console.log('\n ✓ Component renders children') } });
});
it ('should render images', () => {
br.wait(EC.presenceOf(element.all(by.className('news-block__img')).first()), 2500).then((r) => { if (r) { console.log('\n ✓ Component renders images') } });
});
it ('should load images', () => {
br.wait(EC.presenceOf(element(by.className('news-block__image--loaded'))), 2500).then((r) => { if (r) { console.log('\n ✓ Component loads images') } });
})
})