Search code examples
cssbootstrap-4pugcasperjs

CasperJs test can't found css selector (test broke after migrate from jade to pug)


I migrate my templates from jade to pug then all casperJs tests are falling. Most errors are about the css selectors that are not found. here an example of my code :

casperJs test:

casper.thenOpen("http://localhost:8080/activites/E5555", function() {
    this.wait(5000, function() {
      this.click("a.open-user-dialog");
    });
  });

and here the pug for the element:

p
    i.fa-icon-plus.fa-icon-success 
    strong: a.open-user-dialog(href="#user-dialog", data-toggle="modal") Add user

here the test result:

FAIL Cannot dispatch mousedown event on nonexistent selector: a.open-user-dialog

I will appreciate any help.


Solution

  • Finally i figured it out, here the answer: I put casper.wait(2000, function(){}); before loading the page and it fixed the problem.

    casper.wait(2000, function(){});
    casper.thenOpen("http://localhost:8080/activites/E5555", function() {
        this.wait(5000, function() {
          this.click("a.open-user-dialog");
        });
      });