Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(screenshot): Add screenshot function to e2e test (button and checkbox) #2532

Merged
merged 3 commits into from
Jan 12, 2017

Conversation

tinayuangao
Copy link
Contributor

@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Jan 5, 2017
Copy link
Member

@jelbourn jelbourn left a comment

Choose a reason for hiding this comment

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

Did you determine whether writing / reading these files works on SauceLabs?

get filename() {
return this.id
.toLowerCase()
.replace(/[ :\/]/g, '_')
Copy link
Member

Choose a reason for hiding this comment

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

Can change the space to \s to capture all whitespace.

* The filename used to store the screenshot
* @returns {string}
*/
get filename() {
Copy link
Member

Choose a reason for hiding this comment

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

Can do get filename(): string and remove the type from the JsDoc
(here and elsewhere for return types and params)

* The full path to the screenshot
* @returns {string}
*/
get path() {
Copy link
Member

Choose a reason for hiding this comment

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

Let's call this fullPath


describe('button', function () {
describe('disabling behavior', function () {
beforeEach(function() {
browser.get('/button');
});
it('should prevent click handlers from executing when disabled', function () {
let testname =
Copy link
Member

Choose a reason for hiding this comment

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

Jasmine 2.0 made it more difficult to get the current test name, but it's still possible by adding a custom reporter. Example.

Could could add a reporter that just updates a value which is then read in screenshot.ts

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a reporter and we can use the test name in Screenshot now

if (!fs.existsSync(dir)) {
fs.mkdirSync(dir, 0o744);
}
fs.writeFileSync(this.path, png, {encoding: 'base64'});
Copy link
Member

Choose a reason for hiding this comment

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

Why base64 encoding? Shouldn't this be binary?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The output of binary cannot be opened as an image.

storeScreenshot(png: any) {
var dir = path.resolve(__dirname, '..', 'screenshots');
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir, 0o744);
Copy link
Member

Choose a reason for hiding this comment

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

Why octal instead of hexadecimal?

@tinayuangao tinayuangao force-pushed the screenshot-pr branch 6 times, most recently from eb60e39 to 2b4e66d Compare January 6, 2017 22:02
@tinayuangao tinayuangao changed the title Add screenshot function to e2e test (button and checkbox) feat(screenshot): Add screenshot function to e2e test (button and checkbox) Jan 6, 2017
@tinayuangao
Copy link
Contributor Author

Fixed test on travis-ci and sauce labs. Please take another look. Thanks!


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/';

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.

@tinayuangao tinayuangao force-pushed the screenshot-pr branch 2 times, most recently from 53135ce to 1670ee4 Compare January 7, 2017 00:48
Copy link
Member

@jelbourn jelbourn left a comment

Choose a reason for hiding this comment

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

LGTM

@jelbourn jelbourn added pr: lgtm action: merge The PR is ready for merge by the caretaker labels Jan 11, 2017
@tinayuangao tinayuangao merged commit 8ba8deb into angular:master Jan 12, 2017
@devversion
Copy link
Member

@jelbourn @tinayuangao I just have some questions:

  • How would you look at the screenshots in the CI?
  • Is this the base for screenshot-diffs or is it just to look at errors in E2E tests?

    (Asking because Saucelabs can already do screenshots)

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes PR author has agreed to Google's Contributor License Agreement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants