The two statements are not equivalent as such. I created a simple page like below
<html>
<body>
<div id="first_name">Tarun</div>
<script type="text/javascript">
var div = document.createElement('div');
div.innerText = 'lalwani';
div.id = 'last_name';
setTimeout( () => document.body.appendChild(div), 3000);
</script>
</body>
</html>
And a simple test like below
describe('angularjs homepage todo list', function() {
it('should add a todo', async function() {
browser.waitForAngularEnabled(false);
browser.get('http://0.0.0.0:8000');
const eC = protractor.ExpectedConditions;
browser.wait(element(by.id('last_name')).isPresent(), 10000, 'timeout');
});
});
When you run you will find the output is
Started
...
1 spec, 0 failures
Finished in 0.617 seconds
Now if you change the code to
describe('angularjs homepage todo list', function() {
it('should add a todo', async function() {
browser.waitForAngularEnabled(false);
browser.get('http://0.0.0.0:8000');
const eC = protractor.ExpectedConditions;
browser.wait(eC.visibilityOf(element(by.id('last_name'))), 10000, 'timeout');
});
});
The output of the same is below
Started
...
1 spec, 0 failures
Finished in 3.398 seconds
As you can see the visibilityOf
actually waited for the object to appear while the previous one didn't.
This is because the controlFlow will make isPresent
get executed and return the promise returning value of true/false to the wait. While visibilityOf
will return a function that the wait
can check by calling again and again.
You can verify this by adding below in the test
console.log(typeof eC.visibilityOf(element(by.id('last_name'))))
console.log(typeof element(by.id('last_name')))
The output of same is
function
object
So the assumption your below two statements are same is wrong and that is why you don't get the correct results with the first one
browser.wait(element(by.tagName('myComponent')).isPresent(), 10000, 'timeout');
browser.wait(eC.visibilityOf(element(by.tagName('myComponent'))), 10000, 'timeout');