In one of the tests, we need to assert that one of the 3 elements is present. Currently we are doing it using the protractor.promise.all()
and Array.reduce()
:
var title = element(by.id("title")),
summary = element(by.id("summary")),
description = element(by.id("description"));
protractor.promise.all([
title.isPresent(),
summary.isPresent(),
description.isPresent()
]).then(function (arrExists) {
expect(arrExists.reduce(function(a,b) { return a || b; })).toBe(true);
});
Is there a better way to solve it with Jasmine without resolving the promises explicitly? Would we need a custom matcher or it is possible to solve with the built-in matchers?
To check if all of the values in an array are equal to true , use the every() method to iterate over the array and compare each value to true , e.g. arr. every(value => value === true) . The every method will return true if the condition is met for all array elements.
To check if all values in an array are equal:Use the Array. every() method to iterate over the array. Check if each array element is equal to the first one. The every method only returns true if the condition is met for all array elements.
In order to check whether every value of your records/array is equal to each other or not, you can use this function. allEqual() function returns true if the all records of a collection are equal and false otherwise.
The every() method executes a function for each array element. The every() method returns true if the function returns true for all elements.
You could simply get all the elements with a single selector and assert that the count is superior to zero:
var title_summary_description = element.all(by.css("#title, #summary, #description"));
expect(title_summary_description.count()).toBeGreaterThan(0);
Check this:
let EC = protractor.ExpectedConditions;
let title = EC.visibilityOf($("#title")),
summary = EC.visibilityOf($("#summary")),
description = EC.visibilityOf($("#description"));
expect(EC.or(title, summary, description)() ).toBeTruthy('Title or summary or description should be visible on the page')
Notice that i am executing function that ExpectedCondition returns - so i am getting result of that function(Promise that will be resolved to boolean) instead of function.
You can use .presenceOf() if you need it instead .visibilityOf()
http://www.protractortest.org/#/api?view=ExpectedConditions.prototype.or
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With