|
1 |
| -import {browser, by, element} from 'protractor'; |
| 1 | +import {browser, by, element, Key} from 'protractor'; |
2 | 2 |
|
3 | 3 | describe('checkbox', function () {
|
| 4 | + |
4 | 5 | describe('check behavior', function () {
|
| 6 | + |
5 | 7 | beforeEach(function() {
|
6 | 8 | browser.get('/checkbox');
|
7 | 9 | });
|
8 |
| - it('should be checked when clicked, and be unchecked when clicked again', function () { |
9 |
| - element(by.id('test-checkbox')).click(); |
10 |
| - element(by.css('input[id=input-test-checkbox]')).getAttribute('checked').then((value: string) => { |
| 10 | + |
| 11 | + it('should be checked when clicked, and be unchecked when clicked again', () => { |
| 12 | + let checkboxEl = element(by.id('test-checkbox')); |
| 13 | + let inputEl = element(by.css('input[id=input-test-checkbox]')); |
| 14 | + |
| 15 | + checkboxEl.click(); |
| 16 | + inputEl.getAttribute('checked').then((value: string) => { |
11 | 17 | expect(value).toBeTruthy('Expect checkbox "checked" property to be true');
|
12 | 18 | });
|
13 | 19 |
|
14 |
| - element(by.id('test-checkbox')).click(); |
15 |
| - element(by.css('input[id=input-test-checkbox]')).getAttribute('checked').then((value: string) => { |
| 20 | + checkboxEl.click(); |
| 21 | + inputEl.getAttribute('checked').then((value: string) => { |
| 22 | + expect(value).toBeFalsy('Expect checkbox "checked" property to be false'); |
| 23 | + }); |
| 24 | + }); |
| 25 | + |
| 26 | + it('should toggle the checkbox when pressing space', () => { |
| 27 | + let inputEl = element(by.css('input[id=input-test-checkbox]')); |
| 28 | + |
| 29 | + inputEl.getAttribute('checked').then((value: string) => { |
16 | 30 | expect(value).toBeFalsy('Expect checkbox "checked" property to be false');
|
17 | 31 | });
|
| 32 | + |
| 33 | + inputEl.sendKeys(Key.SPACE); |
| 34 | + |
| 35 | + inputEl.getAttribute('checked').then((value: string) => { |
| 36 | + expect(value).toBeTruthy('Expect checkbox "checked" property to be true'); |
| 37 | + }); |
18 | 38 | });
|
| 39 | + |
19 | 40 | });
|
20 | 41 | });
|
0 commit comments