0

I have an element on page. And there could be different text. I am trying to do like (code is below), and it is not printed to console.

this.checkStatus = function () {

    var element = $('.message')
    browser.wait(EC.visibilityOf(element), 5000).then(function () {
        browser.wait(EC.textToBePresentInElement(conStatus, 'TEXT1'), 500).then(function () {
            console.log('TEXT1');
        })
        browser.wait(EC.textToBePresentInElement(element, 'TEXT2'), 500).then(function () {
            console.log('TEXT2');
        })
        browser.wait(EC.textToBePresentInElement(element, 'TEXT3'), 500).then(function () {
            console.log('TEXT3');
        })
        browser.wait(EC.textToBePresentInElement(element, 'TEXT4'), 500).then(function () {
            console.log('TEXT4');
        })
    })
    return this;
}

thanks

AlexT
  • 1
  • 4

2 Answers2

0

I see two problems. first, not sure what 'constatus' is? you need to correct that. second, browser.wait will be throwing error/exceptions when it is not able to find matching condition and timeout expires, So, if your first condition doesn't meet, it will throw timeout exception and will never go to second one. Instead, try something like below

var section = "";
this.checkStatus = function () {

    var element = $('.message')
    browser.wait(EC.visibilityOf(element), 5000).then(function () {
        browser.wait(()=>{

        if(EC.textToBePresentInElement(element, 'TEXT1')){
                    section = "Text1";
        }
            else if(EC.textToBePresentInElement(element, 'TEXT2')) {
                    section = "Text2";
            }
        else if(EC.textToBePresentInElement(element, 'TEXT3')) {
                    section = "Text3";
        }
            else if(EC.textToBePresentInElement(element, 'TEXT4')) {
                    section = "Text4";
            }
        if(section !== "")
            return true;
    }, 5000).then(()=>{
    <here you can do anything based on 'section'>

}

Note - I haven't verified compilation errors.. so check for that.

TypeScripter
  • 879
  • 2
  • 10
  • 23
0

Not sure what are you up to, but you can join multiple expected conditions with "or":

var conStatus = $('.message');
var containsText1 = EC.textToBePresentInElement(conStatus, 'TEXT1');
var containsText2 = EC.textToBePresentInElement(conStatus, 'TEXT2');
var containsText3 = EC.textToBePresentInElement(conStatus, 'TEXT3');
var containsText4 = EC.textToBePresentInElement(conStatus, 'TEXT4');

browser.wait(EC.or(containsText1, containsText2, containsText3, containsText4), 5000);
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
  • Hi Alecxe ! Can you help me ? http://stackoverflow.com/questions/39284506/how-to-integrate-protractor-test-cases-in-atom-using-typescript http://stackoverflow.com/questions/39348479/how-to-write-protractor-test-scripts-using-typescript-along-with-jasmine-framewo?noredirect=1#comment66036450_39348479 . – Kishan Patel Sep 07 '16 at 07:05