How to Check If Checkbox Is Checked With Protractor, Cucumberjs and Chai

How can I check if checkbox is checked with Protractor, CucumberJS and Chai?

isSelected() would do that:

this.expect(element(by.model(el)).isSelected()).to.eventually.be.true;

Protractor Check if Element Does Not Exist

Got the thing working by using something I found in the docs:

expect(element(by.css('.switch')).isPresent()).to.become(false).and.notify(next);

Also uses assertions, so it doesn't break cucumberjs.

How to check whether the element exist using chai?

The exist language chain in vanilla Chai is used to verify that a plain old JavaScript object is neither undefined nor null. It sounds like in your case you actually want to be asserting against a DOM element, which vanilla Chai can't do. Instead, you'll need to pull in a Chai plugin like chai-jquery along with jQuery for DOM manipulation. chai-jquery allows you to write assertions against elements you have located using jQuery, and even provides and overriden form of exist that would likely serve your purpose exactly. All together, the code you're looking for to assert a div with class avatar exists would look something like this:

expect($('div.avatar')).to.exist;

Chai expect - expect(browser.getTitle()) errors with - browser.getTitle is not a function

browser is global variable, you can use it directly without to require it. Thus following line is unnecessary:

const browser = require('protractor');


Related Topics



Leave a reply



Submit