question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Protractor says element is displayed while it's not

See original GitHub issue

Hi @juliemr

I have another test fails even if it does the right thing and the app also behaves correct.

The running app is here: http://shopware40demo.couchcommerce.com/

You can open a search bar by clicking the search icon in the header. I have a test for it, that checks if this is working:

    it('should show search bar on click on search icon', function () {
        app.openSearchBar();
        expect(app.searchBar().isDisplayed()).toBe(true);
    });

The page objects method openSearchBar() looks like this:

    this.openSearchBar = function () {
        element(by.className('cc-header__icon--search')).click();
    };

This test runs successfully. Now, I have another test, that should check, if the app also closes the search bar, when clicking the regarding button.

The test looks like this:

    it('should close search bar', function () {
        app.openSearchBar();
        app.closeSearchBar();
        expect(app.searchBar().isDisplayed()).toBe(false);
    });

The closeSearchbar() method on the page object is defined as follows:

    this.closeSearchBar = function () {
        element(by.className('cc-search-box__close')).click();
    };

But this test fails, it says that the search bar is still displayed even after closing it:

< Failures:
<   1) CouchCommerce App should close search bar
<    Message:
<      Expected true to be false.
<    Stacktrace:

<      Error: Expected true to be false.
<     at promises.not (/usr/local/lib/node_modules/protractor/jasminewd/index.js:88:34)
< Finished in 33.715 seconds

< 7 tests, 7 assertions, 1 failure
<

program terminated

I added debugger statements to check if everything work out fine.

    it('should close search bar', function () {
        app.openSearchBar();
        browser.debugger();
        app.closeSearchBar();
        browser.debugger();
        expect(app.searchBar().isDisplayed()).toBe(false);
    });

Everything works as expected! But app.searchBar().isDisplayed() still resolves with true.

Is that a bug with protractor, or is there anything I can do to make it work?

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
elgalucommented, Jul 10, 2014

The thing is that isDisplayed() returns a webdriver.promise.Promise so:

element(by.css('.navbar-toggle')).isDisplayed().then(function(visible) {
  if (visible) {
    ...
  } else {
    ...
  }
});

So how jasmine can evaluate the correct result? that’s actually jasminewd wrapping matchers so that it can take webdriverJS promises.

0reactions
defxcommented, Mar 25, 2015

@juliemr I encountered this issue whilst writing protractor tests for a carousel component where each slide is absolutely positioned. In it’s initial state (the carousel showing slide 1), calling isDisplayed on slide 1 and 2 correctly return true and false respectively, but after paging to slide 2 then calling isDisplayed again, slide 1 and 2 return true and true respectively, even though slide 1 is now out of view. Here’s the gist of my workaround for anybody encountering the same issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

css - Protractor - Element not visible (but visible when checked ...
I'm new to protractor. I cannot click an element in protractor, it says its not visible even if its visible when checked manually....
Read more >
Correct Strategy for Element to be not present in DOM
An expectation for checking that an element is present on the DOM of a page and visible. Visibility means that the element is...
Read more >
How to check if an element is present with protractor?
Check whether the element is currently displayed on the page. It returns a boolean value if the element is displayed or not. var...
Read more >
Protractor How to find element locators - YouTube
website - https://automationstepbystep.com/ Today we will learn: 1. How to find elements on webpage for Angular applications … Show more.
Read more >
How to use protractor to check if an element is visible
Protractor is an end-to-end test framework developed for AngularJS applications, however, it also works for non-Angular JS applications.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found