|
1 | 1 | # TESTR-TEST-DATA Manual Page |
2 | 2 |
|
3 | 3 | ## NAME |
4 | | -testr-test-data - Test Data syntax for Test Cases using Playwright locators |
| 4 | +testr-test-data - Test Data syntax for Test Cases using Playwright .NET locators |
5 | 5 |
|
6 | 6 | ## SYNOPSIS |
7 | | -Test Data syntax is used to define the actions and expectations for each test step in a Test Case. The syntax follows a key-value pair format. |
| 7 | +Test Data syntax is used to define the actions and expectations for each test step in a Test Case. The syntax follows a key-value pair format where each parameter is specified as `Key=Value` separated by spaces. |
8 | 8 |
|
9 | 9 | ## DESCRIPTION |
10 | | -The Test Data syntax allows you to specify locators, actions, and other parameters for each test step. The following keys are supported: |
| 10 | +The Test Data syntax allows you to specify locators, actions, and other parameters for each test step using Playwright .NET locators. The following keys are supported: |
11 | 11 |
|
12 | 12 | ### Locator |
13 | | -Specifies the method to locate an element on the page. Supported values: |
14 | | -- `BySelector`: Locate by a css-selector. |
15 | | -- `GetByLabel`: Locate an element by its label. |
16 | | -- `GetByRole`: Locate an element by its ARIA role. |
17 | | -- `GetByTestId`: Locate by a data-testId attribute. |
18 | | -- `GetByText`: Locate an element by its text content. |
| 13 | +Specifies the method to locate an element on the page. **Required for all test steps.** |
| 14 | +Supported values: |
| 15 | +- `BySelector`: Locate by a CSS selector (use `Text` parameter for the selector string). |
| 16 | +- `GetByLabel`: Locate an element by its associated label text. |
| 17 | +- `GetByRole`: Locate an element by its ARIA role (requires `AriaRole` parameter). |
| 18 | +- `GetByTestId`: Locate by a data-testid attribute (use `Text` parameter for the test ID). |
| 19 | +- `GetByText`: Locate an element by its visible text content. |
19 | 20 |
|
20 | 21 | ### AriaRole |
21 | | -Specifies the ARIA role of the element. This is used in conjunction with `GetByRole` locator. Supported values include: |
22 | | -- `Button` |
23 | | -- `Link` |
24 | | -- `Textbox` |
25 | | -- `Checkbox` |
26 | | -- (and other ARIA roles) |
| 22 | +Specifies the ARIA role of the element. **Required when using `GetByRole` locator.** |
| 23 | +Supported values include (case-sensitive): |
| 24 | +- `Button` - Button elements |
| 25 | +- `Link` - Link elements |
| 26 | +- `Textbox` - Input fields and text areas |
| 27 | +- `Checkbox` - Checkbox inputs |
| 28 | +- And other standard ARIA roles supported by Playwright |
27 | 29 |
|
28 | 30 | ### Text |
29 | | -Specifies the text content to locate the element. This is used in conjunction with `GetByText` and `GetByLabel` locators. |
| 31 | +Specifies the text content to locate the element. **Required for most locator types.** |
| 32 | +- For `GetByLabel`: The label text associated with the input |
| 33 | +- For `GetByText`: The visible text content of the element |
| 34 | +- For `GetByTestId`: The data-testid attribute value |
| 35 | +- For `BySelector`: The CSS selector string |
| 36 | +- For `GetByRole`: The accessible name of the element (optional) |
30 | 37 |
|
31 | 38 | ### Value |
32 | | -Specifies the value to be used in actions like `Fill`. |
| 39 | +Specifies the value to be used in actions. **Required for `Fill` and `PickFile` actions.** |
| 40 | +- For `Fill`: The text to enter into the input field |
| 41 | +- For `PickFile`: The file path (relative or absolute) to the file to upload |
| 42 | +- Supports variable substitution using `@VariableName` syntax |
33 | 43 |
|
34 | 44 | ### Action |
35 | | -Specifies the action to be performed on the located element. Supported values: |
36 | | -- `Click`: Click on the element. |
37 | | -- `Fill`: Fill the element with the specified value. |
38 | | -- `PickFile`: Pick the element and choose a file. Use the `Value`-text property to specify the path of the file. |
39 | | -- `IsVisible`: Check if the element is visible. |
| 45 | +Specifies the action to be performed on the located element. **Required for all test steps.** |
| 46 | +Supported values: |
| 47 | +- `Click`: Click on the element |
| 48 | +- `Fill`: Fill the element with the specified value (requires `Value` parameter) |
| 49 | +- `PickFile`: Upload a file to a file input (requires `Value` parameter with file path) |
| 50 | +- `IsVisible`: Assert that the element is visible (returns boolean) |
| 51 | + |
| 52 | +## WORKFLOW |
| 53 | +To create and run test cases with testr CLI: |
| 54 | + |
| 55 | +1. **Create a new test case:** |
| 56 | + ``` |
| 57 | + testr test-case TC-001-Login "User Login Test" |
| 58 | + ``` |
| 59 | + |
| 60 | +2. **Edit the generated markdown file** and add your test steps in the table format: |
| 61 | + ```markdown |
| 62 | + <!-- STEPS:BEGIN --> |
| 63 | + | Step ID | Description | Test Data | Expected Result | Actual Result | |
| 64 | + | ------: | ----------- | --------- | --------------- | ------------- | |
| 65 | + | 1 | Enter username | Locator=GetByLabel Text=Username Action=Fill Value=admin | Username is filled | - | |
| 66 | + <!-- STEPS:END --> |
| 67 | + ``` |
| 68 | + |
| 69 | +3. **Validate your test case:** |
| 70 | + ``` |
| 71 | + testr validate TC-001-Login |
| 72 | + ``` |
| 73 | + |
| 74 | +4. **Run the test case:** |
| 75 | + ``` |
| 76 | + testr run https://localhost:5001 -tc TC-001-Login |
| 77 | + ``` |
| 78 | + |
| 79 | +## VARIABLES |
| 80 | +Variables allow you to parameterize test data and can be passed via command line: |
| 81 | + |
| 82 | +- **Define variables in test data:** Use `@VariableName` syntax in the `Value` parameter |
| 83 | +- **Pass variables at runtime:** Use `-v Key=Value` when running tests |
| 84 | +- **Example:** |
| 85 | + - Test Data: `Locator=GetByLabel Text=Password Action=Fill Value=@Password` |
| 86 | + - Command: `testr run https://localhost:5001 -tc TC-001-Login -v Password=mySecretPassword` |
40 | 87 |
|
41 | 88 | ## EXAMPLES |
42 | 89 |
|
43 | | -Example 1: Click a button by its label |
44 | | -Locator=GetByLabel AriaRole=Button Text=Submit Action=Click |
| 90 | +### Basic Form Interactions |
45 | 91 |
|
46 | | -Example 2: Fill a textbox by its label |
47 | | -Locator=GetByLabel AriaRole=Textbox Text=Username Action=Fill Value=admin |
| 92 | +**Example 1: Fill a username field by label** |
| 93 | +``` |
| 94 | +Locator=GetByLabel Text=Username Action=Fill Value=admin |
| 95 | +``` |
48 | 96 |
|
49 | | -Example 3: Check if a text is visible |
50 | | -Locator=GetByText Text="Welcome, User!" Action=IsVisible |
| 97 | +**Example 2: Fill a password field with variable** |
| 98 | +``` |
| 99 | +Locator=GetByLabel Text=Password Action=Fill Value=@Password |
| 100 | +``` |
51 | 101 |
|
52 | | -Example 4: Click a button by its ARIA role |
| 102 | +**Example 3: Click a submit button by role** |
| 103 | +``` |
53 | 104 | Locator=GetByRole AriaRole=Button Text=Login Action=Click |
| 105 | +``` |
| 106 | + |
| 107 | +**Example 4: Click a link by role** |
| 108 | +``` |
| 109 | +Locator=GetByRole AriaRole=Link Text="Forgot Password?" Action=Click |
| 110 | +``` |
| 111 | + |
| 112 | +### Element Verification |
| 113 | + |
| 114 | +**Example 5: Check if welcome message is visible** |
| 115 | +``` |
| 116 | +Locator=GetByText Text="Welcome, User!" Action=IsVisible |
| 117 | +``` |
| 118 | + |
| 119 | +**Example 6: Verify logout button is visible by role** |
| 120 | +``` |
| 121 | +Locator=GetByRole AriaRole=Button Text=Logout Action=IsVisible |
| 122 | +``` |
| 123 | + |
| 124 | +### Advanced Locators |
| 125 | + |
| 126 | +**Example 7: Locate by CSS selector** |
| 127 | +``` |
| 128 | +Locator=BySelector Text=#login-form .submit-btn Action=Click |
| 129 | +``` |
| 130 | + |
| 131 | +**Example 8: Locate by test ID** |
| 132 | +``` |
| 133 | +Locator=GetByTestId Text=submit-button Action=Click |
| 134 | +``` |
| 135 | + |
| 136 | +**Example 9: File upload using test ID** |
| 137 | +``` |
| 138 | +Locator=GetByTestId Text=file-input Action=PickFile Value=../../test-files/document.pdf |
| 139 | +``` |
| 140 | + |
| 141 | +### Complex Text with Escaping |
| 142 | + |
| 143 | +**Example 10: Handle text with quotes and special characters** |
| 144 | +``` |
| 145 | +Locator=GetByText Text=\"Invalid login attempt for user 'admin'\" Action=IsVisible |
| 146 | +``` |
| 147 | + |
| 148 | +**Example 11: Fill field with multi-word text** |
| 149 | +``` |
| 150 | +Locator=GetByLabel Text="First Name" Action=Fill Value=John |
| 151 | +``` |
| 152 | + |
| 153 | +### Complete Test Step Examples |
| 154 | + |
| 155 | +Here's how these test data entries appear in a complete test case table: |
| 156 | + |
| 157 | +```markdown |
| 158 | +<!-- STEPS:BEGIN --> |
| 159 | +| Step ID | Description | Test Data | Expected Result | Actual Result | |
| 160 | +| -------:| ---------------------- | -------------------------------------------------------------- | ---------------------------------------------------------------- | ------------- | |
| 161 | +| 1 | enter username | Locator=GetByLabel Text=Username Action=Fill Value=admin | username is entered | - | |
| 162 | +| 2 | enter password | Locator=GetByLabel Text=Password Action=Fill Value=@Password | password is entered | - | |
| 163 | +| 3 | click login button | Locator=GetByRole AriaRole=Button Text=Login Action=Click | system validates credentials and redirects to dashboard | - | |
| 164 | +| 4 | verify dashboard | Locator=GetByRole AriaRole=Button Text=Logout Action=IsVisible | logout button visible in the main navigation | - | |
| 165 | +| 5 | upload document | Locator=GetByTestId Text=file-input Action=PickFile Value=./test.pdf | file is successfully uploaded | - | |
| 166 | +<!-- STEPS:END --> |
| 167 | +``` |
| 168 | + |
| 169 | +## COMMON PATTERNS |
| 170 | + |
| 171 | +### Form Validation Testing |
| 172 | +``` |
| 173 | +Locator=GetByText Text="This field is required" Action=IsVisible |
| 174 | +Locator=GetByText Text="Invalid email format" Action=IsVisible |
| 175 | +``` |
| 176 | + |
| 177 | +### Navigation Testing |
| 178 | +``` |
| 179 | +Locator=GetByRole AriaRole=Link Text=Dashboard Action=Click |
| 180 | +Locator=GetByRole AriaRole=Link Text="User Profile" Action=Click |
| 181 | +``` |
| 182 | + |
| 183 | +### Modal and Dialog Testing |
| 184 | +``` |
| 185 | +Locator=GetByRole AriaRole=Button Text="Open Dialog" Action=Click |
| 186 | +Locator=GetByRole AriaRole=Button Text="Confirm" Action=Click |
| 187 | +Locator=GetByRole AriaRole=Button Text="Cancel" Action=Click |
| 188 | +``` |
| 189 | + |
| 190 | +## TROUBLESHOOTING |
| 191 | + |
| 192 | +### Common Issues: |
| 193 | +1. **Element not found**: Verify the locator strategy and text match exactly what appears in the DOM |
| 194 | +2. **Action fails**: Ensure the element is interactable (visible, enabled) |
| 195 | +3. **Variable not resolved**: Check that variable is passed with `-v Key=Value` in the run command |
| 196 | +4. **Text escaping**: Use backslash before quotes: `Text=\"quoted text\"` |
| 197 | + |
| 198 | +### Best Practices: |
| 199 | +- Use `GetByRole` with ARIA roles for better accessibility and stability |
| 200 | +- Prefer `GetByLabel` for form inputs over CSS selectors |
| 201 | +- Use `GetByTestId` for elements specifically marked for testing |
| 202 | +- Keep test data parameterized with variables for different environments |
| 203 | +- Use descriptive test step descriptions that match the actual user action |
| 204 | + |
| 205 | +## COMMAND LINE OPTIONS |
| 206 | + |
| 207 | +### Running Tests with Options: |
| 208 | +```bash |
| 209 | +# Run with variables |
| 210 | +testr run https://localhost:5001 -tc TC-001-Login -v Password=secret123 -v Username=testuser |
| 211 | + |
| 212 | +# Run in headed mode (default is headless) |
| 213 | +testr run https://localhost:5001 -tc TC-001-Login --headless=false |
| 214 | + |
| 215 | +# Run with different browser |
| 216 | +testr run https://localhost:5001 -tc TC-001-Login -bt Firefox |
| 217 | + |
| 218 | +# Run with video recording |
| 219 | +testr run https://localhost:5001 -tc TC-001-Login -rvd ./recordings |
| 220 | + |
| 221 | +# Run with custom timeout |
| 222 | +testr run https://localhost:5001 -tc TC-001-Login -t 60000 |
| 223 | +``` |
54 | 224 |
|
55 | 225 | ## NOTES |
56 | | -In case of escaping strings, use a backslash \ followed by a double quote " (e.g., Locator=GetByText Text=\"Invalid login attempt for user 'Albert'\" Action=IsVisible). |
| 226 | +- Test Data parameters are case-sensitive |
| 227 | +- Use backslash escaping for quotes in text: `Text=\"escaped quotes\"` |
| 228 | +- Variable names in `@VariableName` format are case-sensitive |
| 229 | +- File paths in `PickFile` action support both relative and absolute paths |
| 230 | +- Empty or missing required parameters will cause test validation to fail |
57 | 231 |
|
58 | 232 | ## SEE ALSO |
59 | | -Playwright Documentation: https://playwright.dev/docs/locators |
| 233 | + |
| 234 | +### CLI Commands: |
| 235 | +- `testr test-case <id> "<title>"` - Create a new test case definition |
| 236 | +- `testr validate <test-case-id>` - Validate a test case definition |
| 237 | +- `testr run <domain> -tc <test-case-id>` - Execute a test case |
| 238 | +- `testr man` - Display this manual page |
| 239 | +- `testr playwright -c install` - Install Playwright browsers |
| 240 | + |
| 241 | +### Documentation: |
| 242 | +- Playwright .NET Documentation: https://playwright.dev/dotnet/docs/locators |
| 243 | +- ARIA Roles Reference: https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles |
| 244 | +- CSS Selectors Guide: https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors |
| 245 | + |
| 246 | +### Test Case Structure: |
| 247 | +Test cases are markdown files with metadata and a steps table. The basic structure includes: |
| 248 | +- Metadata (Date, Module, Type, Status, Route) |
| 249 | +- Description and Preconditions |
| 250 | +- Steps table with test data |
| 251 | +- Postconditions |
| 252 | + |
| 253 | +For complete examples, see the samples directory in the testr repository. |
0 commit comments