dimanche 28 octobre 2018

Expected to have a button disables fails

I am trying to perform some user interface end to end tests on an angular project. What I do:

  • Use Gherkin and Cucumber to write my scenarios.
  • I translate them in Protractor for example like this:
 Given('first step', {timeout: 90 * 1000},function(callback) {
     .... some code
     
    });
 
  When('second step',{timeout: 90 * 1000},  function(name, callback) {
       some code 
   
});

The reason I am not specifying what is inside these functions is because everythiung that is there is executed perfectly. So in these functions I perform some steps on my app, like login, put some data and log out, which are run perfectly and I can see them executed in my browser when I run tests.

  • Thirdly I need to write some expectations after performing the steps, so what I want to check is if a button that I have in my app is disabled or enabled after teh test. Here is the HTML code for my button:
<button id="ref_button" type="submit" [disabled]="editForm.form.invalid || isSaving" class="btn btn-primary">

As you can see there is used Angular to disable or enable the button.

Now to write assertions for Cucumber and priotrcator the only library that I could find in cucumber documentation is Chai cucumber page where I see teh recomendadtion Chai library for dom

Now I write this line as an expectation according to chai syntax tocheck teh disability of the button:

 document.getElementById("ref_button").should.have.attr("disabled");

The error that I get this:

  **ReferenceError: document is not defined**
Is there something wrong? I have had plenty of research on this. Has somebody used another better library for assertions in this case? Help please!

Aucun commentaire:

Enregistrer un commentaire