Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Click not working on ion-button (e2e) #62

Open
Natanael1234 opened this issue Aug 9, 2017 · 9 comments
Open

Click not working on ion-button (e2e) #62

Natanael1234 opened this issue Aug 9, 2017 · 9 comments

Comments

@Natanael1234
Copy link

Natanael1234 commented Aug 9, 2017

I 'm developing an Ionic 3 PWA (using lazy load). The tests was based on this example. I'm trying to do e2e tests.

My initial test is try to fill a form and click in the submit button of a login screen. I can select the button, altought the click event doesn't works. It should show an error message if the input are empty.

My test:


import { browser, by, WebElementPromise } from 'protractor';

describe('App', () => {

  beforeEach(() => {
    
  });

  describe('default screen', () => {
    beforeEach(() => {
      browser.navigateTo('http://10.0.1.63:8100/#/login');
    });

    

    it('It must work', () => {
              browser.findElement(by.css('#login-button')).then(function (element) {                    
                element.click().then(function (clickResult) {
                      console.log(clickResult) // it logs null
                  }).catch(function (error) {
                      console.error('ERROr ON CLICK', error)
                  });
              }).catch(function (error: Error) {
                  console.error('ERROR ON FIND ELEMENT', error)
              });
    });
        
  })
});


Package.json:
{
  "name": "ionic-unit-testing-example",
  "author": "Ionic Framework",
  "homepage": "https://ionicframework.com/",
  "private": true,
  "scripts": {
    "clean": "ionic-app-scripts clean",
    "build": "ionic-app-scripts build",
    "ionic:build": "ionic-app-scripts build",
    "ionic:serve": "ionic-app-scripts serve",
    "test": "karma start ./test-config/karma.conf.js",
    "test-ci": "karma start ./test-config/karma.conf.js --single-run",
    "e2e": "webdriver-manager update --standalone false --gecko false; protractor ./test-config/protractor.conf.js"
  },
  "dependencies": {
    "@angular/common": "4.1.2",
    "@angular/compiler": "4.1.2",
    "@angular/compiler-cli": "4.1.2",
    "@angular/core": "4.1.2",
    "@angular/forms": "4.1.2",
    "@angular/http": "4.1.2",
    "@angular/platform-browser": "4.1.2",
    "@angular/platform-browser-dynamic": "4.1.2",
    "@ionic-native/core": "3.12.1",
    "@ionic-native/splash-screen": "3.12.1",
    "@ionic-native/status-bar": "3.12.1",
    "@ionic/storage": "2.0.1",
    "ionic-angular": "3.3.0",
    "ionicons": "3.0.0",
    "rxjs": "5.1.1",
    "sw-toolbox": "3.4.0",
    "zone.js": "0.8.11"
  },
  "devDependencies": {
    "@ionic/app-scripts": "1.3.7",
    "@ionic/cli-plugin-ionic-angular": "1.4.1",
    "@types/jasmine": "^2.5.41",
    "@types/node": "^7.0.8",
    "angular2-template-loader": "^0.6.2",
    "html-loader": "^0.4.5",
    "ionic": "3.7.0",
    "jasmine": "^2.5.3",
    "jasmine-spec-reporter": "^4.1.0",
    "karma": "^1.5.0",
    "karma-chrome-launcher": "^2.0.0",
    "karma-jasmine": "^1.1.0",
    "karma-jasmine-html-reporter": "^0.2.2",
    "karma-sourcemap-loader": "^0.3.7",
    "karma-webpack": "^2.0.3",
    "null-loader": "^0.1.1",
    "protractor": "^5.1.1",
    "ts-loader": "^2.0.3",
    "ts-node": "^3.0.2",
    "typescript": "2.3.3"
  },
  "version": "0.0.1",
  "description": "An Ionic project"
}

@leifwells
Copy link
Contributor

Is the button clickable when you click it?

Also, I typically use Protractor's element object to locate my elements. As in:

let button = element(by.css('#login-button'));
let expected = browser.ExpectedConditions;
browser.wait(expected.elementToBeClickable(button));
button.click().then(() => {
     // tests here
});

... but maybe I'm old school.

Are you receiving errors in the terminal window? If so, what do they look like?

@anibalsanchez
Copy link

Same issue here.

The problem is that elementToBeClickable is true but the click method throws the exception about not being clickable.

@philippdrebes
Copy link

Same issue here.

  loginBtn = element(by.css('button[type="submit"]'));

...

    let expected = browser.ExpectedConditions;
    await browser.wait(expected.elementToBeClickable(this.loginBtn), 5000);
    await this.loginBtn.click();

Results in this error:

Error: WebDriverError: unknown error: Element <button class="login-button button button-md button-default button-default-md button-md-primary" color="primary" float-right="" ion-button="" type="submit" ng-reflect-color="primary">...</button is not clickable at point (705, 270). Other element would receive the click: 
<div class="click-block click-block-enabled click-block-active"></div>

@ilkkanisula
Copy link

ilkkanisula commented May 25, 2018

I'm also having random issues with click-block never leaving.

Try the following:
browser.executeScript('arguments[0].click()', loginBtn.getWebElement())

@trajano
Copy link

trajano commented Jun 5, 2019

@ilkkanisula didn't work for me. it does not error out but the button didn't click

@trajano
Copy link

trajano commented Jun 5, 2019

@philippdrebes were you able to fix it? I am getting the same error as you right now.

@trajano
Copy link

trajano commented Jun 5, 2019

Ok here's the weird part

This fails

    console.log("Wait for button to be clickable");
    await browser.wait(ExpectedConditions.elementToBeClickable(signInButton));
    expect(signInButton.isDisplayed()).toBeTruthy();
    signInButton.click();

But this worked

    console.log("Wait for button to be clickable");
    await browser.wait(ExpectedConditions.elementToBeClickable(signInButton));
    expect(signInButton.isDisplayed()).toBeTruthy();
    console.log("click", signInButton); // just added this
    signInButton.click();

@trajano
Copy link

trajano commented Jun 5, 2019

Here's what I eventually ended up with, basically I just made it wait for that webElement promise from @ilkkanisula to be fullfilled

    await browser.wait(ExpectedConditions.elementToBeClickable(signInButton));
    expect(signInButton.isDisplayed()).toBeTruthy();
    await signInButton.getWebElement();
    signInButton.click();

@adetokunbo
Copy link

adetokunbo commented Jun 20, 2019

FWIW: here's what I worked for me after I tried the solutions from @trajano and @ilkkanisula without success

// my-page.po.ts

export class MyPagePO {
  ...
  get clickBlocker()  {
     return element(by.css('div.click-block'));
  }

  async waitUntilNotBlocked() {
     // the loop is needed because the click-block element does not show up immediately
     for (var i = 0; i < 3; i++) {
       await browser.waitForAngular();
       await browser.wait(ExpectedConditions.invisibilityOf(this.clickBlocker));
       await browser.sleep(1000);
     }
  }

  ...
}

// my-test.e2e-spec.ts
...
let po = MyPagePO();
await browser.wait(ExpectedConditions.elementToBeClickable(po.myButton));
await po.waitUntilNotBlocked();
await po.myButton.click()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants