-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Show how to get the current page's HTML source (#711)
* add new recipe showing how to get the current page * add new recipe to circle * add new recipe to the README file
- Loading branch information
Showing
7 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Page source | ||
> Get the source of the page under test | ||
 | ||
|
||
You can get the current document's HTML using `document.documentElement.outerHTML` property. Then you can validate / sanitize the HTML. You can even write it back as text into the current browser to see it, as [spec.js](./cypress/integration/spec.js) shows. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"fixturesFolder": false, | ||
"supportFile": false, | ||
"pluginsFile": false, | ||
"baseUrl": "https://www.cypress.io/" | ||
} |
17 changes: 17 additions & 0 deletions
17
examples/testing-dom__page-source/cypress/integration/spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/// <reference types="cypress" /> | ||
|
||
describe('Page source', () => { | ||
it('gets the currently loaded document HTML', () => { | ||
cy.visit('/') | ||
cy.document().its('documentElement.outerHTML') | ||
.should('be.a', 'string') | ||
// let's show the HTML as text right in the browser | ||
// we need to sanitize the "<", ">", "&" characters | ||
.invoke('replace', /&/g, '&') | ||
.invoke('replace', /</g, '<') | ||
.invoke('replace', />/g, '>') | ||
.then((sanitized) => { | ||
cy.document().invoke('write', sanitized) | ||
}) | ||
}) | ||
}) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"name": "page-source", | ||
"version": "1.0.0", | ||
"description": "Get the source of the page under test", | ||
"private": true, | ||
"scripts": { | ||
"cypress:open": "../../node_modules/.bin/cypress open", | ||
"cypress:run": "../../node_modules/.bin/cypress run", | ||
"start": "echo nothing to start", | ||
"test:ci": "npm run cypress:run" | ||
} | ||
} |