|
| 1 | +--- |
| 2 | +id: smartui-layout-testing |
| 3 | +title: Layout Comparison in SmartUI SDK |
| 4 | +sidebar_label: Layout Testing |
| 5 | +description: Learn how to use SmartUI SDK's layout testing feature to verify only the layout structure of your pages while ignoring content and style changes |
| 6 | +keywords: |
| 7 | + - layout comparison |
| 8 | + - visual regression testing |
| 9 | + - ignore layout differences |
| 10 | + - smartui sdk |
| 11 | + - visual testing |
| 12 | + - layout structure |
| 13 | + - element positions |
| 14 | + - layout testing |
| 15 | +url: https://www.lambdatest.com/support/docs/smartui-layout-comparison/ |
| 16 | +site_name: LambdaTest |
| 17 | +slug: smartui-layout-testing/ |
| 18 | +--- |
| 19 | + |
| 20 | +# Layout Comparison in SmartUI SDK |
| 21 | + |
| 22 | +The layout comparison feature in SmartUI SDK allows you to verify only the layout structure of your pages while ignoring content and style changes. This is particularly useful for frontend developers who need to ensure that the structural integrity of their UI remains consistent across different versions or environments. |
| 23 | + |
| 24 | +## How to Use Layout Comparison |
| 25 | + |
| 26 | +To use the layout comparison feature, you need to set the `ignoreType` option to `"layout"` when taking a screenshot: |
| 27 | + |
| 28 | +import Tabs from '@theme/Tabs'; |
| 29 | +import TabItem from '@theme/TabItem'; |
| 30 | + |
| 31 | +<Tabs> |
| 32 | + <TabItem value="javascript" label="JavaScript" default> |
| 33 | + ```javascript |
| 34 | + // Set options to focus only on layout structure |
| 35 | + let options = { |
| 36 | + ignoreType: "layout" |
| 37 | + }; |
| 38 | + |
| 39 | + // Take a screenshot with layout comparison enabled |
| 40 | + await smartuiSnapshot(driver, "ScreenshotName", options); |
| 41 | + ``` |
| 42 | + </TabItem> |
| 43 | + <TabItem value="java" label="Java"> |
| 44 | + ```java |
| 45 | + // Set options to focus only on layout structure |
| 46 | + SmartUIOptions options = new SmartUIOptions(); |
| 47 | + options.IgnoreType("layout"); |
| 48 | + |
| 49 | + // Take a screenshot with layout comparison enabled |
| 50 | + smartuiSnapshot(driver, "ScreenshotName", options); |
| 51 | + ``` |
| 52 | + </TabItem> |
| 53 | + <TabItem value="python" label="Python"> |
| 54 | + ```python |
| 55 | + # Set options to focus only on layout structure |
| 56 | + options = { |
| 57 | + "ignoreType": "layout" |
| 58 | + } |
| 59 | + |
| 60 | + # Take a screenshot with layout comparison enabled |
| 61 | + smartui_snapshot(driver, "ScreenshotName", options) |
| 62 | + ``` |
| 63 | + </TabItem> |
| 64 | + <TabItem value="csharp" label="C#"> |
| 65 | + ```csharp |
| 66 | + // Set options to focus only on layout structure |
| 67 | + var options = new SmartUIOptions |
| 68 | + { |
| 69 | + IgnoreType = "layout" |
| 70 | + }; |
| 71 | + |
| 72 | + // Take a screenshot with layout comparison enabled |
| 73 | + await SmartUI.Snapshot(driver, "ScreenshotName", options); |
| 74 | + ``` |
| 75 | + </TabItem> |
| 76 | + <TabItem value="ruby" label="Ruby"> |
| 77 | + ```ruby |
| 78 | + # Set options to focus only on layout structure |
| 79 | + options = { |
| 80 | + ignoreType: "layout" |
| 81 | + } |
| 82 | + |
| 83 | + # Take a screenshot with layout comparison enabled |
| 84 | + smartui_snapshot(driver, "ScreenshotName", options) |
| 85 | + ``` |
| 86 | + </TabItem> |
| 87 | +</Tabs> |
| 88 | + |
| 89 | +This configuration tells SmartUI to focus only on the layout structure while comparing screenshots, ignoring content and style changes. |
| 90 | + |
| 91 | +## What Layout Comparison Verifies |
| 92 | + |
| 93 | +The layout comparison feature specifically focuses on: |
| 94 | + |
| 95 | +1. **Element Positions**: The relative positioning of elements compared to their siblings |
| 96 | +2. **Parent-Child Relationships**: The hierarchical structure of elements in the DOM |
| 97 | +3. **Basic Structural Hierarchy**: The overall layout structure of the page |
| 98 | + |
| 99 | +## What Layout Comparison Ignores |
| 100 | + |
| 101 | +When using layout comparison, the following aspects are ignored: |
| 102 | + |
| 103 | +1. **Text Content**: Changes in text content are not considered in the comparison |
| 104 | +2. **Color Values**: Differences in color schemes or individual color values are ignored |
| 105 | +3. **Style Properties**: Changes in CSS properties like font size, padding, margins, etc. are not compared |
| 106 | +4. **Image Content**: Differences in image content are ignored, only their position and size are considered |
| 107 | + |
| 108 | +## Content vs. Layout Diffs |
| 109 | + |
| 110 | +Understanding the difference between content and layout is crucial for effective visual testing: |
| 111 | + |
| 112 | +- **Content** refers to the actual information that users interact with on a webpage, such as text, images, videos, and other elements that convey your message. |
| 113 | + |
| 114 | +- **Layout** pertains to the arrangement and presentation of this content, including the positioning, styling, and structuring of elements. The goal of layout design is to ensure that content is visually appealing and well-organized. |
| 115 | + |
| 116 | +SmartUI's layout comparison feature allows you to focus specifically on layout differences while ignoring content changes, giving you more precise control over your visual testing process. |
| 117 | + |
| 118 | +## Use Cases for Layout Comparison |
| 119 | + |
| 120 | +The layout comparison feature is particularly valuable in the following scenarios: |
| 121 | + |
| 122 | +1. **Component Library Development**: When developing reusable components, you may want to verify that the layout structure remains consistent while allowing for content and style variations. |
| 123 | + |
| 124 | +2. **Responsive Design Testing**: When testing responsive layouts across different screen sizes, you may want to focus on ensuring the layout structure adapts correctly while ignoring specific content or style changes. |
| 125 | + |
| 126 | +3. **Design System Implementation**: When implementing a design system, you may need to verify that the layout structure follows the established patterns while allowing for content and style variations. |
| 127 | + |
| 128 | +4. **A/B Testing**: During A/B testing of different layouts, you may want to compare the structural integrity while ignoring the intentional content and style differences between variants. |
| 129 | + |
| 130 | +5. **Multi-language Testing**: When testing websites in different languages, you may want to verify that the layout structure remains consistent despite text length variations. |
| 131 | + |
| 132 | +6. **Cross-Environment Testing**: Ensure that your page structure remains intact across different operating systems, browsers, devices, viewport sizes, and orientations. |
| 133 | + |
| 134 | +## Validations |
| 135 | + |
| 136 | +When using layout comparison, SmartUI performs the following validations: |
| 137 | + |
| 138 | +1. **Layout Structure Extraction**: The system extracts the layout structure from the page |
| 139 | +2. **Position Calculations**: Accurate calculation of element positions relative to each other |
| 140 | +3. **Relative Positioning**: Preservation of relative positioning between elements |
| 141 | +4. **Viewport Considerations**: Proper handling of viewport dimensions and scrolling |
| 142 | + |
| 143 | +## Example Implementation |
| 144 | + |
| 145 | +Here's a complete example showing how to implement layout comparison in a test: |
| 146 | + |
| 147 | +```javascript |
| 148 | +describe('Layout Structure Test', () => { |
| 149 | + it('should verify layout structure while ignoring content and style changes', async () => { |
| 150 | + // Navigate to the page |
| 151 | + await driver.get('https://example.com'); |
| 152 | + |
| 153 | + // Wait for layout to stabilize (important for dynamic content) |
| 154 | + await driver.wait(until.elementLocated(By.cssSelector('.main-content')), 5000); |
| 155 | + |
| 156 | + // Configure options to focus only on layout structure |
| 157 | + let options = { |
| 158 | + ignoreType: "layout" |
| 159 | + }; |
| 160 | + |
| 161 | + // Take screenshot with layout comparison |
| 162 | + await smartuiSnapshot(driver, "HomePageLayout", options); |
| 163 | + }); |
| 164 | +}); |
| 165 | +``` |
| 166 | + |
| 167 | +## Additional Resources |
| 168 | + |
| 169 | +- [SmartUI SDK Documentation](/docs/smartui-sdk-config-options) |
| 170 | +- [Visual Regression Testing Guide](/docs/smart-visual-testing) |
| 171 | +- [Comparison Settings Documentation](/docs/test-settings-options) |
0 commit comments