Skip to content

Commit

Permalink
Update e2e tests, take screenshots when screen become stable
Browse files Browse the repository at this point in the history
  • Loading branch information
tinayuangao committed Feb 15, 2017
1 parent ec7e2e4 commit 25a168d
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 12 deletions.
10 changes: 7 additions & 3 deletions e2e/components/button/button.e2e.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {browser, by, element} from 'protractor';
import {browser, by, element, ExpectedConditions} from 'protractor';
import {screenshot} from '../../screenshot';


Expand All @@ -9,12 +9,16 @@ describe('button', () => {
it('should prevent click handlers from executing when disabled', () => {
element(by.id('test-button')).click();
expect(element(by.id('click-counter')).getText()).toEqual('1');
screenshot('clicked once');
browser.wait(ExpectedConditions.not(
ExpectedConditions.presenceOf(element(by.css('div.mat-ripple-element')))))
.then(() => screenshot('clicked once'));

element(by.id('disable-toggle')).click();
element(by.id('test-button')).click();
expect(element(by.id('click-counter')).getText()).toEqual('1');
screenshot('click disabled');
browser.wait(ExpectedConditions.not(
ExpectedConditions.presenceOf(element(by.css('div.mat-ripple-element')))))
.then(() => screenshot('click disabled'));
});
});
});
19 changes: 13 additions & 6 deletions e2e/components/checkbox/checkbox.e2e.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {browser, by, element, Key} from 'protractor';
import {browser, by, element, Key, ExpectedConditions} from 'protractor';
import {screenshot} from '../../screenshot';

describe('checkbox', function () {
Expand All @@ -17,31 +17,38 @@ describe('checkbox', function () {
checkboxEl.click();
inputEl.getAttribute('checked').then((value: string) => {
expect(value).toBeTruthy('Expect checkbox "checked" property to be true');
browser.wait(ExpectedConditions.not(
ExpectedConditions.presenceOf(element(by.css('div.mat-ripple-element')))))
.then(() => screenshot('checked'));
});
screenshot('checked');

checkboxEl.click();
inputEl.getAttribute('checked').then((value: string) => {
expect(value).toBeFalsy('Expect checkbox "checked" property to be false');
browser.wait(ExpectedConditions.not(
ExpectedConditions.presenceOf(element(by.css('div.mat-ripple-element')))))
.then(() => screenshot('unchecked'));
});
screenshot('unchecked');
});

it('should toggle the checkbox when pressing space', () => {
let inputEl = element(by.css('input[id=input-test-checkbox]'));

inputEl.getAttribute('checked').then((value: string) => {
expect(value).toBeFalsy('Expect checkbox "checked" property to be false');
screenshot('start');
browser.wait(ExpectedConditions.not(
ExpectedConditions.presenceOf(element(by.css('div.mat-ripple-element')))))
.then(() => screenshot('start'));
});

inputEl.sendKeys(Key.SPACE);

inputEl.getAttribute('checked').then((value: string) => {
expect(value).toBeTruthy('Expect checkbox "checked" property to be true');
screenshot('pressed space');
browser.wait(ExpectedConditions.not(
ExpectedConditions.presenceOf(element(by.css('div.mat-ripple-element')))))
.then(() => screenshot('pressed space'));
});
});

});
});
2 changes: 2 additions & 0 deletions e2e/components/grid-list/grid-list.e2e.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import {browser} from 'protractor';
import {expectToExist} from '../../util/asserts';
import {screenshot} from '../../screenshot';

