我在tect.html文件中有此表单,我想测试按钮是否被禁用:
//an ID INPUT
<label class="form-control-label" jhiTranslate="oncosupApp.protocolo.identificador" for="field_identificador">Identificador</label>
<input type="text" class="form-control" name="identificador" id="field_identificador"
[(ngModel)]="protocolo.identificador" required/>
//and the button
<button id="ref_button" type="submit" [disabled]="editForm.form.invalid || isSaving" class="btn btn-primary">
我正在使用量角器,黄瓜和dom方法来测试在表单数据无效时此按钮是否被禁用,因此我像这样检查其属性已禁用:
const { Given, When, Then } = require('cucumber');
const jsdom = require("jsdom");
const { JSDOM } = jsdom;
const chai = require('chai');
const expect = chai.expect;
const should = chai.should();
chai.use(require('chai-dom'));
Given('I go to the project', {timeout: 90 * 1000},function(callback) {
browser.driver.manage().window().maximize();
browser.get('http://localhost:8080/#/').then(callback);
});
When('I put a blank id',{timeout: 90 * 1000}, function( callback) {
element(by.css("*[id='field_identificador']")).click();
element(by.css("*[id='field_identificador']")).sendKeys('4').then(callback);
});
Then('Disabled should be true',{timeout: 90 * 1000}, function() {
JSDOM.fromFile("src/main/webapp/app/entities/protocolo/protocolo-dialog.component.html").then(dom => {
dom.window.document.getElementById("ref_button").hasAttribute('disabled').should.be.true;
});
});
//describe.....
it('When the id is blank form is invalid so disabled should be true', function () {
element(by.css("*[id='field_identificador']")).click();
element(by.css("*[id='field_identificador']")).sendKeys('');
expect(button.getAttribute('disabled')).toEqual('true');
});
谢谢!