I am new in Protractor. And I am doing tests to be familiar with it. Here, I met a problem what I cannot distinguish between ignoreSynchronization and async/await method. I had 3 blocks to test them. The first is clear with protractor's own async features.
it('without await and ignoreSynchronization', async function() {
await browser.waitForAngularEnabled(false);
await browser.driver.get('https://www.baidu.com');
console.log('1');
element(by.css('#kw')).sendKeys('protractor').then(() => {
console.log('2');
});
console.log('3');
console.log('4');
element(by.css('#su')).click().then(() => {
console.log('5');
})
console.log('6');
browser.driver.sleep(2000);
});
It is clear that the print flow is 1,3,4,6,2,5 The second is the first block adding await
it('with await', async function() {
await browser.waitForAngularEnabled(false);
await browser.driver.get('https://www.baidu.com');
await console.log('1');
await element(by.css('#kw')).sendKeys('protractor').then(() => {
console.log('2');
});
await console.log('3');
await console.log('4');
await element(by.css('#su')).click().then(() => {
console.log('5');
})
await console.log('6');
browser.driver.sleep(2000);
});
The print flow of this block is 1,2,3,4,5,6. For the last block, it is a clear version with ignoreSynchronization method
it('with ignoreSynchronization is True', async function() {
await browser.waitForAngularEnabled(false);
await browser.driver.get('https://www.baidu.com');
browser.ignoreSynchronization = true;
console.log('1');
element(by.css('#kw')).sendKeys('protractor').then(() => {
console.log('2');
});
console.log('3');
console.log('4');
element(by.css('#su')).click().then(() => {
console.log('5');
})
console.log('6');
browser.driver.sleep(2000);
});
The result of this block is the same as the first one? I don't know why. Perhaps, I did not use ignoreSynchronization as a correct way. But can anyone explain what's difference between these two methods? Many thanks