Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions e2e/components/button/button.e2e.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
import {browser, by, element} from 'protractor';
import {screenshot} from '../../screenshot';


describe('button', function () {
describe('disabling behavior', function () {
beforeEach(function() {
browser.get('/button');
});

it('should prevent click handlers from executing when disabled', function () {
element(by.id('test-button')).click();
expect(element(by.id('click-counter')).getText()).toEqual('1');
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');
});
});
});
6 changes: 6 additions & 0 deletions e2e/components/checkbox/checkbox.e2e.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {browser, by, element, Key} from 'protractor';
import {screenshot} from '../../screenshot';

describe('checkbox', function () {

Expand All @@ -12,28 +13,33 @@ describe('checkbox', function () {
let checkboxEl = element(by.id('test-checkbox'));
let inputEl = element(by.css('input[id=input-test-checkbox]'));

screenshot('start');
checkboxEl.click();
inputEl.getAttribute('checked').then((value: string) => {
expect(value).toBeTruthy('Expect checkbox "checked" property to be true');
});
screenshot('checked');

checkboxEl.click();
inputEl.getAttribute('checked').then((value: string) => {
expect(value).toBeFalsy('Expect checkbox "checked" property to be false');
});
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');
});

inputEl.sendKeys(Key.SPACE);

inputEl.getAttribute('checked').then((value: string) => {
expect(value).toBeTruthy('Expect checkbox "checked" property to be true');
screenshot('pressed space');
});
});

Expand Down
54 changes: 54 additions & 0 deletions e2e/screenshot.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import * as fs from 'fs';
import * as gulp from 'gulp';
import * as path from 'path';
import {browser} from 'protractor';


function initializeEnvironment(jasmine: any) {
var reporter = new jasmine.JsApiReporter({});
reporter.specStarted = function(result: any) {
jasmine.getEnv().currentSpec = result.fullName;
Copy link
Member

@jelbourn jelbourn Jan 7, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of storing this to jasmine.getEnv(), would it work to create a variable at the file level and update that? E.g.,

let currentJasmineSpecName = '';

/**  Adds a custom jasmine reporter that simply keeps track of the current test name. */
function installJasmineReporter(jasmine: any) {
  jasmine.getEnv().addReporter(new jasmine.JsApiReporter({
    specStarted: (result: any) => {
      currentJasmineSpecName = result.fullName;
    }
  }));
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also just realized: we should make sure that the test results are still being reported normally with the custom report installed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to file-level variable.

Constructor JsApiReporter({specStarted}) is not working.

Tested the test results are being reported normally.

};
jasmine.getEnv().addReporter(reporter);
}

initializeEnvironment(jasmine);

export class Screenshot {
id: string;
dir: string = '/tmp/angular-material2-build/screenshots/';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make this a file-level constant, e.g.,

/** Directory into which screenshots will be written. */
const OUTPUT_DIR = '/tmp/angular-material2-build/screenshots/';


/** The filename used to store the screenshot. */
get filename(): string {
return this.id
.toLowerCase()
.replace(/\s/g, '_')
.replace(/[^/a-z0-9_]+/g, '')
+ '.screenshot.png';
}

/** The full path to the screenshot */
get fullPath(): string {
return path.resolve(this.dir, this.filename);
}

constructor(id: string) {
this.id = `${jasmine.getEnv().currentSpec} ${id}`;
browser.takeScreenshot().then(png => this.storeScreenshot(png));
}

/** Replaces the existing screenshot with the newly generated one. */
storeScreenshot(png: any) {
if (!fs.existsSync(this.dir)) {
fs.mkdirSync(this.dir, '744');
}

if (fs.existsSync(this.dir)) {
fs.writeFileSync(this.fullPath, png, {encoding: 'base64' });
}
}
}

export function screenshot(id: string) {
return new Screenshot(id);
}