我对角度测试非常新鲜,请帮助将量角器角度e2e测试代码编写到下面的术语和条件复选框。
仅在单击复选框时将启用创建配置文件按钮。
//when clicked the checkbox
<md-checkbox ng-model="terms" aria-label="Terms & Conditions" required="" tabindex="0" type="checkbox" role="checkbox" class="md-checked ng-not-empty ng-dirty ng-valid-parse ng-valid ng-valid-required ng-touched" aria-required="true" aria-checked="true" aria-invalid="false" style=""><div class="md-container md-ink-ripple" md-ink-ripple="" md-ink-ripple-checkbox=""><div class="md-icon"></div><div class="md-ripple-container"></div></div><div ng-transclude="" class="md-label"><span class="ng-scope">
I agree to example</span><a target="_blank" href="https://example.com/" class="ng-scope">Terms & Conditions</a>
</div></md-checkbox>
//when not clicked the checkbox
<md-checkbox ng-model="terms" aria-label="Terms & Conditions" required="" tabindex="0" type="checkbox" role="checkbox" class="ng-dirty ng-valid-parse ng-touched ng-empty ng-invalid ng-invalid-required" aria-required="true" aria-checked="false" aria-invalid="true" style=""><div class="md-container md-ink-ripple" md-ink-ripple="" md-ink-ripple-checkbox=""><div class="md-icon"></div><div class="md-ripple-container"></div></div><div ng-transclude="" class="md-label"><span class="ng-scope">
I agree to example </span><a target="_blank" href="https://example.com/" class="ng-scope">Terms & Conditions</a>
</div></md-checkbox>
答案 0 :(得分:0)
你必须模拟复选框上的点击,然后写一个断言,在这个例子中,断言是元素上的ng-valid
类。
describe('Validate terms and conditions', () => {
it('should accept terms and conditions', (done) => {
browser.get('/#/transfert');
const checkbox = element(by.model('terms'));
checkbox.click().then(() => {
expect(checkbox.getAttribute('class').to.equal('ng-valid'))
});
});
});
答案 1 :(得分:0)
在e2e测试中,实际上您会模拟用户操作,以查看您的应用程序是否按预期响应。所以这里应该遵循以下流程:
let checkboxElement = element(by.model('terms'));
let createProfileButtonElement = element(by.id('my-id-create-profile-button'));
checkboxElement.click().then((data) => {
expect(createProfileButtonElement.isEnabled()).to.become(true);
// done() callback of the it block
});