Skip to content

Commit

Permalink
Taking screenshots in Electron and Chrome (#97)
Browse files Browse the repository at this point in the history
* adding example

* report image sizes after the test

* capture more images

* add badge to README

* try 1280,1024 chrome size
  • Loading branch information
bahmutov authored Feb 19, 2020
1 parent cc5cc55 commit 50a1dff
Show file tree
Hide file tree
Showing 10 changed files with 1,900 additions and 19 deletions.
17 changes: 0 additions & 17 deletions .github/workflows/example-basic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,6 @@ jobs:
with:
working-directory: examples/basic

# store screenshot captured during the test
- uses: actions/upload-artifact@v1
with:
name: screenshots-in-electron
path: examples/basic/cypress/screenshots

- name: Chrome
uses: ./
with:
working-directory: examples/basic
browser: chrome

- uses: actions/upload-artifact@v1
with:
name: screenshots-in-chrome
path: examples/basic/cypress/screenshots

basic-on-windows:
runs-on: windows-latest
steps:
Expand Down
51 changes: 51 additions & 0 deletions .github/workflows/example-chrome.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: example-chrome
on: [push]
jobs:
tests:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v1

- name: Electron
uses: ./
with:
working-directory: examples/chrome

# store screenshot captured during the test
- uses: actions/upload-artifact@v1
with:
name: screenshots-in-electron
path: examples/chrome/cypress/screenshots

- run: npx image-size cypress/screenshots/**/*.png
working-directory: examples/chrome

- name: Chrome
uses: ./
with:
working-directory: examples/chrome
browser: chrome

- uses: actions/upload-artifact@v1
with:
name: screenshots-in-chrome
path: examples/chrome/cypress/screenshots

- run: npx image-size cypress/screenshots/**/*.png
working-directory: examples/chrome

- name: Chrome headless
uses: ./
with:
working-directory: examples/chrome
browser: chrome
headless: true

- uses: actions/upload-artifact@v1
with:
name: screenshots-in-headless-chrome
path: examples/chrome/cypress/screenshots

- run: npx image-size cypress/screenshots/**/*.png
working-directory: examples/chrome
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules/
cypress/videos/
examples/env/cypress/videos/
examples/*/cypress/videos
examples/*/cypress/screenshots
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ jobs:
browser: chrome
```

[![Chrome example](https://github.com/cypress-io/github-action/workflows/example-chrome/badge.svg?branch=master)](.github/workflows/example-chrome.yml)

### Headless

Run the browser in headless mode
Expand Down
1 change: 0 additions & 1 deletion examples/basic/cypress/integration/spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
it('works', () => {
expect(42).to.equal(21 + 21)
cy.visit('https://example.cypress.io')
cy.screenshot('example', { capture: 'runner' })
})
4 changes: 4 additions & 0 deletions examples/chrome/cypress.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"fixturesFolder": false,
"supportFile": false
}
12 changes: 12 additions & 0 deletions examples/chrome/cypress/integration/spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
it('works', () => {
expect(42).to.equal(21 + 21)
cy.visit('https://example.cypress.io')
// runner includes the application in the viewport
// and the reporter showing the command log
cy.screenshot('runner', { capture: 'runner' })
// just the visible portion of the viewport
cy.screenshot('viewport', { capture: 'viewport' })
// you can take the screenshot of the entire page
// which will be stitched into one tall image
cy.screenshot('fullPage', { capture: 'fullPage' })
})
16 changes: 16 additions & 0 deletions examples/chrome/cypress/plugins/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const os = require('os')
module.exports = on => {
on('before:browser:launch', (browser, launchOptions) => {
console.log('before launching browser')
console.log(browser)

if (browser.name === 'chrome') {
// https://www.ghacks.net/2013/10/06/list-useful-google-chrome-command-line-switches/
launchOptions.args.push('--window-size=1280,1024')

console.log('chrome launch args:')
console.log(launchOptions.args.join(os.EOL))
return launchOptions
}
})
}
Loading

0 comments on commit 50a1dff

Please sign in to comment.