angular / protractor

E2E test framework for Angular apps
http://www.protractortest.org
MIT License
8.75k stars 2.31k forks source link

Need to click twice #2360

Closed mariemignot44 closed 8 years ago

mariemignot44 commented 9 years ago

Hello,

I would like to test i18n on my angular website. There is a French link and an English link in the footer:

<span id="BUTTON_LANG_EN" ng-click="changeLanguage('en')" class="label label-primary">
      <a href="">{{'BUTTON_LANG_EN' | translate }}</a>
</span>
<span id="BUTTON_LANG_FR" ng-click="changeLanguage('fr')" class="label label-primary">
      <a href="">{{'BUTTON_LANG_FR' | translate }}</a>
</span>

Here is my protractor test:

it('test', function() {
    expect(usernameLabel.getText()).toBe('Username');
    var frenchButton = element(by.id("BUTTON_LANG_FR" ));
// here I can't understand why 2 clicks are needed
    frenchButton.click();
    frenchButton.click();
    browser.wait(function() {
      return frenchButton.getText().then(function(text) {
        return text === 'Français';
      });
    }, 1000);

    expect(usernameLabel.getText()).toBe('Identifiant');
});

This test is ok, but if I comment one of the 2 frenchButton.click();, the test fails (timeout in browser wait, nothing translated). I tried to change the template to:

<span class="label label-primary">
      <a id="BUTTON_LANG_EN" ng-click="changeLanguage('en')" href="">{{'BUTTON_LANG_EN' | translate }}</a>
</span>
<span class="label label-primary">
      <a id="BUTTON_LANG_FR" ng-click="changeLanguage('fr')" href="">{{'BUTTON_LANG_FR' | translate }}</a>
</span>

but this is the same result as the code above. I also tried browser.wait(EC.elementToBeClickable(frenchButton), 5000); but it doesn't work better

The browser is FF 39.0. When I manually click on the frenchButton, a single click is needed to translate the page. I also tried to pause protractor and manually click on the frenchButton, the page is translated after the 1st click. My buttons are on the bottom of page, so their coordinates can change during the translation because the content height changes. I tried with browser.waitForAngular() but the test still fails. How can I check if the click event is emitted by the 1st click? Thank you for your answer.

sjelin commented 9 years ago

Have you tried using browser.pause() to debug your problem?

Droogans commented 9 years ago

Sometimes it helps to try and use browser.actions().mouseDown(frenchButton).mouseUp().perform();.

This happens to me sometimes in dropdowns in firefox. Might be worth a shot.

mariemignot44 commented 9 years ago

Thanks for your replies. @sjelin yes I tried. I added browser.pause() before and after clicking: 2 clicks are needed by protractor. If I click manually during the pause, only 1 click is needed @Droogans I tried browser.actions().mouseDown(frenchButton).mouseUp().perform(); but it is not better, protractor needs these actions twice. I also tried browser.actions().mouseMove(frenchButton).click().perform();, without success.

selfrefactor commented 9 years ago

I can confirm that I also had similar issue which was solved by double clicking.

szimek commented 8 years ago

I'm trying to update protractor to 3.0.0, because webdriver used by 2.x.x does not support Firefox 43 anymore.

It looks like something has changed in webdriver 2.48.2, because I have similar issues as mentioned above. In some cases I need to click twice. Sometimes when I call element.click() Firefox tries to scroll to this element, but e.g. because of parallax that messes up scroll height, fails, the element is outside of viewport and element.click() does nothing - there's no error, but the element is not clicked. Things like element.getText() work correctly though. I fixed it by adding a helper that scrolls to the element using element.scrollIntoView() and call it before clicking anything. The way Firefox finds elements by itself (unlike e.g. Chrome) was the main reason for me to use it in e2e tests...

I'm not sure if these 2 issues are related, e.g. if the second click scrolls the page so that the element is in the viewport and the click actually works.

anudeep-mj commented 8 years ago

Yea I have been trying to do the click twice using protractor and it hasnt been working out. I did Droogan's suggestion and I tried browser.pause() too. The browser I am using is chrome for a testing a non-angular single page application

juliemr commented 8 years ago

I'm closing this issue as stale - there's a couple bugs listed that I think aren't actually the same thing, and no way for us to reproduce them. If you are still having an issue that you can show us in a reproducible example, please open up a new issue. Thanks!

yashika-garg09 commented 1 year ago

@mariemignot44 , I am facing the same "Twice click" issue. Did you find any workaround other than clicking twice?