代码之家  ›  专栏  ›  技术社区  ›  Tester

期望…禁用属性

  •  0
  • Tester  · 技术社区  · 6 年前

    我在一个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">

    我使用了delegator、cucumber和dom方法来测试表单数据无效时是否禁用了此按钮,因此我检查其属性disabled,如下所示:

    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');
    
        });
    我第一次和cuccmber交配的时候缺了什么?也许是jsdom?也许是回电话?也许还有另一种使用cuccmber和protrcator测试dom的方法???

    谢谢!

    0 回复  |  直到 6 年前