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

测试量角器中的元素是否禁用

  •  0
  • nhrcpt  · 技术社区  · 5 年前

    我们在应用程序上有一些应禁用的复选框。下面是HTML代码段:

    <label _ngcontent-c17="">
    <input _ngcontent-c17="" checked="" disabled="" type="checkbox" value="">
        <span _ngcontent-c17="" class="ml-2"> Speech</span>
    </label>
    

    在应用程序中,我看到复选框同时被选中和禁用。

    下面是测试“speech”复选框是否被选中和禁用的代码段:

     it(' Should validate the checked list on "Not Started" Page ', function () {
      expect(EC.elementToBeSelected(G.Speech_Checkbox_on_Services)).toBeTruthy();
      expect(G.Speech_Checkbox_on_Services.isEnabled()).toBeFalsy();
      expect(G.Speech_Checkbox_on_Services.getAttribute('disabled')).toBeTruthy();
      });
    

    代码的最后两行应该检查复选框是否被禁用。但是,当我运行它时,两条线都失败了。我怎么修这个?

    Expected true to be falsy.
    Expected null to be truthy.
    

    原木:

    Error: Failed expectation
    at UserContext.<anonymous> (C:\ESY_testing-and-deployment\Non_Test_Speks\TestBed.js:57:57)
    at C:\Users\Nasim Patwary\AppData\Roaming\npm\node_modules\protractor\node_modules\jasminewd2\index.js:112:25
    at new ManagedPromise (C:\Users\Nasim Patwary\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:1077:7)
    at ControlFlow.promise (C:\Users\Nasim Patwary\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:2505:12)
    at schedulerExecute (C:\Users\Nasim Patwary\AppData\Roaming\npm\node_modules\protractor\node_modules\jasminewd2\index.js:95:18)
    at TaskQueue.execute_ (C:\Users\Nasim Patwary\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:3084:14)
    at TaskQueue.executeNext_ (C:\Users\Nasim Patwary\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:3067:27)
    at asyncRun (C:\Users\Nasim Patwary\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:2974:25)
    at C:\Users\Nasim Patwary\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:668:7
    
    Error: Failed expectation
    at UserContext.<anonymous> (C:\ESY_testing-and-deployment\Non_Test_Speks\TestBed.js:58:70)
    at C:\Users\Nasim Patwary\AppData\Roaming\npm\node_modules\protractor\node_modules\jasminewd2\index.js:112:25
    at new ManagedPromise (C:\Users\Nasim Patwary\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:1077:7)
    at ControlFlow.promise (C:\Users\Nasim Patwary\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:2505:12)
    at schedulerExecute (C:\Users\Nasim Patwary\AppData\Roaming\npm\node_modules\protractor\node_modules\jasminewd2\index.js:95:18)
    at TaskQueue.execute_ (C:\Users\Nasim Patwary\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:3084:14)
    at TaskQueue.executeNext_ (C:\Users\Nasim Patwary\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:3067:27)
    at asyncRun (C:\Users\Nasim Patwary\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:2974:25)
    at C:\Users\Nasim Patwary\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:668:7
    
    1 回复  |  直到 5 年前
        1
  •  2
  •   Bharath Kumar S    5 年前

    如果要检查复选框是否被选中和禁用

    expect(G.Speech_Checkbox_on_Services.attr('checked')).toBeTruthy();
    expect(G.Speech_Checkbox_on_Services.getAttribute('disabled')).toBe(true);
    

    https://www.protractortest.org/#/api?view=webdriver.WebElement.prototype.isEnabled

    希望这有帮助。