Thursday, 1 June 2017

Protractor: Is it possible to check if an element doesn't contain certain text?

On the page that I am testing, a user can have a single currency or multiple currencies (i.e EUR and USD)the currency/currencies will appear in the same div at the top of the page. If a user has multiple currencies, a tab for each currency will appear further down the page, if a user has only one currency, no tabs will appear (as there is no need for the user to switch tabs).

I am able to test multi currency users by checking to see if the text contained in the header matches the text contained in the currencies tabs.

However, as no tabs appear for a single currency, I'm not sure how to test this.

For example, if I have only a 'EUR' currency, is there a way to do something like

if element(by.className("currencies"))contains 'EUR'

&& doesn't contain 'USD' && doesn't contain 'GBP' expect element(by.className("tabs").toDisplay.toBeFalsy()

This is the code for the page object file

this.checkCurrency = function(currency) {
 var checkBalance = element(by.className("balances"));
 checkBalance.getText().then(function (text) {
   if (text.indexOf("GBP" && "EUR")>= 0) {
  expect(element.all(by.linkText("GBP")).isDisplayed()).toBeTruthy();
   console.log("EUR GBP buyer");
   }
   else if (text.indexOf("GBP" && "USD")>= 0) {
  expect(element.all(by.linkText('USD')).isDisplayed()).toBeTruthy();
   console.log("USD GBP buyer");
   }
   else
   {
   console.log("false");
   }
   });
};


via James

No comments:

Post a Comment