|
| 1 | +--- |
| 2 | +id: smartui-cli-basic-auth |
| 3 | +title: Basic Authentication in SmartUI CLI |
| 4 | +sidebar_label: Capturing assets protected with authentication |
| 5 | +description: Learn how to capture screenshots of assets protected behind authentication using SmartUI CLI |
| 6 | +keywords: |
| 7 | + - Visual Regression |
| 8 | + - SmartUI SDK |
| 9 | + - Basic Authentication |
| 10 | + - Protected Assets |
| 11 | + - Authentication Headers |
| 12 | +url: https://www.lambdatest.com/support/docs/smartui-basic-auth/ |
| 13 | +slug: smartui-cli-basic-auth/ |
| 14 | +--- |
| 15 | + |
| 16 | +import Tabs from '@theme/Tabs'; |
| 17 | +import TabItem from '@theme/TabItem'; |
| 18 | +import NewTag from '../src/component/newTag'; |
| 19 | + |
| 20 | +--- |
| 21 | +<script type="application/ld+json" |
| 22 | + dangerouslySetInnerHTML={{ __html: JSON.stringify({ |
| 23 | + "@context": "https://schema.org", |
| 24 | + "@type": "BreadcrumbList", |
| 25 | + "itemListElement": [{ |
| 26 | + "@type": "ListItem", |
| 27 | + "position": 1, |
| 28 | + "name": "LambdaTest", |
| 29 | + "item": "https://www.lambdatest.com" |
| 30 | + },{ |
| 31 | + "@type": "ListItem", |
| 32 | + "position": 2, |
| 33 | + "name": "Support", |
| 34 | + "item": "https://www.lambdatest.com/support/docs/" |
| 35 | + },{ |
| 36 | + "@type": "ListItem", |
| 37 | + "position": 3, |
| 38 | + "name": "Smart Visual Testing", |
| 39 | + "item": "https://www.lambdatest.com/support/docs/smart-ui-cypress/" |
| 40 | + }] |
| 41 | + }) |
| 42 | + }} |
| 43 | +></script> |
| 44 | + |
| 45 | + |
| 46 | +When capturing screenshots of applications or websites that are protected with authentication, you need to configure SmartUI to pass the necessary authentication headers. This ensures that SmartUI can access and properly render all assets on the page. |
| 47 | + |
| 48 | +## Why Basic Authentication is Needed |
| 49 | + |
| 50 | +Without proper authentication configuration: |
| 51 | +- Protected assets may fail to load |
| 52 | +- Screenshots might be incomplete or broken |
| 53 | +- CSS and other resources behind authentication may not be accessible |
| 54 | + |
| 55 | +## Configuration |
| 56 | + |
| 57 | +Add the following configuration to your `.smartui.json` file to enable basic authentication: |
| 58 | + |
| 59 | +```json |
| 60 | +{ |
| 61 | + "basicAuthorization": { |
| 62 | + "username": "username", |
| 63 | + "password": "password" |
| 64 | + } |
| 65 | +} |
| 66 | +``` |
| 67 | + |
| 68 | +### Configuration Parameters |
| 69 | + |
| 70 | +- **username**: Your authentication username |
| 71 | +- **password**: Your authentication password |
| 72 | + |
| 73 | +## Example Usage |
| 74 | + |
| 75 | +Here's a complete example of a SmartUI configuration file with basic authentication: |
| 76 | + |
| 77 | +```json |
| 78 | +{ |
| 79 | + "web": { |
| 80 | + "browsers": ["chrome", "firefox"], |
| 81 | + "viewports": [ |
| 82 | + [1920, 1080], |
| 83 | + [1366, 768] |
| 84 | + ] |
| 85 | + }, |
| 86 | + "basicAuthorization": { |
| 87 | + "username": "your-username", |
| 88 | + "password": "your-password" |
| 89 | + }, |
| 90 | + "waitForTimeout": 1000 |
| 91 | +} |
| 92 | +``` |
| 93 | + |
| 94 | +## Using Environment Variables |
| 95 | + |
| 96 | +For better security, you can use environment variables for your authentication credentials: |
| 97 | + |
| 98 | +```json |
| 99 | +{ |
| 100 | + "basicAuthorization": { |
| 101 | + "username": "${AUTH_USERNAME}", |
| 102 | + "password": "${AUTH_PASSWORD}" |
| 103 | + } |
| 104 | +} |
| 105 | +``` |
| 106 | + |
| 107 | +Then set your environment variables: |
| 108 | + |
| 109 | +<Tabs className="docs__val" groupId="language"> |
| 110 | +<TabItem value="MacOS/Linux" label="MacOS/Linux" default> |
| 111 | + |
| 112 | +```bash |
| 113 | +export AUTH_USERNAME="your-username" |
| 114 | +export AUTH_PASSWORD="your-password" |
| 115 | +``` |
| 116 | +</TabItem> |
| 117 | +<TabItem value="Windows" label="Windows" default> |
| 118 | + |
| 119 | +```bash |
| 120 | +set AUTH_USERNAME="your-username" |
| 121 | +set AUTH_PASSWORD="your-password" |
| 122 | +``` |
| 123 | +</TabItem> |
| 124 | +</Tabs> |
| 125 | + |
| 126 | +## Common Issues and Solutions |
| 127 | + |
| 128 | +1. **Assets Not Loading** |
| 129 | + - Verify that the provided credentials have access to all required resources |
| 130 | + - Check if any assets are served from different domains requiring separate authentication |
| 131 | + |
| 132 | +2. **Authentication Failures** |
| 133 | + - Ensure credentials are correct and active |
| 134 | + - Verify that the authentication endpoint is accessible from LambdaTest's infrastructure |
| 135 | + |
| 136 | +:::tip |
| 137 | +When using basic authentication: |
| 138 | +1. Test your credentials manually before running SmartUI tests |
| 139 | +2. Ensure all required assets are accessible with the provided credentials |
| 140 | +3. Use secure methods to manage your authentication credentials |
| 141 | +4. Consider implementing a test user specifically for visual testing |
| 142 | +::: |
0 commit comments