File tree Expand file tree Collapse file tree 3 files changed +75
-0
lines changed Expand file tree Collapse file tree 3 files changed +75
-0
lines changed Original file line number Diff line number Diff line change 1+ const { smartuiSnapshot } = require ( './src/smartui' ) ;
2+
3+ module . exports = {
4+ smartuiSnapshot
5+ }
Original file line number Diff line number Diff line change 1+ {
2+ "name" : " @lambdatest/puppeteer-driver" ,
3+ "version" : " 1.0.0" ,
4+ "description" : " Puppeteer SDK for smart UI" ,
5+ "main" : " index.js" ,
6+ "scripts" : {
7+ "test" : " echo \" Error: no test specified\" && exit 1"
8+ },
9+ "repository" : {
10+ "type" : " git" ,
11+ "url" : " git+https://github.com/LambdaTest/lambdatest-js-sdk.git" ,
12+ "directory" : " packages/puppeteer"
13+ },
14+ "keywords" : [
15+ " lambdatest" ,
16+ " puppeteer" ,
17+ " smartui"
18+ ],
19+ "author" :
" LambdaTest <[email protected] >" ,
20+ "license" : " MIT" ,
21+ "bugs" : {
22+ "url" : " https://github.com/LambdaTest/lambdatest-js-sdk/issues"
23+ },
24+ "homepage" : " https://github.com/LambdaTest/lambdatest-js-sdk#readme" ,
25+ "dependencies" : {
26+ "@lambdatest/sdk-utils" : " workspace:^"
27+ }
28+ }
Original file line number Diff line number Diff line change 1+ const utils = require ( '@lambdatest/sdk-utils' ) ;
2+ const pkgName = require ( '../package.json' ) . name ;
3+
4+
5+ async function smartuiSnapshot ( page , name , options = { } ) {
6+ if ( ! page ) throw new Error ( 'puppeteer `page` argument is required.' ) ;
7+ if ( ! name ) throw new Error ( 'The `name` argument is required.' ) ;
8+ if ( ! ( await utils . isSmartUIRunning ( ) ) ) throw new Error ( 'SmartUI server is not running.' ) ;
9+
10+ let log = utils . logger ( pkgName ) ;
11+
12+ try {
13+ // Fetch the DOM serializer from the SmartUI server.
14+ let resp = await utils . fetchDOMSerializer ( ) ;
15+
16+ // Inject the DOM serializer into the page.
17+ await page . evaluate ( resp . body . data . dom ) ;
18+
19+ // Serialize the DOM
20+ let { dom, url } = await page . evaluate ( options => ( {
21+ dom : SmartUIDOM . serialize ( options ) ,
22+ url : document . URL
23+ } ) , { } ) ;
24+
25+
26+ // Post it to the SmartUI server.
27+ await utils . postSnapshot ( {
28+ dom : dom . html ,
29+ url,
30+ name,
31+ options
32+ } , pkgName ) ;
33+
34+ log . info ( `Snapshot captured: ${ name } ` ) ;
35+ } catch ( error ) {
36+ throw new Error ( error ) ;
37+ }
38+ }
39+
40+ module . exports = {
41+ smartuiSnapshot
42+ } ;
You can’t perform that action at this time.
0 commit comments