@@ -330,10 +330,300 @@ Create the SmartUI configuration file using:
330330npx smartui config:create smartui-web.json
331331```
332332
333+ ## Best Practices
334+
335+ ### Screenshot Naming
336+
337+ - Use descriptive, unique names for each screenshot
338+ - Include page/component name and state (e.g., ` homepage-logged-in ` , ` checkout-step-2 ` )
339+ - Avoid special characters that might cause issues in URLs
340+ - Use consistent naming conventions across your test suite
341+
342+ ### When to Take Screenshots
343+
344+ - ** Critical user flows** : Login, checkout, payment
345+ - ** Dynamic content** : After user interactions, form submissions
346+ - ** Responsive breakpoints** : Different viewport sizes
347+ - ** State changes** : Before and after important actions
348+
349+ ### Performance Optimization
350+
351+ - Take screenshots only when necessary (not on every page load)
352+ - Use ` waitForPageRender ` in ` smartui-web.json ` for slow-loading pages
353+ - Consider viewport-specific screenshots instead of full-page when possible
354+ - Use ignore options to reduce false positives from dynamic content
355+
356+ ### Error Handling
357+
358+ ``` javascript
359+ try {
360+ await driver .get (' https://www.lambdatest.com' );
361+ await smartuiSnapshot (driver, " homepage" );
362+ } catch (error) {
363+ console .error (' Screenshot failed:' , error);
364+ // Handle error appropriately
365+ throw error;
366+ } finally {
367+ await driver .quit ();
368+ }
369+ ```
370+
371+ ## Common Use Cases
372+
373+ ### Multiple Screenshots in Sequence
374+
375+ ``` javascript
376+ await driver .get (' https://www.lambdatest.com' );
377+ await smartuiSnapshot (driver, " homepage" );
378+
379+ await driver .findElement (By .linkText (' Pricing' )).click ();
380+ await smartuiSnapshot (driver, " pricing-page" );
381+
382+ await driver .findElement (By .linkText (' Documentation' )).click ();
383+ await smartuiSnapshot (driver, " documentation-page" );
384+ ```
385+
386+ ### Screenshot After User Interaction
387+
388+ ``` javascript
389+ await driver .get (' https://www.lambdatest.com' );
390+
391+ // Wait for element and interact
392+ const searchBox = await driver .findElement (By .id (' search' ));
393+ await searchBox .sendKeys (' Selenium' );
394+ await searchBox .sendKeys (Key .RETURN );
395+
396+ // Wait for results to load
397+ await driver .wait (until .elementLocated (By .className (' results' )), 10000 );
398+
399+ // Take screenshot after interaction
400+ await smartuiSnapshot (driver, " search-results" );
401+ ```
402+
403+ ### Conditional Screenshots
404+
405+ ``` javascript
406+ const isLoggedIn = await driver .findElements (By .className (' user-menu' )).length > 0 ;
407+
408+ if (isLoggedIn) {
409+ await smartuiSnapshot (driver, " homepage-logged-in" );
410+ } else {
411+ await smartuiSnapshot (driver, " homepage-guest" );
412+ }
413+ ```
414+
415+ ## CI/CD Integration
416+
417+ ### GitHub Actions Example
418+
419+ ``` yaml
420+ name : SmartUI Visual Tests
421+
422+ on :
423+ push :
424+ branches : [ main ]
425+ pull_request :
426+ branches : [ main ]
427+
428+ jobs :
429+ visual-tests :
430+ runs-on : ubuntu-latest
431+ steps :
432+ - uses : actions/checkout@v3
433+
434+ - name : Setup Node.js
435+ uses : actions/setup-node@v3
436+ with :
437+ node-version : ' 18'
438+
439+ - name : Install dependencies
440+ run : |
441+ cd sdk
442+ npm ci
443+
444+ - name : Run SmartUI tests
445+ env :
446+ PROJECT_TOKEN : ${{ secrets.SMARTUI_PROJECT_TOKEN }}
447+ LT_USERNAME : ${{ secrets.LT_USERNAME }}
448+ LT_ACCESS_KEY : ${{ secrets.LT_ACCESS_KEY }}
449+ run : |
450+ cd sdk
451+ npx smartui exec node sdkCloud.js
452+ ```
453+
454+ ### Jenkins Pipeline Example
455+
456+ ``` groovy
457+ pipeline {
458+ agent any
459+
460+ environment {
461+ PROJECT_TOKEN = credentials('smartui-project-token')
462+ LT_USERNAME = credentials('lambdatest-username')
463+ LT_ACCESS_KEY = credentials('lambdatest-access-key')
464+ }
465+
466+ stages {
467+ stage('Install Dependencies') {
468+ steps {
469+ sh 'cd sdk && npm ci'
470+ }
471+ }
472+
473+ stage('Run Visual Tests') {
474+ steps {
475+ sh 'cd sdk && npx smartui exec node sdkCloud.js'
476+ }
477+ }
478+ }
479+ }
480+ ```
481+
482+ ## Troubleshooting
483+
484+ ### Issue: ` Error: SmartUI Config already exists: smartui-web.json `
485+
486+ ** Solution** : This is informational. The config file already exists. You can:
487+ - Use the existing config file
488+ - Delete it and create a new one: ` rm smartui-web.json && npx smartui config:create smartui-web.json `
489+ - Use a different config file: ` npx smartui --config custom-config.json exec ... `
490+
491+ ### Issue: ` PROJECT_TOKEN is required `
492+
493+ ** Solution** : Ensure the ` PROJECT_TOKEN ` environment variable is set:
494+ ``` bash
495+ export PROJECT_TOKEN=' your_project_token'
496+ # Verify it's set
497+ echo $PROJECT_TOKEN
498+ ```
499+
500+ ### Issue: ` Unauthorized, either Username or AccessKey is invalid ` (Cloud)
501+
502+ ** Solution** :
503+ 1 . Verify your credentials are set correctly:
504+ ``` bash
505+ echo $LT_USERNAME
506+ echo $LT_ACCESS_KEY
507+ ```
508+ 2 . Check your credentials in [ LambdaTest Profile Settings] ( https://accounts.lambdatest.com/profile )
509+ 3 . Ensure there are no extra spaces or quotes in the environment variables
510+
511+ ### Issue: ` Cannot find module '@lambdatest/selenium-driver' `
512+
513+ ** Solution** : Install dependencies:
514+ ``` bash
515+ cd sdk
516+ npm install @lambdatest/smartui-cli @lambdatest/selenium-driver selenium-webdriver
517+ ```
518+
519+ ### Issue: Screenshots not appearing in SmartUI Dashboard
520+
521+ ** Solution** :
522+ 1 . Verify the ` PROJECT_TOKEN ` matches your SmartUI project
523+ 2 . Check that the build completed successfully (no errors in terminal)
524+ 3 . Wait a few moments for screenshots to process
525+ 4 . Verify you're looking at the correct project in the dashboard
526+
527+ ### Issue: ` ChromeDriver version mismatch ` (Local)
528+
529+ ** Solution** :
530+ 1 . Update ChromeDriver: ` npm install --save-dev chromedriver `
531+ 2 . Or use WebDriver Manager: ` npm install --save-dev webdriver-manager `
532+ 3 . Ensure Chrome browser is up to date
533+
534+ ### Issue: Timeout errors when taking screenshots
535+
536+ ** Solution** :
537+ 1 . Increase ` waitForPageRender ` in ` smartui-web.json ` :
538+ ``` json
539+ {
540+ "web" : {
541+ "waitForPageRender" : 60000
542+ }
543+ }
544+ ```
545+ 2 . Add explicit waits before taking screenshots:
546+ ``` javascript
547+ await driver .wait (until .elementLocated (By .id (' main-content' )), 10000 );
548+ await smartuiSnapshot (driver, " screenshot" );
549+ ```
550+
551+ ### Issue: False positives in visual comparisons
552+
553+ ** Solution** :
554+ 1 . Use ignore options for dynamic content (ads, timestamps, etc.)
555+ 2 . Increase ` waitForTimeout ` in ` smartui-web.json ` for lazy-loaded content
556+ 3 . Use viewport-specific screenshots instead of full-page when appropriate
557+ 4 . Review and update baseline screenshots when intentional changes are made
558+
559+ ## Configuration Tips
560+
561+ ### Optimizing ` smartui-web.json `
562+
563+ ``` json
564+ {
565+ "web" : {
566+ "browsers" : [" chrome" , " firefox" ],
567+ "viewports" : [
568+ [1920 , 1080 ],
569+ [1366 , 768 ],
570+ [360 , 640 ]
571+ ],
572+ "waitForPageRender" : 30000 ,
573+ "waitForTimeout" : 2000
574+ }
575+ }
576+ ```
577+
578+ ** Tips** :
579+ - Start with fewer browsers/viewports for faster initial testing
580+ - Adjust ` waitForPageRender ` based on your page load times
581+ - Use ` waitForTimeout ` for async components (lazy-loaded images, animations)
582+
583+ ### Environment-Specific Configuration
584+
585+ Create different config files for different environments:
586+
587+ ``` bash
588+ # Development
589+ npx smartui --config smartui-dev.json exec node sdkLocal.js
590+
591+ # Staging
592+ npx smartui --config smartui-staging.json exec node sdkCloud.js
593+
594+ # Production
595+ npx smartui --config smartui-prod.json exec node sdkCloud.js
596+ ```
597+
333598## View Results
334599
335600After running the tests, visit your SmartUI project dashboard to view the captured screenshots and compare them with baseline builds.
336601
337- ## More Information
602+ ### Understanding Results
603+
604+ - ** Baseline Created** : First run creates baseline screenshots
605+ - ** Passed** : Screenshot matches baseline (no visual differences)
606+ - ** Failed** : Visual differences detected
607+ - ** Review Required** : Manual review needed for differences
608+
609+ ### Managing Baselines
610+
611+ - Update baseline when intentional UI changes are made
612+ - Review failed comparisons to identify false positives
613+ - Use ignore options to exclude known dynamic content
614+
615+ ## Additional Resources
616+
617+ - [ SmartUI Selenium JavaScript Onboarding Guide] ( https://www.lambdatest.com/support/docs/smartui-onboarding-selenium-js/ )
618+ - [ LambdaTest Selenium Documentation] ( https://www.lambdatest.com/support/docs/selenium-automation/ )
619+ - [ SmartUI Dashboard] ( https://smartui.lambdatest.com/ )
620+ - [ LambdaTest Automation Dashboard] ( https://automation.lambdatest.com/ )
621+ - [ LambdaTest Community] ( https://community.lambdatest.com/ )
622+ - [ LambdaTest Blog] ( https://www.lambdatest.com/blog/ )
623+
624+ ## Support
338625
339- For detailed onboarding instructions, see the [ SmartUI Selenium JavaScript Onboarding Guide] ( https://www.lambdatest.com/support/docs/smartui-onboarding-selenium-js/ ) .
626+ For additional help:
627+ - [ LambdaTest Support] ( https://www.lambdatest.com/support/ )
628+ - [ Documentation] ( https://www.lambdatest.com/support/docs/ )
629+ - [ 24/7 Chat Support] ( https://www.lambdatest.com/ )
0 commit comments