describe('grid-list', () => {
beforeEach(() => browser.get('/grid-list'));

it('should render a grid list container', () => {
expectToExist('md-grid-list');
screenshot('');
});

it('should render list items inside the grid list container', () => {
Expand Down
2 changes: 2 additions & 0 deletions e2e/components/icon/icon.e2e.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {browser, by, element} from 'protractor';
import {screenshot} from '../../screenshot';

describe('icon', () => {
describe('font icons by ligature', () => {
Expand All @@ -13,6 +14,7 @@ describe('icon', () => {
testIcon.getAttribute('aria-label').then((attr: string) => {
expect(attr).toEqual('favorite');
});
screenshot('');
});

it('should have the correct class when used', () => {
Expand Down
2 changes: 2 additions & 0 deletions e2e/components/list/list.e2e.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import {browser} from 'protractor';
import {expectToExist} from '../../util/asserts';
import {screenshot} from '../../screenshot';

describe('list', () => {
beforeEach(() => browser.get('/list'));

it('should render a list container', () => {
expectToExist('md-list');
screenshot('');
});

it('should render list items inside the list container', () => {
Expand Down
6 changes: 6 additions & 0 deletions e2e/components/menu/menu.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {Key, protractor} from 'protractor';
import {MenuPage} from './menu-page';
import {expectToExist, expectAlignedWith, expectFocusOn, expectLocation} from '../../util/asserts';
import {pressKeys} from '../../util/actions';
import {screenshot} from '../../screenshot';

describe('menu', () => {
const menuSelector = '.mat-menu-panel';
Expand All @@ -15,28 +16,33 @@ describe('menu', () => {

expectToExist(menuSelector);
expect(page.menu().getText()).toEqual('One\nTwo\nThree\nFour');
screenshot('');
});

it('should close menu when menu item is clicked', () => {
page.trigger().click();
page.items(0).click();
expectToExist(menuSelector, false);
screenshot('');
});

it('should run click handlers on regular menu items', () => {
page.trigger().click();
page.items(0).click();
expect(page.getResultText()).toEqual('one');
screenshot('one');

page.trigger().click();
page.items(1).click();
expect(page.getResultText()).toEqual('two');
screenshot('two');
});

it('should run not run click handlers on disabled menu items', () => {
page.trigger().click();
page.items(2).click();
expect(page.getResultText()).toEqual('');
screenshot('');
});

it('should support multiple triggers opening the same menu', () => {
Expand Down
17 changes: 15 additions & 2 deletions e2e/components/radio/radio.e2e.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {browser, by, element} from 'protractor';
import {browser, by, element, ExpectedConditions} from 'protractor';
import {screenshot} from '../../screenshot';

describe('radio', () => {
describe('disabling behavior', () => {
Expand All @@ -8,6 +9,9 @@ describe('radio', () => {
element(by.id('water')).click();
element(by.id('water')).getAttribute('class').then((value: string) => {
expect(value).toContain('mat-radio-checked');
browser.wait(ExpectedConditions.not(
ExpectedConditions.presenceOf(element(by.css('div.mat-ripple-element')))))
.then(() => screenshot('water'));
});
element(by.css('input[id=water-input]')).getAttribute('checked').then((value: string) => {
expect(value).toBeTruthy();
Expand All @@ -19,6 +23,9 @@ describe('radio', () => {
element(by.id('leaf')).click();
element(by.id('leaf')).getAttribute('class').then((value: string) => {
expect(value).toContain('mat-radio-checked');
browser.wait(ExpectedConditions.not(
ExpectedConditions.presenceOf(element(by.css('div.mat-ripple-element')))))
.then(() => screenshot('leaf'));
});
element(by.css('input[id=leaf-input]')).getAttribute('checked').then((value: string) => {
expect(value).toBeTruthy();
Expand All @@ -33,14 +40,20 @@ describe('radio', () => {
element(by.id('water')).click();
element(by.id('water')).getAttribute('class').then((value: string) => {
expect(value).toContain('mat-radio-disabled');
browser.wait(ExpectedConditions.not(
ExpectedConditions.presenceOf(element(by.css('div.mat-ripple-element')))))
.then(() => screenshot('water'));
});
element(by.css('input[id=water-input]')).getAttribute('disabled').then((value: string) => {
element(by.css('input[id=water-input]')).getAttribute('disabled').then((value: string) => {
expect(value).toBeTruthy();
});

element(by.id('leaf')).click();
element(by.id('leaf')).getAttribute('class').then((value: string) => {
expect(value).toContain('mat-radio-disabled');
browser.wait(ExpectedConditions.not(
ExpectedConditions.presenceOf(element(by.css('div.mat-ripple-element')))))
.then(() => screenshot('leaf'));
});
element(by.css('input[id=leaf-input]')).getAttribute('disabled').then((value: string) => {
expect(value).toBeTruthy();
Expand Down
6 changes: 6 additions & 0 deletions e2e/components/slide-toggle/slide-toggle.e2e.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {browser, element, by, Key} from 'protractor';
import {expectToExist} from '../../util/asserts';
import {screenshot} from '../../screenshot';

describe('slide-toggle', () => {
const getInput = () => element(by.css('#normal-slide-toggle input'));
Expand All @@ -9,6 +10,7 @@ describe('slide-toggle', () => {

it('should render a slide-toggle', () => {
expectToExist('md-slide-toggle');
screenshot('');
});

it('should change the checked state on click', () => {
Expand All @@ -19,6 +21,7 @@ describe('slide-toggle', () => {
getNormalToggle().click();

expect(inputEl.getAttribute('checked')).toBeTruthy('Expect slide-toggle to be checked');
screenshot('');
});

it('should change the checked state on click', () => {
Expand All @@ -29,6 +32,7 @@ describe('slide-toggle', () => {
getNormalToggle().click();

expect(inputEl.getAttribute('checked')).toBeTruthy('Expect slide-toggle to be checked');
screenshot('');
});

it('should not change the checked state on click when disabled', () => {
Expand All @@ -39,6 +43,7 @@ describe('slide-toggle', () => {
element(by.css('#disabled-slide-toggle')).click();

expect(inputEl.getAttribute('checked')).toBeFalsy('Expect slide-toggle to be unchecked');
screenshot('');
});

it('should move the thumb on state change', () => {
Expand All @@ -52,6 +57,7 @@ describe('slide-toggle', () => {
let newX = thumbEl.getLocation().then(pos => pos.x);

expect(previousX).not.toBe(newX);
screenshot('');
});

it('should toggle the slide-toggle on space key', () => {
Expand Down
9 changes: 8 additions & 1 deletion e2e/components/tabs/tabs.e2e.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {browser, by, element, ElementArrayFinder, ElementFinder, Key} from 'protractor';
import {browser, by, element, ElementArrayFinder, ElementFinder, Key, ExpectedConditions} from 'protractor';
import {pressKeys} from '../../util/actions';
import {screenshot} from '../../screenshot';

describe('tabs', () => {
describe('basic behavior', () => {
Expand All @@ -18,10 +19,16 @@ describe('tabs', () => {
tabLabels.get(1).click();
expect(getLabelActiveStates(tabLabels)).toEqual([false, true, false]);
expect(getBodyActiveStates(tabBodies)).toEqual([false, true, false]);
browser.wait(ExpectedConditions.not(
ExpectedConditions.presenceOf(element(by.css('div.mat-ripple-element')))))
.then(() => screenshot('click1'));

tabLabels.get(0).click();
expect(getLabelActiveStates(tabLabels)).toEqual([true, false, false]);
expect(getBodyActiveStates(tabBodies)).toEqual([true, false, false]);
browser.wait(ExpectedConditions.not(
ExpectedConditions.presenceOf(element(by.css('div.mat-ripple-element')))))
.then(() => screenshot('click0'));
});

it('should change focus with keyboard interaction', () => {
Expand Down

0 comments on commit 25a168d

Please sign in to comment.