我们有一些应在应用程序上禁用的复选框。以下是html代码段:
<label _ngcontent-c17="">
<input _ngcontent-c17="" checked="" disabled="" type="checkbox" value="">
<span _ngcontent-c17="" class="ml-2"> Speech</span>
</label>
在应用程序上,我看到该复选框同时处于选中状态和禁用状态。
下面是我的代码段,用于测试是否已选中并禁用“语音”复选框:
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
答案 0 :(得分:2)
如果您要检查复选框是否已选中并禁用
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
希望这会有所帮助。