-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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
Conversation
There was a problem hiding this 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, '_') |
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
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 = |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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'}); |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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?
eb60e39
to
2b4e66d
Compare
6b45e60
to
a48c356
Compare
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/'; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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;
}
}));
}
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
53135ce
to
1670ee4
Compare
c312aa6
to
268c55a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@jelbourn @tinayuangao I just have some questions:
|
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
R: @jelbourn