Protractor: how to compare the text content of the same web element before and after clicking the button

I would like to test the filter function in my angularJS application. In fact, when I click on the filter, the number of search results displayed on the page should decrease. Here is my code:

    element(by.id('foundNumber')).getText().then (function(text){console.log(text); })
    element(by.repeater('term in facets.uproctype').row(0)).click ()
    element(by.id('foundNumber')).getText().then (function(text){console.log(text); })

And here is my console log:

Using the selenium server at http://localhost:4444/wd/hub
6209
6195
.... 

I do not know how I can compare the theses of two values โ€‹โ€‹in the wait string, since I cannot use them inside my function. Any help?

Thanks Zied

+4
source share
3 answers

I believe that you will need to nest your functions then in order to provide the original value.

element(by.id('foundNumber')).getText().then( function(original_text) {

  element(by.repeater('term in facets.uproctype').row(0)).click ();

  element(by.id('foundNumber')).getText().then( function(new_text){
    expect(original_text).not.toBe(new_text);
  });

});

. https://code.google.com/p/selenium/wiki/WebDriverJs#Control_Flows

+8

- , , .

var oldValue,newValue;
element(by.id('foundNumber')).getText().then(function(text){oldValue=text})
element(by.repeater('term in facets.uproctype').row(0)).click()
element(by.id('foundNumber')).getText().then(function(text){newValue=text})

protractor.promise.controlFlow()
  .execute(function(){return protractor.promise.fulfilled()},'wait for control flow')
    .then(function(){
      expect(oldValue).not.toEqual(newValue);
    });

flow.execute().

+2

, .getText() , expect

var text1 = element(by.id('foundNumber')).getText();
element(by.repeater('term in facets.uproctype').row(0)).click();
var text2 = element(by.id('foundNumber')).getText();
expect(text1).not.toBe(text2);

expect promises, , .

+2

Source: https://habr.com/ru/post/1527898/


All Articles