Currently, I am encountering an issue with validating the text on my links before and after they are clicked.
If the link text reads "one two" before clicking and remains as "one two" after the click, then the test case passes. However, if the text changes to "two one" after the click, the test case fails.
I have tried using
expect(beforeClick).toContain(afterClick)
and expect(beforeClick).matches(afterClick)
, but both methods do not seem to work for me. Therefore, I am in search of a simpler method like just containing the text.
Do you know of any alternative approach that could help with this situation?
verifyLinks() {
var allLinks = element.all(by.css('div>h3>a'));
browser.sleep(15000); // added for debugging purposes to wait for page loading.
allLinks.count().then(function (length) {
console.log('Number of links: ' + length);
for (let i = 0; i < length; i++) {
allLinks.get(i).getText().then(function (linkTextBeforeClick) {
var string = linkTextBeforeClick.replace(/\(|,/g, '');
var textBeforeClick = string.replace(/\)|,/g, '');
console.log("Before Click Text:" + textBeforeClick);
allLinks.get(i).click();
browser.sleep(5000);
element(by.css('div>h2')).getText().then(function (linkTextAfterClick) {
var string = linkTextAfterClick.replace(/\(|,/g, '');
var textAfterClick = string.replace(/\)|,/g, '');
console.log("After Click Text:" + textAfterClick);
expect(textBeforeClick).toContain(textAfterClick);
})
browser.navigate().back();
})
}
})
}