feat(api): shorted getByLabel, getByPlaceholder (#17816)
This commit is contained in:
parent
e2b5fc4f88
commit
8810b55504
|
|
@ -918,24 +918,24 @@ Attribute name to get the value for.
|
||||||
### option: Frame.getByAltText.exact = %%-locator-get-by-text-exact-%%
|
### option: Frame.getByAltText.exact = %%-locator-get-by-text-exact-%%
|
||||||
|
|
||||||
|
|
||||||
## method: Frame.getByLabelText
|
## method: Frame.getByLabel
|
||||||
* since: v1.27
|
* since: v1.27
|
||||||
- returns: <[Locator]>
|
- returns: <[Locator]>
|
||||||
|
|
||||||
%%-template-locator-get-by-label-text-%%
|
%%-template-locator-get-by-label-text-%%
|
||||||
|
|
||||||
### param: Frame.getByLabelText.text = %%-locator-get-by-text-text-%%
|
### param: Frame.getByLabel.text = %%-locator-get-by-text-text-%%
|
||||||
### option: Frame.getByLabelText.exact = %%-locator-get-by-text-exact-%%
|
### option: Frame.getByLabel.exact = %%-locator-get-by-text-exact-%%
|
||||||
|
|
||||||
|
|
||||||
## method: Frame.getByPlaceholderText
|
## method: Frame.getByPlaceholder
|
||||||
* since: v1.27
|
* since: v1.27
|
||||||
- returns: <[Locator]>
|
- returns: <[Locator]>
|
||||||
|
|
||||||
%%-template-locator-get-by-placeholder-text-%%
|
%%-template-locator-get-by-placeholder-text-%%
|
||||||
|
|
||||||
### param: Frame.getByPlaceholderText.text = %%-locator-get-by-text-text-%%
|
### param: Frame.getByPlaceholder.text = %%-locator-get-by-text-text-%%
|
||||||
### option: Frame.getByPlaceholderText.exact = %%-locator-get-by-text-exact-%%
|
### option: Frame.getByPlaceholder.exact = %%-locator-get-by-text-exact-%%
|
||||||
|
|
||||||
|
|
||||||
## method: Frame.getByRole
|
## method: Frame.getByRole
|
||||||
|
|
|
||||||
|
|
@ -124,24 +124,24 @@ in that iframe.
|
||||||
### option: FrameLocator.getByAltText.exact = %%-locator-get-by-text-exact-%%
|
### option: FrameLocator.getByAltText.exact = %%-locator-get-by-text-exact-%%
|
||||||
|
|
||||||
|
|
||||||
## method: FrameLocator.getByLabelText
|
## method: FrameLocator.getByLabel
|
||||||
* since: v1.27
|
* since: v1.27
|
||||||
- returns: <[Locator]>
|
- returns: <[Locator]>
|
||||||
|
|
||||||
%%-template-locator-get-by-label-text-%%
|
%%-template-locator-get-by-label-text-%%
|
||||||
|
|
||||||
### param: FrameLocator.getByLabelText.text = %%-locator-get-by-text-text-%%
|
### param: FrameLocator.getByLabel.text = %%-locator-get-by-text-text-%%
|
||||||
### option: FrameLocator.getByLabelText.exact = %%-locator-get-by-text-exact-%%
|
### option: FrameLocator.getByLabel.exact = %%-locator-get-by-text-exact-%%
|
||||||
|
|
||||||
|
|
||||||
## method: FrameLocator.getByPlaceholderText
|
## method: FrameLocator.getByPlaceholder
|
||||||
* since: v1.27
|
* since: v1.27
|
||||||
- returns: <[Locator]>
|
- returns: <[Locator]>
|
||||||
|
|
||||||
%%-template-locator-get-by-placeholder-text-%%
|
%%-template-locator-get-by-placeholder-text-%%
|
||||||
|
|
||||||
### param: FrameLocator.getByPlaceholderText.text = %%-locator-get-by-text-text-%%
|
### param: FrameLocator.getByPlaceholder.text = %%-locator-get-by-text-text-%%
|
||||||
### option: FrameLocator.getByPlaceholderText.exact = %%-locator-get-by-text-exact-%%
|
### option: FrameLocator.getByPlaceholder.exact = %%-locator-get-by-text-exact-%%
|
||||||
|
|
||||||
|
|
||||||
## method: FrameLocator.getByRole
|
## method: FrameLocator.getByRole
|
||||||
|
|
|
||||||
|
|
@ -644,24 +644,24 @@ Attribute name to get the value for.
|
||||||
### option: Locator.getByAltText.exact = %%-locator-get-by-text-exact-%%
|
### option: Locator.getByAltText.exact = %%-locator-get-by-text-exact-%%
|
||||||
|
|
||||||
|
|
||||||
## method: Locator.getByLabelText
|
## method: Locator.getByLabel
|
||||||
* since: v1.27
|
* since: v1.27
|
||||||
- returns: <[Locator]>
|
- returns: <[Locator]>
|
||||||
|
|
||||||
%%-template-locator-get-by-label-text-%%
|
%%-template-locator-get-by-label-text-%%
|
||||||
|
|
||||||
### param: Locator.getByLabelText.text = %%-locator-get-by-text-text-%%
|
### param: Locator.getByLabel.text = %%-locator-get-by-text-text-%%
|
||||||
### option: Locator.getByLabelText.exact = %%-locator-get-by-text-exact-%%
|
### option: Locator.getByLabel.exact = %%-locator-get-by-text-exact-%%
|
||||||
|
|
||||||
|
|
||||||
## method: Locator.getByPlaceholderText
|
## method: Locator.getByPlaceholder
|
||||||
* since: v1.27
|
* since: v1.27
|
||||||
- returns: <[Locator]>
|
- returns: <[Locator]>
|
||||||
|
|
||||||
%%-template-locator-get-by-placeholder-text-%%
|
%%-template-locator-get-by-placeholder-text-%%
|
||||||
|
|
||||||
### param: Locator.getByPlaceholderText.text = %%-locator-get-by-text-text-%%
|
### param: Locator.getByPlaceholder.text = %%-locator-get-by-text-text-%%
|
||||||
### option: Locator.getByPlaceholderText.exact = %%-locator-get-by-text-exact-%%
|
### option: Locator.getByPlaceholder.exact = %%-locator-get-by-text-exact-%%
|
||||||
|
|
||||||
|
|
||||||
## method: Locator.getByRole
|
## method: Locator.getByRole
|
||||||
|
|
@ -1128,31 +1128,31 @@ await element.TypeAsync("World", new() { Delay = 100 }); // Types slower, like a
|
||||||
An example of typing into a text field and then submitting the form:
|
An example of typing into a text field and then submitting the form:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const element = page.getByLabelText('Password');
|
const element = page.getByLabel('Password');
|
||||||
await element.type('my password');
|
await element.type('my password');
|
||||||
await element.press('Enter');
|
await element.press('Enter');
|
||||||
```
|
```
|
||||||
|
|
||||||
```java
|
```java
|
||||||
Locator element = page.getByLabelText("Password");
|
Locator element = page.getByLabel("Password");
|
||||||
element.type("my password");
|
element.type("my password");
|
||||||
element.press("Enter");
|
element.press("Enter");
|
||||||
```
|
```
|
||||||
|
|
||||||
```python async
|
```python async
|
||||||
element = page.get_by_label_text("Password")
|
element = page.get_by_label("Password")
|
||||||
await element.type("my password")
|
await element.type("my password")
|
||||||
await element.press("Enter")
|
await element.press("Enter")
|
||||||
```
|
```
|
||||||
|
|
||||||
```python sync
|
```python sync
|
||||||
element = page.get_by_label_text("Password")
|
element = page.get_by_label("Password")
|
||||||
element.type("my password")
|
element.type("my password")
|
||||||
element.press("Enter")
|
element.press("Enter")
|
||||||
```
|
```
|
||||||
|
|
||||||
```csharp
|
```csharp
|
||||||
var element = page.GetByLabelText("Password");
|
var element = page.GetByLabel("Password");
|
||||||
await element.TypeAsync("my password");
|
await element.TypeAsync("my password");
|
||||||
await element.PressAsync("Enter");
|
await element.PressAsync("Enter");
|
||||||
```
|
```
|
||||||
|
|
|
||||||
|
|
@ -404,30 +404,30 @@ Expected options currently selected.
|
||||||
Ensures the [Locator] points to a checked input.
|
Ensures the [Locator] points to a checked input.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const locator = page.getByLabelText('Subscribe to newsletter');
|
const locator = page.getByLabel('Subscribe to newsletter');
|
||||||
await expect(locator).toBeChecked();
|
await expect(locator).toBeChecked();
|
||||||
```
|
```
|
||||||
|
|
||||||
```java
|
```java
|
||||||
assertThat(page.getByLabelText("Subscribe to newsletter")).isChecked();
|
assertThat(page.getByLabel("Subscribe to newsletter")).isChecked();
|
||||||
```
|
```
|
||||||
|
|
||||||
```python async
|
```python async
|
||||||
from playwright.async_api import expect
|
from playwright.async_api import expect
|
||||||
|
|
||||||
locator = page.get_by_label_text("Subscribe to newsletter")
|
locator = page.get_by_label("Subscribe to newsletter")
|
||||||
await expect(locator).to_be_checked()
|
await expect(locator).to_be_checked()
|
||||||
```
|
```
|
||||||
|
|
||||||
```python sync
|
```python sync
|
||||||
from playwright.sync_api import expect
|
from playwright.sync_api import expect
|
||||||
|
|
||||||
locator = page.get_by_label_text("Subscribe to newsletter")
|
locator = page.get_by_label("Subscribe to newsletter")
|
||||||
expect(locator).to_be_checked()
|
expect(locator).to_be_checked()
|
||||||
```
|
```
|
||||||
|
|
||||||
```csharp
|
```csharp
|
||||||
var locator = Page.GetByLabelText("Subscribe to newsletter");
|
var locator = Page.GetByLabel("Subscribe to newsletter");
|
||||||
await Expect(locator).ToBeCheckedAsync();
|
await Expect(locator).ToBeCheckedAsync();
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2193,24 +2193,24 @@ Attribute name to get the value for.
|
||||||
### option: Page.getByAltText.exact = %%-locator-get-by-text-exact-%%
|
### option: Page.getByAltText.exact = %%-locator-get-by-text-exact-%%
|
||||||
|
|
||||||
|
|
||||||
## method: Page.getByLabelText
|
## method: Page.getByLabel
|
||||||
* since: v1.27
|
* since: v1.27
|
||||||
- returns: <[Locator]>
|
- returns: <[Locator]>
|
||||||
|
|
||||||
%%-template-locator-get-by-label-text-%%
|
%%-template-locator-get-by-label-text-%%
|
||||||
|
|
||||||
### param: Page.getByLabelText.text = %%-locator-get-by-text-text-%%
|
### param: Page.getByLabel.text = %%-locator-get-by-text-text-%%
|
||||||
### option: Page.getByLabelText.exact = %%-locator-get-by-text-exact-%%
|
### option: Page.getByLabel.exact = %%-locator-get-by-text-exact-%%
|
||||||
|
|
||||||
|
|
||||||
## method: Page.getByPlaceholderText
|
## method: Page.getByPlaceholder
|
||||||
* since: v1.27
|
* since: v1.27
|
||||||
- returns: <[Locator]>
|
- returns: <[Locator]>
|
||||||
|
|
||||||
%%-template-locator-get-by-placeholder-text-%%
|
%%-template-locator-get-by-placeholder-text-%%
|
||||||
|
|
||||||
### param: Page.getByPlaceholderText.text = %%-locator-get-by-text-text-%%
|
### param: Page.getByPlaceholder.text = %%-locator-get-by-text-text-%%
|
||||||
### option: Page.getByPlaceholderText.exact = %%-locator-get-by-text-exact-%%
|
### option: Page.getByPlaceholder.exact = %%-locator-get-by-text-exact-%%
|
||||||
|
|
||||||
|
|
||||||
## method: Page.getByRole
|
## method: Page.getByRole
|
||||||
|
|
|
||||||
|
|
@ -23,8 +23,8 @@ test.beforeEach(async ({ page }) => {
|
||||||
// Runs before each test and signs in each page.
|
// Runs before each test and signs in each page.
|
||||||
await page.goto('https://github.com/login');
|
await page.goto('https://github.com/login');
|
||||||
await page.getByText('Login').click();
|
await page.getByText('Login').click();
|
||||||
await page.getByLabelText('User Name').fill('username');
|
await page.getByLabel('User Name').fill('username');
|
||||||
await page.getByLabelText('Password').fill('password');
|
await page.getByLabel('Password').fill('password');
|
||||||
await page.getByText('Submit').click();
|
await page.getByText('Submit').click();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -44,8 +44,8 @@ test.beforeEach(async ({ page }) => {
|
||||||
// Runs before each test and signs in each page.
|
// Runs before each test and signs in each page.
|
||||||
await page.goto('https://github.com/login');
|
await page.goto('https://github.com/login');
|
||||||
await page.getByText('Login').click();
|
await page.getByText('Login').click();
|
||||||
await page.getByLabelText('User name').fill('username');
|
await page.getByLabel('User name').fill('username');
|
||||||
await page.getByLabelText('Password').fill('password');
|
await page.getByLabel('Password').fill('password');
|
||||||
await page.getByText('Submit').click();
|
await page.getByText('Submit').click();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -64,8 +64,8 @@ await page.goto('https://github.com/login');
|
||||||
|
|
||||||
// Interact with login form
|
// Interact with login form
|
||||||
await page.getByText('Login').click();
|
await page.getByText('Login').click();
|
||||||
await page.getByLabelText('User Name').fill(USERNAME);
|
await page.getByLabel('User Name').fill(USERNAME);
|
||||||
await page.getByLabelText('Password').fill(PASSWORD);
|
await page.getByLabel('Password').fill(PASSWORD);
|
||||||
await page.getByText('Submit').click();
|
await page.getByText('Submit').click();
|
||||||
// Continue with the test
|
// Continue with the test
|
||||||
```
|
```
|
||||||
|
|
@ -75,8 +75,8 @@ Page page = context.newPage();
|
||||||
page.navigate("https://github.com/login");
|
page.navigate("https://github.com/login");
|
||||||
// Interact with login form
|
// Interact with login form
|
||||||
page.getByText("Login").click();
|
page.getByText("Login").click();
|
||||||
page.getByLabelText("User Name").fill(USERNAME);
|
page.getByLabel("User Name").fill(USERNAME);
|
||||||
page.getByLabelText("Password").fill(PASSWORD);
|
page.getByLabel("Password").fill(PASSWORD);
|
||||||
page.locator("text=Submit").click();
|
page.locator("text=Submit").click();
|
||||||
// Continue with the test
|
// Continue with the test
|
||||||
```
|
```
|
||||||
|
|
@ -87,8 +87,8 @@ await page.goto('https://github.com/login')
|
||||||
|
|
||||||
# Interact with login form
|
# Interact with login form
|
||||||
await page.get_by_text("Login").click()
|
await page.get_by_text("Login").click()
|
||||||
await page.get_by_label_text("User Name").fill(USERNAME)
|
await page.get_by_label("User Name").fill(USERNAME)
|
||||||
await page.get_by_label_text("Password").fill(PASSWORD)
|
await page.get_by_label("Password").fill(PASSWORD)
|
||||||
await page.get_by_text('Submit').click()
|
await page.get_by_text('Submit').click()
|
||||||
# Continue with the test
|
# Continue with the test
|
||||||
```
|
```
|
||||||
|
|
@ -99,8 +99,8 @@ page.goto('https://github.com/login')
|
||||||
|
|
||||||
# Interact with login form
|
# Interact with login form
|
||||||
page.get_by_text("Login").click()
|
page.get_by_text("Login").click()
|
||||||
page.get_by_label_text("User Name").fill(USERNAME)
|
page.get_by_label("User Name").fill(USERNAME)
|
||||||
page.get_by_label_text("Password").fill(PASSWORD)
|
page.get_by_label("Password").fill(PASSWORD)
|
||||||
page.get_by_text('Submit').click()
|
page.get_by_text('Submit').click()
|
||||||
# Continue with the test
|
# Continue with the test
|
||||||
```
|
```
|
||||||
|
|
@ -110,8 +110,8 @@ var page = await context.NewPageAsync();
|
||||||
await page.GotoAsync("https://github.com/login");
|
await page.GotoAsync("https://github.com/login");
|
||||||
// Interact with login form
|
// Interact with login form
|
||||||
await page.GetByText("Login").ClickAsync();
|
await page.GetByText("Login").ClickAsync();
|
||||||
await page.GetByLabelText("User Name").FillAsync(USERNAME);
|
await page.GetByLabel("User Name").FillAsync(USERNAME);
|
||||||
await page.GetByLabelText("Password").FillAsync(PASSWORD);
|
await page.GetByLabel("Password").FillAsync(PASSWORD);
|
||||||
await page.GetByText("Submit").ClickAsync();
|
await page.GetByText("Submit").ClickAsync();
|
||||||
// Continue with the test
|
// Continue with the test
|
||||||
```
|
```
|
||||||
|
|
@ -189,8 +189,8 @@ module.exports = async config => {
|
||||||
const browser = await chromium.launch();
|
const browser = await chromium.launch();
|
||||||
const page = await browser.newPage();
|
const page = await browser.newPage();
|
||||||
await page.goto('https://github.com/login');
|
await page.goto('https://github.com/login');
|
||||||
await page.getByLabelText('User Name').fill('user');
|
await page.getByLabel('User Name').fill('user');
|
||||||
await page.getByLabelText('Password').fill('password');
|
await page.getByLabel('Password').fill('password');
|
||||||
await page.getByText('Sign in').click();
|
await page.getByText('Sign in').click();
|
||||||
// Save signed-in state to 'storageState.json'.
|
// Save signed-in state to 'storageState.json'.
|
||||||
await page.context().storageState({ path: 'storageState.json' });
|
await page.context().storageState({ path: 'storageState.json' });
|
||||||
|
|
@ -206,8 +206,8 @@ async function globalSetup(config: FullConfig) {
|
||||||
const browser = await chromium.launch();
|
const browser = await chromium.launch();
|
||||||
const page = await browser.newPage();
|
const page = await browser.newPage();
|
||||||
await page.goto('https://github.com/login');
|
await page.goto('https://github.com/login');
|
||||||
await page.getByLabelText('User Name').fill('user');
|
await page.getByLabel('User Name').fill('user');
|
||||||
await page.getByLabelText('Password').fill('password');
|
await page.getByLabel('Password').fill('password');
|
||||||
await page.getByText('Sign in').click();
|
await page.getByText('Sign in').click();
|
||||||
// Save signed-in state to 'storageState.json'.
|
// Save signed-in state to 'storageState.json'.
|
||||||
await page.context().storageState({ path: 'storageState.json' });
|
await page.context().storageState({ path: 'storageState.json' });
|
||||||
|
|
@ -339,8 +339,8 @@ exports.test = base.extend({
|
||||||
// Make sure we are not using any other storage state.
|
// Make sure we are not using any other storage state.
|
||||||
const page = await browser.newPage({ storageState: undefined });
|
const page = await browser.newPage({ storageState: undefined });
|
||||||
await page.goto('https://github.com/login');
|
await page.goto('https://github.com/login');
|
||||||
await page.getByLabelText('User Name').fill(users[testInfo.workerIndex].username);
|
await page.getByLabel('User Name').fill(users[testInfo.workerIndex].username);
|
||||||
await page.getByLabelText('Password').fill(users[testInfo.workerIndex].password);
|
await page.getByLabel('Password').fill(users[testInfo.workerIndex].password);
|
||||||
await page.getByText('Sign in').click();
|
await page.getByText('Sign in').click();
|
||||||
await page.context().storageState({ path: fileName });
|
await page.context().storageState({ path: fileName });
|
||||||
await page.close();
|
await page.close();
|
||||||
|
|
@ -378,8 +378,8 @@ export const test = baseTest.extend({
|
||||||
const page = await browser.newPage({ storageState: undefined });
|
const page = await browser.newPage({ storageState: undefined });
|
||||||
await page.goto('https://github.com/login');
|
await page.goto('https://github.com/login');
|
||||||
// Create a unique username for each worker.
|
// Create a unique username for each worker.
|
||||||
await page.getByLabelText('User Name').fill(users[testInfo.workerIndex].username);
|
await page.getByLabel('User Name').fill(users[testInfo.workerIndex].username);
|
||||||
await page.getByLabelText('Password').fill(users[testInfo.workerIndex].password);
|
await page.getByLabel('Password').fill(users[testInfo.workerIndex].password);
|
||||||
await page.getByText('Sign in').click();
|
await page.getByText('Sign in').click();
|
||||||
await page.context().storageState({ path: fileName });
|
await page.context().storageState({ path: fileName });
|
||||||
await page.close();
|
await page.close();
|
||||||
|
|
@ -675,8 +675,8 @@ test.beforeAll(async ({ browser }) => {
|
||||||
// Create page yourself and sign in.
|
// Create page yourself and sign in.
|
||||||
page = await browser.newPage();
|
page = await browser.newPage();
|
||||||
await page.goto('https://github.com/login');
|
await page.goto('https://github.com/login');
|
||||||
await page.getByLabelText('User Name').fill('user');
|
await page.getByLabel('User Name').fill('user');
|
||||||
await page.getByLabelText('Password').fill('password');
|
await page.getByLabel('Password').fill('password');
|
||||||
await page.getByText('Sign in').click();
|
await page.getByText('Sign in').click();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -706,8 +706,8 @@ test.beforeAll(async ({ browser }) => {
|
||||||
// Create page once and sign in.
|
// Create page once and sign in.
|
||||||
page = await browser.newPage();
|
page = await browser.newPage();
|
||||||
await page.goto('https://github.com/login');
|
await page.goto('https://github.com/login');
|
||||||
await page.getByLabelText('User Name').fill('user');
|
await page.getByLabel('User Name').fill('user');
|
||||||
await page.getByLabelText('Password').fill('password');
|
await page.getByLabel('Password').fill('password');
|
||||||
await page.getByText('Sign in').click();
|
await page.getByText('Sign in').click();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,32 +11,32 @@ inside the frame.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
// Locate element inside frame
|
// Locate element inside frame
|
||||||
const username = await page.frameLocator('.frame-class').getByLabelText('User Name');
|
const username = await page.frameLocator('.frame-class').getByLabel('User Name');
|
||||||
await username.fill('John');
|
await username.fill('John');
|
||||||
```
|
```
|
||||||
|
|
||||||
```java
|
```java
|
||||||
// Locate element inside frame
|
// Locate element inside frame
|
||||||
Locator username = page.frameLocator(".frame-class").getByLabelText("User Name");
|
Locator username = page.frameLocator(".frame-class").getByLabel("User Name");
|
||||||
username.fill("John");
|
username.fill("John");
|
||||||
```
|
```
|
||||||
|
|
||||||
```python async
|
```python async
|
||||||
# Locate element inside frame
|
# Locate element inside frame
|
||||||
username = await page.frame_locator('.frame-class').get_by_label_text('User Name')
|
username = await page.frame_locator('.frame-class').get_by_label('User Name')
|
||||||
await username.fill('John')
|
await username.fill('John')
|
||||||
```
|
```
|
||||||
|
|
||||||
```python sync
|
```python sync
|
||||||
# Locate element inside frame
|
# Locate element inside frame
|
||||||
# Get frame using any other selector
|
# Get frame using any other selector
|
||||||
username = page.frame_locator('.frame-class').get_by_label_text('User Name')
|
username = page.frame_locator('.frame-class').get_by_label('User Name')
|
||||||
username.fill('John')
|
username.fill('John')
|
||||||
```
|
```
|
||||||
|
|
||||||
```csharp
|
```csharp
|
||||||
// Locate element inside frame
|
// Locate element inside frame
|
||||||
var username = await page.FrameLocator(".frame-class").GetByLabelText("User Name");
|
var username = await page.FrameLocator(".frame-class").GetByLabel("User Name");
|
||||||
await username.FillAsync("John");
|
await username.FillAsync("John");
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,13 +14,13 @@ Using [`method: Locator.fill`] is the easiest way to fill out the form fields. I
|
||||||
await page.getByRole('textbox').fill('Peter');
|
await page.getByRole('textbox').fill('Peter');
|
||||||
|
|
||||||
// Date input
|
// Date input
|
||||||
await page.getByLabelText('Birth date').fill('2020-02-02');
|
await page.getByLabel('Birth date').fill('2020-02-02');
|
||||||
|
|
||||||
// Time input
|
// Time input
|
||||||
await page.getByLabelText('Appointment time').fill('13:15');
|
await page.getByLabel('Appointment time').fill('13:15');
|
||||||
|
|
||||||
// Local datetime input
|
// Local datetime input
|
||||||
await page.getByLabelText('Local time').fill('2020-03-02T05:15');
|
await page.getByLabel('Local time').fill('2020-03-02T05:15');
|
||||||
```
|
```
|
||||||
|
|
||||||
```java
|
```java
|
||||||
|
|
@ -28,13 +28,13 @@ await page.getByLabelText('Local time').fill('2020-03-02T05:15');
|
||||||
page.getByRole("textbox").fill("Peter");
|
page.getByRole("textbox").fill("Peter");
|
||||||
|
|
||||||
// Date input
|
// Date input
|
||||||
page.getByLabelText("Birth date").fill("2020-02-02");
|
page.getByLabel("Birth date").fill("2020-02-02");
|
||||||
|
|
||||||
// Time input
|
// Time input
|
||||||
page.getByLabelText("Appointment time").fill("13-15");
|
page.getByLabel("Appointment time").fill("13-15");
|
||||||
|
|
||||||
// Local datetime input
|
// Local datetime input
|
||||||
page.getByLabelText("Local time").fill("2020-03-02T05:15");
|
page.getByLabel("Local time").fill("2020-03-02T05:15");
|
||||||
```
|
```
|
||||||
|
|
||||||
```python async
|
```python async
|
||||||
|
|
@ -42,13 +42,13 @@ page.getByLabelText("Local time").fill("2020-03-02T05:15");
|
||||||
await page.get_by_role("textbox").fill("Peter")
|
await page.get_by_role("textbox").fill("Peter")
|
||||||
|
|
||||||
# Date input
|
# Date input
|
||||||
await page.get_by_label_text("Birth date").fill("2020-02-02")
|
await page.get_by_label("Birth date").fill("2020-02-02")
|
||||||
|
|
||||||
# Time input
|
# Time input
|
||||||
await page.get_by_label_text("Appointment time").fill("13:15")
|
await page.get_by_label("Appointment time").fill("13:15")
|
||||||
|
|
||||||
# Local datetime input
|
# Local datetime input
|
||||||
await page.get_by_label_text("Local time").fill("2020-03-02T05:15")
|
await page.get_by_label("Local time").fill("2020-03-02T05:15")
|
||||||
```
|
```
|
||||||
|
|
||||||
```python sync
|
```python sync
|
||||||
|
|
@ -56,13 +56,13 @@ await page.get_by_label_text("Local time").fill("2020-03-02T05:15")
|
||||||
page.get_by_role("textbox").fill("Peter")
|
page.get_by_role("textbox").fill("Peter")
|
||||||
|
|
||||||
# Date input
|
# Date input
|
||||||
page.get_by_label_text("Birth date").fill("2020-02-02")
|
page.get_by_label("Birth date").fill("2020-02-02")
|
||||||
|
|
||||||
# Time input
|
# Time input
|
||||||
page.get_by_label_text("Appointment time").fill("13:15")
|
page.get_by_label("Appointment time").fill("13:15")
|
||||||
|
|
||||||
# Local datetime input
|
# Local datetime input
|
||||||
page.get_by_label_text("Local time").fill("2020-03-02T05:15")
|
page.get_by_label("Local time").fill("2020-03-02T05:15")
|
||||||
```
|
```
|
||||||
|
|
||||||
```csharp
|
```csharp
|
||||||
|
|
@ -70,13 +70,13 @@ page.get_by_label_text("Local time").fill("2020-03-02T05:15")
|
||||||
await page.GetByRole("textbox").FillAsync("Peter");
|
await page.GetByRole("textbox").FillAsync("Peter");
|
||||||
|
|
||||||
// Date input
|
// Date input
|
||||||
await page.GetByLabelText("Birth date").FillAsync("2020-02-02");
|
await page.GetByLabel("Birth date").FillAsync("2020-02-02");
|
||||||
|
|
||||||
// Time input
|
// Time input
|
||||||
await page.GetByLabelText("Appointment time").FillAsync("13-15");
|
await page.GetByLabel("Appointment time").FillAsync("13-15");
|
||||||
|
|
||||||
// Local datetime input
|
// Local datetime input
|
||||||
await page.GetByLabelText("Local time").FillAsync("2020-03-02T05:15");
|
await page.GetByLabel("Local time").FillAsync("2020-03-02T05:15");
|
||||||
```
|
```
|
||||||
|
|
||||||
## Checkboxes and radio buttons
|
## Checkboxes and radio buttons
|
||||||
|
|
@ -85,57 +85,57 @@ Using [`method: Locator.setChecked`] is the easiest way to check and uncheck a c
|
||||||
|
|
||||||
```js
|
```js
|
||||||
// Check the checkbox
|
// Check the checkbox
|
||||||
await page.getByLabelText('I agree to the terms above').check();
|
await page.getByLabel('I agree to the terms above').check();
|
||||||
|
|
||||||
// Assert the checked state
|
// Assert the checked state
|
||||||
expect(await page.getByLabelText('Subscribe to newsletter').isChecked()).toBeTruthy()
|
expect(await page.getByLabel('Subscribe to newsletter').isChecked()).toBeTruthy()
|
||||||
|
|
||||||
// Select the radio button
|
// Select the radio button
|
||||||
await page.getByLabelText('XL').check();
|
await page.getByLabel('XL').check();
|
||||||
```
|
```
|
||||||
|
|
||||||
```java
|
```java
|
||||||
// Check the checkbox
|
// Check the checkbox
|
||||||
page.getByLabelText("I agree to the terms above").check();
|
page.getByLabel("I agree to the terms above").check();
|
||||||
|
|
||||||
// Assert the checked state
|
// Assert the checked state
|
||||||
assertTrue(page.getByLabelText("Subscribe to newsletter").isChecked());
|
assertTrue(page.getByLabel("Subscribe to newsletter").isChecked());
|
||||||
|
|
||||||
// Select the radio button
|
// Select the radio button
|
||||||
page.getByLabelText("XL").check();
|
page.getByLabel("XL").check();
|
||||||
```
|
```
|
||||||
|
|
||||||
```python async
|
```python async
|
||||||
# Check the checkbox
|
# Check the checkbox
|
||||||
await page.get_by_label_text('I agree to the terms above').check()
|
await page.get_by_label('I agree to the terms above').check()
|
||||||
|
|
||||||
# Assert the checked state
|
# Assert the checked state
|
||||||
assert await page.get_by_label_text('Subscribe to newsletter').is_checked() is True
|
assert await page.get_by_label('Subscribe to newsletter').is_checked() is True
|
||||||
|
|
||||||
# Select the radio button
|
# Select the radio button
|
||||||
await page.get_by_label_text('XL').check()
|
await page.get_by_label('XL').check()
|
||||||
```
|
```
|
||||||
|
|
||||||
```python sync
|
```python sync
|
||||||
# Check the checkbox
|
# Check the checkbox
|
||||||
page.get_by_label_text('I agree to the terms above').check()
|
page.get_by_label('I agree to the terms above').check()
|
||||||
|
|
||||||
# Assert the checked state
|
# Assert the checked state
|
||||||
assert page.get_by_label_text('Subscribe to newsletter').is_checked() is True
|
assert page.get_by_label('Subscribe to newsletter').is_checked() is True
|
||||||
|
|
||||||
# Select the radio button
|
# Select the radio button
|
||||||
page.get_by_label_text('XL').check()
|
page.get_by_label('XL').check()
|
||||||
```
|
```
|
||||||
|
|
||||||
```csharp
|
```csharp
|
||||||
// Check the checkbox
|
// Check the checkbox
|
||||||
await page.GetByLabelText("I agree to the terms above").CheckAsync();
|
await page.GetByLabel("I agree to the terms above").CheckAsync();
|
||||||
|
|
||||||
// Assert the checked state
|
// Assert the checked state
|
||||||
Assert.True(await page.GetByLabelText("Subscribe to newsletter").IsCheckedAsync());
|
Assert.True(await page.GetByLabel("Subscribe to newsletter").IsCheckedAsync());
|
||||||
|
|
||||||
// Select the radio button
|
// Select the radio button
|
||||||
await page.GetByLabelText("XL").CheckAsync();
|
await page.GetByLabel("XL").CheckAsync();
|
||||||
```
|
```
|
||||||
|
|
||||||
## Select options
|
## Select options
|
||||||
|
|
@ -145,57 +145,57 @@ You can specify option `value`, or `label` to select. Multiple options can be se
|
||||||
|
|
||||||
```js
|
```js
|
||||||
// Single selection matching the value
|
// Single selection matching the value
|
||||||
await page.getByLabelText('Choose a color').selectOption('blue');
|
await page.getByLabel('Choose a color').selectOption('blue');
|
||||||
|
|
||||||
// Single selection matching the label
|
// Single selection matching the label
|
||||||
await page.getByLabelText('Choose a color').selectOption({ label: 'Blue' });
|
await page.getByLabel('Choose a color').selectOption({ label: 'Blue' });
|
||||||
|
|
||||||
// Multiple selected items
|
// Multiple selected items
|
||||||
await page.getByLabelText('Choose multiple colors').selectOption(['red', 'green', 'blue']);
|
await page.getByLabel('Choose multiple colors').selectOption(['red', 'green', 'blue']);
|
||||||
```
|
```
|
||||||
|
|
||||||
```java
|
```java
|
||||||
// Single selection matching the value
|
// Single selection matching the value
|
||||||
page.getByLabelText("Choose a color").selectOption("blue");
|
page.getByLabel("Choose a color").selectOption("blue");
|
||||||
|
|
||||||
// Single selection matching the label
|
// Single selection matching the label
|
||||||
page.getByLabelText("Choose a color").selectOption(new SelectOption().setLabel("Blue"));
|
page.getByLabel("Choose a color").selectOption(new SelectOption().setLabel("Blue"));
|
||||||
|
|
||||||
// Multiple selected items
|
// Multiple selected items
|
||||||
page.getByLabelText("Choose multiple colors").selectOption(new String[] {"red", "green", "blue"});
|
page.getByLabel("Choose multiple colors").selectOption(new String[] {"red", "green", "blue"});
|
||||||
```
|
```
|
||||||
|
|
||||||
```python async
|
```python async
|
||||||
# Single selection matching the value
|
# Single selection matching the value
|
||||||
await page.get_by_label_text('Choose a color').select_option('blue')
|
await page.get_by_label('Choose a color').select_option('blue')
|
||||||
|
|
||||||
# Single selection matching the label
|
# Single selection matching the label
|
||||||
await page.get_by_label_text('Choose a color').select_option(label='Blue')
|
await page.get_by_label('Choose a color').select_option(label='Blue')
|
||||||
|
|
||||||
# Multiple selected items
|
# Multiple selected items
|
||||||
await page.get_by_label_text('Choose multiple colors').select_option(['red', 'green', 'blue'])
|
await page.get_by_label('Choose multiple colors').select_option(['red', 'green', 'blue'])
|
||||||
```
|
```
|
||||||
|
|
||||||
```python sync
|
```python sync
|
||||||
# Single selection matching the value
|
# Single selection matching the value
|
||||||
page.get_by_label_text('Choose a color').select_option('blue')
|
page.get_by_label('Choose a color').select_option('blue')
|
||||||
|
|
||||||
# Single selection matching the label
|
# Single selection matching the label
|
||||||
page.get_by_label_text('Choose a color').select_option(label='Blue')
|
page.get_by_label('Choose a color').select_option(label='Blue')
|
||||||
|
|
||||||
# Multiple selected items
|
# Multiple selected items
|
||||||
page.get_by_label_text('Choose multiple colors').select_option(['red', 'green', 'blue'])
|
page.get_by_label('Choose multiple colors').select_option(['red', 'green', 'blue'])
|
||||||
```
|
```
|
||||||
|
|
||||||
```csharp
|
```csharp
|
||||||
// Single selection matching the value
|
// Single selection matching the value
|
||||||
await page.GetByLabelText("Choose a color").SelectOptionAsync("blue");
|
await page.GetByLabel("Choose a color").SelectOptionAsync("blue");
|
||||||
|
|
||||||
// Single selection matching the label
|
// Single selection matching the label
|
||||||
await page.GetByLabelText("Choose a color").SelectOptionAsync(new SelectOptionValue { Label = "blue" }));
|
await page.GetByLabel("Choose a color").SelectOptionAsync(new SelectOptionValue { Label = "blue" }));
|
||||||
|
|
||||||
// Multiple selected items
|
// Multiple selected items
|
||||||
await page.GetByLabelText("Choose multiple colors").SelectOptionAsync(new[] { "blue", "green", "red" });
|
await page.GetByLabel("Choose multiple colors").SelectOptionAsync(new[] { "blue", "green", "red" });
|
||||||
```
|
```
|
||||||
|
|
||||||
## Mouse click
|
## Mouse click
|
||||||
|
|
@ -516,16 +516,16 @@ You can select input files for upload using the [`method: Locator.setInputFiles`
|
||||||
|
|
||||||
```js
|
```js
|
||||||
// Select one file
|
// Select one file
|
||||||
await page.getByLabelText('Upload file').setInputFiles('myfile.pdf');
|
await page.getByLabel('Upload file').setInputFiles('myfile.pdf');
|
||||||
|
|
||||||
// Select multiple files
|
// Select multiple files
|
||||||
await page.getByLabelText('Upload files').setInputFiles(['file1.txt', 'file2.txt']);
|
await page.getByLabel('Upload files').setInputFiles(['file1.txt', 'file2.txt']);
|
||||||
|
|
||||||
// Remove all the selected files
|
// Remove all the selected files
|
||||||
await page.getByLabelText('Upload file').setInputFiles([]);
|
await page.getByLabel('Upload file').setInputFiles([]);
|
||||||
|
|
||||||
// Upload buffer from memory
|
// Upload buffer from memory
|
||||||
await page.getByLabelText('Upload file').setInputFiles({
|
await page.getByLabel('Upload file').setInputFiles({
|
||||||
name: 'file.txt',
|
name: 'file.txt',
|
||||||
mimeType: 'text/plain',
|
mimeType: 'text/plain',
|
||||||
buffer: Buffer.from('this is test')
|
buffer: Buffer.from('this is test')
|
||||||
|
|
@ -534,31 +534,31 @@ await page.getByLabelText('Upload file').setInputFiles({
|
||||||
|
|
||||||
```java
|
```java
|
||||||
// Select one file
|
// Select one file
|
||||||
page.getByLabelText("Upload file").setInputFiles(Paths.get("myfile.pdf"));
|
page.getByLabel("Upload file").setInputFiles(Paths.get("myfile.pdf"));
|
||||||
|
|
||||||
// Select multiple files
|
// Select multiple files
|
||||||
page.getByLabelText("Upload files").setInputFiles(new Path[] {Paths.get("file1.txt"), Paths.get("file2.txt")});
|
page.getByLabel("Upload files").setInputFiles(new Path[] {Paths.get("file1.txt"), Paths.get("file2.txt")});
|
||||||
|
|
||||||
// Remove all the selected files
|
// Remove all the selected files
|
||||||
page.getByLabelText("Upload file").setInputFiles(new Path[0]);
|
page.getByLabel("Upload file").setInputFiles(new Path[0]);
|
||||||
|
|
||||||
// Upload buffer from memory
|
// Upload buffer from memory
|
||||||
page.getByLabelText("Upload file").setInputFiles(new FilePayload(
|
page.getByLabel("Upload file").setInputFiles(new FilePayload(
|
||||||
"file.txt", "text/plain", "this is test".getBytes(StandardCharsets.UTF_8)));
|
"file.txt", "text/plain", "this is test".getBytes(StandardCharsets.UTF_8)));
|
||||||
```
|
```
|
||||||
|
|
||||||
```python async
|
```python async
|
||||||
# Select one file
|
# Select one file
|
||||||
await page.get_by_label_text("Upload file").set_input_files('myfile.pdf')
|
await page.get_by_label("Upload file").set_input_files('myfile.pdf')
|
||||||
|
|
||||||
# Select multiple files
|
# Select multiple files
|
||||||
await page.get_by_label_text("Upload files").set_input_files(['file1.txt', 'file2.txt'])
|
await page.get_by_label("Upload files").set_input_files(['file1.txt', 'file2.txt'])
|
||||||
|
|
||||||
# Remove all the selected files
|
# Remove all the selected files
|
||||||
await page.get_by_label_text("Upload file").set_input_files([])
|
await page.get_by_label("Upload file").set_input_files([])
|
||||||
|
|
||||||
# Upload buffer from memory
|
# Upload buffer from memory
|
||||||
await page.get_by_label_text("Upload file").set_input_files(
|
await page.get_by_label("Upload file").set_input_files(
|
||||||
files=[
|
files=[
|
||||||
{"name": "test.txt", "mimeType": "text/plain", "buffer": b"this is a test"}
|
{"name": "test.txt", "mimeType": "text/plain", "buffer": b"this is a test"}
|
||||||
],
|
],
|
||||||
|
|
@ -567,16 +567,16 @@ await page.get_by_label_text("Upload file").set_input_files(
|
||||||
|
|
||||||
```python sync
|
```python sync
|
||||||
# Select one file
|
# Select one file
|
||||||
page.get_by_label_text("Upload file").set_input_files('myfile.pdf')
|
page.get_by_label("Upload file").set_input_files('myfile.pdf')
|
||||||
|
|
||||||
# Select multiple files
|
# Select multiple files
|
||||||
page.get_by_label_text("Upload files").set_input_files(['file1.txt', 'file2.txt'])
|
page.get_by_label("Upload files").set_input_files(['file1.txt', 'file2.txt'])
|
||||||
|
|
||||||
# Remove all the selected files
|
# Remove all the selected files
|
||||||
page.get_by_label_text("Upload file").set_input_files([])
|
page.get_by_label("Upload file").set_input_files([])
|
||||||
|
|
||||||
# Upload buffer from memory
|
# Upload buffer from memory
|
||||||
page.get_by_label_text("Upload file").set_input_files(
|
page.get_by_label("Upload file").set_input_files(
|
||||||
files=[
|
files=[
|
||||||
{"name": "test.txt", "mimeType": "text/plain", "buffer": b"this is a test"}
|
{"name": "test.txt", "mimeType": "text/plain", "buffer": b"this is a test"}
|
||||||
],
|
],
|
||||||
|
|
@ -585,16 +585,16 @@ page.get_by_label_text("Upload file").set_input_files(
|
||||||
|
|
||||||
```csharp
|
```csharp
|
||||||
// Select one file
|
// Select one file
|
||||||
await page.GetByLabelText("Upload file").SetInputFilesAsync("myfile.pdf");
|
await page.GetByLabel("Upload file").SetInputFilesAsync("myfile.pdf");
|
||||||
|
|
||||||
// Select multiple files
|
// Select multiple files
|
||||||
await page.GetByLabelText("Upload files").SetInputFilesAsync(new[] { "file1.txt", "file12.txt" });
|
await page.GetByLabel("Upload files").SetInputFilesAsync(new[] { "file1.txt", "file12.txt" });
|
||||||
|
|
||||||
// Remove all the selected files
|
// Remove all the selected files
|
||||||
await page.GetByLabelText("Upload file").SetInputFilesAsync(new[] {});
|
await page.GetByLabel("Upload file").SetInputFilesAsync(new[] {});
|
||||||
|
|
||||||
// Upload buffer from memory
|
// Upload buffer from memory
|
||||||
await page.GetByLabelText("Upload file").SetInputFilesAsync(new FilePayload
|
await page.GetByLabel("Upload file").SetInputFilesAsync(new FilePayload
|
||||||
{
|
{
|
||||||
Name = "file.txt",
|
Name = "file.txt",
|
||||||
MimeType = "text/plain",
|
MimeType = "text/plain",
|
||||||
|
|
@ -650,23 +650,23 @@ await fileChooser.SetFilesAsync("myfile.pdf");
|
||||||
For the dynamic pages that handle focus events, you can focus the given element with [`method: Locator.focus`].
|
For the dynamic pages that handle focus events, you can focus the given element with [`method: Locator.focus`].
|
||||||
|
|
||||||
```js
|
```js
|
||||||
await page.getByLabelText('Password').focus();
|
await page.getByLabel('Password').focus();
|
||||||
```
|
```
|
||||||
|
|
||||||
```java
|
```java
|
||||||
page.getByLabelText("Password").focus();
|
page.getByLabel("Password").focus();
|
||||||
```
|
```
|
||||||
|
|
||||||
```python async
|
```python async
|
||||||
await page.get_by_label_text('password').focus()
|
await page.get_by_label('password').focus()
|
||||||
```
|
```
|
||||||
|
|
||||||
```python sync
|
```python sync
|
||||||
page.get_by_label_text('password').focus()
|
page.get_by_label('password').focus()
|
||||||
```
|
```
|
||||||
|
|
||||||
```csharp
|
```csharp
|
||||||
await page.GetByLabelText("Password").FocusAsync();
|
await page.GetByLabel("Password").FocusAsync();
|
||||||
```
|
```
|
||||||
|
|
||||||
## Drag and Drop
|
## Drag and Drop
|
||||||
|
|
|
||||||
|
|
@ -162,7 +162,7 @@ By default, [`method: Locator.click`] will wait for the navigation step to compl
|
||||||
await page.getByText('Login').click();
|
await page.getByText('Login').click();
|
||||||
|
|
||||||
// Fill will auto-wait for element on navigated page
|
// Fill will auto-wait for element on navigated page
|
||||||
await page.getByLabelText('User Name').fill('John Doe');
|
await page.getByLabel('User Name').fill('John Doe');
|
||||||
```
|
```
|
||||||
|
|
||||||
```java
|
```java
|
||||||
|
|
@ -170,7 +170,7 @@ await page.getByLabelText('User Name').fill('John Doe');
|
||||||
page.getByText("Login").click();
|
page.getByText("Login").click();
|
||||||
|
|
||||||
// Fill will auto-wait for element on navigated page
|
// Fill will auto-wait for element on navigated page
|
||||||
page.getByLabelText("User Name").fill("John Doe");
|
page.getByLabel("User Name").fill("John Doe");
|
||||||
```
|
```
|
||||||
|
|
||||||
```python async
|
```python async
|
||||||
|
|
@ -178,7 +178,7 @@ page.getByLabelText("User Name").fill("John Doe");
|
||||||
await page.get_by_text("Login").click()
|
await page.get_by_text("Login").click()
|
||||||
|
|
||||||
# Fill will auto-wait for element on navigated page
|
# Fill will auto-wait for element on navigated page
|
||||||
await page.get_by_label_text("User Name").fill("John Doe")
|
await page.get_by_label("User Name").fill("John Doe")
|
||||||
```
|
```
|
||||||
|
|
||||||
```python sync
|
```python sync
|
||||||
|
|
@ -186,7 +186,7 @@ await page.get_by_label_text("User Name").fill("John Doe")
|
||||||
page.get_by_text("Login").click()
|
page.get_by_text("Login").click()
|
||||||
|
|
||||||
# Fill will auto-wait for element on navigated page
|
# Fill will auto-wait for element on navigated page
|
||||||
page.get_by_label_text("User Name").fill("John Doe")
|
page.get_by_label("User Name").fill("John Doe")
|
||||||
```
|
```
|
||||||
|
|
||||||
```csharp
|
```csharp
|
||||||
|
|
@ -194,7 +194,7 @@ page.get_by_label_text("User Name").fill("John Doe")
|
||||||
await page.GetByText("Login").ClickAsync();
|
await page.GetByText("Login").ClickAsync();
|
||||||
|
|
||||||
// Fill will auto-wait for element on navigated page
|
// Fill will auto-wait for element on navigated page
|
||||||
await page.GetByLabelText("User Name").FillAsync("John Doe");
|
await page.GetByLabel("User Name").FillAsync("John Doe");
|
||||||
```
|
```
|
||||||
|
|
||||||
### Custom wait
|
### Custom wait
|
||||||
|
|
@ -235,60 +235,60 @@ Alternatively, page interactions like [`method: Locator.click`] auto-wait for el
|
||||||
// Click will auto-wait for the element and trigger navigation
|
// Click will auto-wait for the element and trigger navigation
|
||||||
await page.getByText('Login').click();
|
await page.getByText('Login').click();
|
||||||
// Wait for the element
|
// Wait for the element
|
||||||
await page.getByLabelText('User Name').waitFor();
|
await page.getByLabel('User Name').waitFor();
|
||||||
|
|
||||||
// Click triggers navigation
|
// Click triggers navigation
|
||||||
await page.getByText('Login').click();
|
await page.getByText('Login').click();
|
||||||
// Fill will auto-wait for element
|
// Fill will auto-wait for element
|
||||||
await page.getByLabelText('User Name').fill('John Doe');
|
await page.getByLabel('User Name').fill('John Doe');
|
||||||
```
|
```
|
||||||
|
|
||||||
```java
|
```java
|
||||||
// Click will auto-wait for the element and trigger navigation
|
// Click will auto-wait for the element and trigger navigation
|
||||||
page.getByText("Login").click();
|
page.getByText("Login").click();
|
||||||
// Wait for the element
|
// Wait for the element
|
||||||
page.getByLabelText("User Name").waitFor();
|
page.getByLabel("User Name").waitFor();
|
||||||
|
|
||||||
// Click triggers navigation
|
// Click triggers navigation
|
||||||
page.getByText("Login").click();
|
page.getByText("Login").click();
|
||||||
// Fill will auto-wait for element
|
// Fill will auto-wait for element
|
||||||
page.getByLabelText("User Name").fill("John Doe");
|
page.getByLabel("User Name").fill("John Doe");
|
||||||
```
|
```
|
||||||
|
|
||||||
```python async
|
```python async
|
||||||
# Click will auto-wait for the element and trigger navigation
|
# Click will auto-wait for the element and trigger navigation
|
||||||
await page.get_by_text("Login").click()
|
await page.get_by_text("Login").click()
|
||||||
# Wait for the element
|
# Wait for the element
|
||||||
await page.get_by_label_text("User Name").wait_for()
|
await page.get_by_label("User Name").wait_for()
|
||||||
|
|
||||||
# Click triggers navigation
|
# Click triggers navigation
|
||||||
await page.get_by_text("Login").click()
|
await page.get_by_text("Login").click()
|
||||||
# Fill will auto-wait for element
|
# Fill will auto-wait for element
|
||||||
await page.get_by_label_text("User Name").fill("John Doe")
|
await page.get_by_label("User Name").fill("John Doe")
|
||||||
```
|
```
|
||||||
|
|
||||||
```python sync
|
```python sync
|
||||||
# Click triggers navigation
|
# Click triggers navigation
|
||||||
page.get_by_text("Login").click()
|
page.get_by_text("Login").click()
|
||||||
# Click will auto-wait for the element
|
# Click will auto-wait for the element
|
||||||
page.get_by_label_text("User Name").wait_for()
|
page.get_by_label("User Name").wait_for()
|
||||||
|
|
||||||
# Click triggers navigation
|
# Click triggers navigation
|
||||||
page.get_by_text("Login").click()
|
page.get_by_text("Login").click()
|
||||||
# Fill will auto-wait for element
|
# Fill will auto-wait for element
|
||||||
page.get_by_label_text("User Name").fill("John Doe")
|
page.get_by_label("User Name").fill("John Doe")
|
||||||
```
|
```
|
||||||
|
|
||||||
```csharp
|
```csharp
|
||||||
// Click will auto-wait for the element and trigger navigation
|
// Click will auto-wait for the element and trigger navigation
|
||||||
await page.GetByText("Login").ClickAsync();
|
await page.GetByText("Login").ClickAsync();
|
||||||
// Wait for the element
|
// Wait for the element
|
||||||
await page.GetByLabelText("User Name").WaitForAsync();
|
await page.GetByLabel("User Name").WaitForAsync();
|
||||||
|
|
||||||
// Click triggers navigation
|
// Click triggers navigation
|
||||||
await page.GetByText("Login").ClickAsync();
|
await page.GetByText("Login").ClickAsync();
|
||||||
// Fill will auto-wait for element
|
// Fill will auto-wait for element
|
||||||
await page.GetByLabelText("User Name").FillAsync("John Doe");
|
await page.GetByLabel("User Name").FillAsync("John Doe");
|
||||||
```
|
```
|
||||||
|
|
||||||
### Asynchronous navigation
|
### Asynchronous navigation
|
||||||
|
|
|
||||||
|
|
@ -224,8 +224,8 @@ module.exports = async config => {
|
||||||
const browser = await chromium.launch();
|
const browser = await chromium.launch();
|
||||||
const page = await browser.newPage();
|
const page = await browser.newPage();
|
||||||
await page.goto(baseURL);
|
await page.goto(baseURL);
|
||||||
await page.getByLabelText('User Name').fill('user');
|
await page.getByLabel('User Name').fill('user');
|
||||||
await page.getByLabelText('Password').fill('password');
|
await page.getByLabel('Password').fill('password');
|
||||||
await page.getByText('Sign in').click();
|
await page.getByText('Sign in').click();
|
||||||
await page.context().storageState({ path: storageState });
|
await page.context().storageState({ path: storageState });
|
||||||
await browser.close();
|
await browser.close();
|
||||||
|
|
@ -241,8 +241,8 @@ async function globalSetup(config: FullConfig) {
|
||||||
const browser = await chromium.launch();
|
const browser = await chromium.launch();
|
||||||
const page = await browser.newPage();
|
const page = await browser.newPage();
|
||||||
await page.goto(baseURL!);
|
await page.goto(baseURL!);
|
||||||
await page.getByLabelText('User Name').fill('user');
|
await page.getByLabel('User Name').fill('user');
|
||||||
await page.getByLabelText('Password').fill('password');
|
await page.getByLabel('Password').fill('password');
|
||||||
await page.getByText('Sign in').click();
|
await page.getByText('Sign in').click();
|
||||||
await page.context().storageState({ path: storageState as string });
|
await page.context().storageState({ path: storageState as string });
|
||||||
await browser.close();
|
await browser.close();
|
||||||
|
|
@ -373,8 +373,8 @@ module.exports = async config => {
|
||||||
try {
|
try {
|
||||||
await context.tracing.start({ screenshots: true, snapshots: true });
|
await context.tracing.start({ screenshots: true, snapshots: true });
|
||||||
await page.goto(baseURL);
|
await page.goto(baseURL);
|
||||||
await page.getByLabelText('User Name').fill('user');
|
await page.getByLabel('User Name').fill('user');
|
||||||
await page.getByLabelText('Password').fill('password');
|
await page.getByLabel('Password').fill('password');
|
||||||
await page.getByText('Sign in').click();
|
await page.getByText('Sign in').click();
|
||||||
await context.storageState({ path: storageState });
|
await context.storageState({ path: storageState });
|
||||||
await context.tracing.stop({
|
await context.tracing.stop({
|
||||||
|
|
@ -403,8 +403,8 @@ async function globalSetup(config: FullConfig) {
|
||||||
try {
|
try {
|
||||||
await context.tracing.start({ screenshots: true, snapshots: true });
|
await context.tracing.start({ screenshots: true, snapshots: true });
|
||||||
await page.goto(baseURL!);
|
await page.goto(baseURL!);
|
||||||
await page.getByLabelText('User Name').fill('user');
|
await page.getByLabel('User Name').fill('user');
|
||||||
await page.getByLabelText('Password').fill('password');
|
await page.getByLabel('Password').fill('password');
|
||||||
await page.getByText('Sign in').click();
|
await page.getByText('Sign in').click();
|
||||||
await context.storageState({ path: storageState as string });
|
await context.storageState({ path: storageState as string });
|
||||||
await context.tracing.stop({
|
await context.tracing.stop({
|
||||||
|
|
|
||||||
|
|
@ -77,8 +77,8 @@ const { test, expect } = require('@playwright/test');
|
||||||
|
|
||||||
test('basic test', async ({ page }) => {
|
test('basic test', async ({ page }) => {
|
||||||
await page.goto('/signin');
|
await page.goto('/signin');
|
||||||
await page.getByLabelText('User Name').fill('user');
|
await page.getByLabel('User Name').fill('user');
|
||||||
await page.getByLabelText('Password').fill('password');
|
await page.getByLabel('Password').fill('password');
|
||||||
await page.getByText('Sign in').click();
|
await page.getByText('Sign in').click();
|
||||||
// ...
|
// ...
|
||||||
});
|
});
|
||||||
|
|
@ -89,8 +89,8 @@ import { test, expect } from '@playwright/test';
|
||||||
|
|
||||||
test('basic test', async ({ page }) => {
|
test('basic test', async ({ page }) => {
|
||||||
await page.goto('/signin');
|
await page.goto('/signin');
|
||||||
await page.getByLabelText('User Name').fill('user');
|
await page.getByLabel('User Name').fill('user');
|
||||||
await page.getByLabelText('Password').fill('password');
|
await page.getByLabel('Password').fill('password');
|
||||||
await page.getByText('Sign in').click();
|
await page.getByText('Sign in').click();
|
||||||
// ...
|
// ...
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -24,8 +24,8 @@ test.beforeEach(async ({ page }) => {
|
||||||
// Runs before each test and signs in each page.
|
// Runs before each test and signs in each page.
|
||||||
await page.goto('https://github.com/login');
|
await page.goto('https://github.com/login');
|
||||||
await page.getByText('Login').click();
|
await page.getByText('Login').click();
|
||||||
await page.getByLabelText('User Name').fill('user');
|
await page.getByLabel('User Name').fill('user');
|
||||||
await page.getByLabelText('Password').fill('password');
|
await page.getByLabel('Password').fill('password');
|
||||||
await page.getByText('Submit').click();
|
await page.getByText('Submit').click();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -45,8 +45,8 @@ test.beforeEach(async ({ page }) => {
|
||||||
// Runs before each test and signs in each page.
|
// Runs before each test and signs in each page.
|
||||||
await page.goto('https://github.com/login');
|
await page.goto('https://github.com/login');
|
||||||
await page.getByText('Login').click();
|
await page.getByText('Login').click();
|
||||||
await page.getByLabelText('User Name').fill('user');
|
await page.getByLabel('User Name').fill('user');
|
||||||
await page.getByLabelText('Password').fill('password');
|
await page.getByLabel('Password').fill('password');
|
||||||
await page.getByText('Sign in').click();
|
await page.getByText('Sign in').click();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -77,8 +77,8 @@ module.exports = async config => {
|
||||||
const browser = await chromium.launch();
|
const browser = await chromium.launch();
|
||||||
const page = await browser.newPage();
|
const page = await browser.newPage();
|
||||||
await page.goto('https://github.com/login');
|
await page.goto('https://github.com/login');
|
||||||
await page.getByLabelText('User Name').fill('user');
|
await page.getByLabel('User Name').fill('user');
|
||||||
await page.getByLabelText('Password').fill('password');
|
await page.getByLabel('Password').fill('password');
|
||||||
await page.getByText('Sign in').click();
|
await page.getByText('Sign in').click();
|
||||||
// Save signed-in state to 'storageState.json'.
|
// Save signed-in state to 'storageState.json'.
|
||||||
await page.context().storageState({ path: 'storageState.json' });
|
await page.context().storageState({ path: 'storageState.json' });
|
||||||
|
|
@ -94,8 +94,8 @@ async function globalSetup(config: FullConfig) {
|
||||||
const browser = await chromium.launch();
|
const browser = await chromium.launch();
|
||||||
const page = await browser.newPage();
|
const page = await browser.newPage();
|
||||||
await page.goto('https://github.com/login');
|
await page.goto('https://github.com/login');
|
||||||
await page.getByLabelText('User Name').fill('user');
|
await page.getByLabel('User Name').fill('user');
|
||||||
await page.getByLabelText('Password').fill('password');
|
await page.getByLabel('Password').fill('password');
|
||||||
await page.getByText('Sign in').click();
|
await page.getByText('Sign in').click();
|
||||||
// Save signed-in state to 'storageState.json'.
|
// Save signed-in state to 'storageState.json'.
|
||||||
await page.context().storageState({ path: 'storageState.json' });
|
await page.context().storageState({ path: 'storageState.json' });
|
||||||
|
|
@ -226,8 +226,8 @@ exports.test = base.extend({
|
||||||
// Make sure we are not using any other storage state.
|
// Make sure we are not using any other storage state.
|
||||||
const page = await browser.newPage({ storageState: undefined });
|
const page = await browser.newPage({ storageState: undefined });
|
||||||
await page.goto('https://github.com/login');
|
await page.goto('https://github.com/login');
|
||||||
await page.getByLabelText('User Name').fill(users[testInfo.workerIndex].username);
|
await page.getByLabel('User Name').fill(users[testInfo.workerIndex].username);
|
||||||
await page.getByLabelText('Password').fill(users[testInfo.workerIndex].password);
|
await page.getByLabel('Password').fill(users[testInfo.workerIndex].password);
|
||||||
await page.getByText('Sign in').click();
|
await page.getByText('Sign in').click();
|
||||||
await page.context().storageState({ path: fileName });
|
await page.context().storageState({ path: fileName });
|
||||||
await page.close();
|
await page.close();
|
||||||
|
|
@ -265,8 +265,8 @@ export const test = baseTest.extend({
|
||||||
const page = await browser.newPage({ storageState: undefined });
|
const page = await browser.newPage({ storageState: undefined });
|
||||||
await page.goto('https://github.com/login');
|
await page.goto('https://github.com/login');
|
||||||
// Create a unique username for each worker.
|
// Create a unique username for each worker.
|
||||||
await page.getByLabelText('User Name').fill(users[testInfo.workerIndex].username);
|
await page.getByLabel('User Name').fill(users[testInfo.workerIndex].username);
|
||||||
await page.getByLabelText('Password').fill(users[testInfo.workerIndex].password);
|
await page.getByLabel('Password').fill(users[testInfo.workerIndex].password);
|
||||||
await page.getByText('Sign in').click();
|
await page.getByText('Sign in').click();
|
||||||
await page.context().storageState({ path: fileName });
|
await page.context().storageState({ path: fileName });
|
||||||
await page.close();
|
await page.close();
|
||||||
|
|
@ -558,8 +558,8 @@ test.beforeAll(async ({ browser }) => {
|
||||||
// Create page yourself and sign in.
|
// Create page yourself and sign in.
|
||||||
page = await browser.newPage();
|
page = await browser.newPage();
|
||||||
await page.goto('https://github.com/login');
|
await page.goto('https://github.com/login');
|
||||||
await page.getByLabelText('User Name').fill('user');
|
await page.getByLabel('User Name').fill('user');
|
||||||
await page.getByLabelText('Password').fill('password');
|
await page.getByLabel('Password').fill('password');
|
||||||
await page.getByText('Sign in').click();
|
await page.getByText('Sign in').click();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -589,8 +589,8 @@ test.beforeAll(async ({ browser }) => {
|
||||||
// Create page once and sign in.
|
// Create page once and sign in.
|
||||||
page = await browser.newPage();
|
page = await browser.newPage();
|
||||||
await page.goto('https://github.com/login');
|
await page.goto('https://github.com/login');
|
||||||
await page.getByLabelText('User Name').fill('user');
|
await page.getByLabel('User Name').fill('user');
|
||||||
await page.getByLabelText('Password').fill('password');
|
await page.getByLabel('Password').fill('password');
|
||||||
await page.getByText('Sign in').click();
|
await page.getByText('Sign in').click();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -334,8 +334,8 @@ exports.test = base.test.extend({
|
||||||
// Create the account with Playwright.
|
// Create the account with Playwright.
|
||||||
const page = await browser.newPage();
|
const page = await browser.newPage();
|
||||||
await page.goto('/signup');
|
await page.goto('/signup');
|
||||||
await page.getByLabelText('User Name').fill(username);
|
await page.getByLabel('User Name').fill(username);
|
||||||
await page.getByLabelText('Password').fill(password);
|
await page.getByLabel('Password').fill(password);
|
||||||
await page.getByText('Sign up').click();
|
await page.getByText('Sign up').click();
|
||||||
// Make sure everything is ok.
|
// Make sure everything is ok.
|
||||||
await expect(page.locator('#result')).toHaveText('Success');
|
await expect(page.locator('#result')).toHaveText('Success');
|
||||||
|
|
@ -350,8 +350,8 @@ exports.test = base.test.extend({
|
||||||
// Sign in with our account.
|
// Sign in with our account.
|
||||||
const { username, password } = account;
|
const { username, password } = account;
|
||||||
await page.goto('/signin');
|
await page.goto('/signin');
|
||||||
await page.getByLabelText('User Name').fill(username);
|
await page.getByLabel('User Name').fill(username);
|
||||||
await page.getByLabelText('Password').fill(password);
|
await page.getByLabel('Password').fill(password);
|
||||||
await page.getByText('Sign in').click();
|
await page.getByText('Sign in').click();
|
||||||
await expect(page.locator('#userinfo')).toHaveText(username);
|
await expect(page.locator('#userinfo')).toHaveText(username);
|
||||||
|
|
||||||
|
|
@ -381,8 +381,8 @@ export const test = base.extend<{}, { account: Account }>({
|
||||||
// Create the account with Playwright.
|
// Create the account with Playwright.
|
||||||
const page = await browser.newPage();
|
const page = await browser.newPage();
|
||||||
await page.goto('/signup');
|
await page.goto('/signup');
|
||||||
await page.getByLabelText('User Name').fill(username);
|
await page.getByLabel('User Name').fill(username);
|
||||||
await page.getByLabelText('Password').fill(password);
|
await page.getByLabel('Password').fill(password);
|
||||||
await page.getByText('Sign up').click();
|
await page.getByText('Sign up').click();
|
||||||
// Make sure everything is ok.
|
// Make sure everything is ok.
|
||||||
await expect(page.locator('#result')).toHaveText('Success');
|
await expect(page.locator('#result')).toHaveText('Success');
|
||||||
|
|
@ -397,8 +397,8 @@ export const test = base.extend<{}, { account: Account }>({
|
||||||
// Sign in with our account.
|
// Sign in with our account.
|
||||||
const { username, password } = account;
|
const { username, password } = account;
|
||||||
await page.goto('/signin');
|
await page.goto('/signin');
|
||||||
await page.getByLabelText('User Name').fill(username);
|
await page.getByLabel('User Name').fill(username);
|
||||||
await page.getByLabelText('Password').fill(password);
|
await page.getByLabel('Password').fill(password);
|
||||||
await page.getByText('Sign in').click();
|
await page.getByText('Sign in').click();
|
||||||
await expect(page.locator('#userinfo')).toHaveText(username);
|
await expect(page.locator('#userinfo')).toHaveText(username);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -143,7 +143,7 @@ exports.test = base.test.extend({
|
||||||
page: async ({ page, person }, use) => {
|
page: async ({ page, person }, use) => {
|
||||||
await page.goto('/chat');
|
await page.goto('/chat');
|
||||||
// We use "person" parameter as a "name" for the chat room.
|
// We use "person" parameter as a "name" for the chat room.
|
||||||
await page.getByLabelText('User Name').fill(person);
|
await page.getByLabel('User Name').fill(person);
|
||||||
await page.getByText('Enter chat room').click();
|
await page.getByText('Enter chat room').click();
|
||||||
// Each test will get a "page" that already has the person name.
|
// Each test will get a "page" that already has the person name.
|
||||||
await use(page);
|
await use(page);
|
||||||
|
|
@ -168,7 +168,7 @@ export const test = base.test.extend<TestOptions>({
|
||||||
page: async ({ page, person }, use) => {
|
page: async ({ page, person }, use) => {
|
||||||
await page.goto('/chat');
|
await page.goto('/chat');
|
||||||
// We use "person" parameter as a "name" for the chat room.
|
// We use "person" parameter as a "name" for the chat room.
|
||||||
await page.getByLabelText('User Name').fill(person);
|
await page.getByLabel('User Name').fill(person);
|
||||||
await page.getByText('Enter chat room').click();
|
await page.getByText('Enter chat room').click();
|
||||||
// Each test will get a "page" that already has the person name.
|
// Each test will get a "page" that already has the person name.
|
||||||
await use(page);
|
await use(page);
|
||||||
|
|
@ -190,8 +190,8 @@ For example, consider the following test file that needs a username and a passwo
|
||||||
// example.spec.js
|
// example.spec.js
|
||||||
test(`example test`, async ({ page }) => {
|
test(`example test`, async ({ page }) => {
|
||||||
// ...
|
// ...
|
||||||
await page.getByLabelText('User Name').fill(process.env.USERNAME);
|
await page.getByLabel('User Name').fill(process.env.USERNAME);
|
||||||
await page.getByLabelText('Password').fill(process.env.PASSWORD);
|
await page.getByLabel('Password').fill(process.env.PASSWORD);
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
@ -199,8 +199,8 @@ test(`example test`, async ({ page }) => {
|
||||||
// example.spec.ts
|
// example.spec.ts
|
||||||
test(`example test`, async ({ page }) => {
|
test(`example test`, async ({ page }) => {
|
||||||
// ...
|
// ...
|
||||||
await page.getByLabelText('User Name').fill(process.env.USERNAME);
|
await page.getByLabel('User Name').fill(process.env.USERNAME);
|
||||||
await page.getByLabelText('Password').fill(process.env.PASSWORD);
|
await page.getByLabel('Password').fill(process.env.PASSWORD);
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,8 +25,8 @@ import { test, expect } from '@playwright/test';
|
||||||
import { username, password } from './helper';
|
import { username, password } from './helper';
|
||||||
|
|
||||||
test('example', async ({ page }) => {
|
test('example', async ({ page }) => {
|
||||||
await page.getByLabelText('User Name').fill(username);
|
await page.getByLabel('User Name').fill(username);
|
||||||
await page.getByLabelText('Password').fill(password);
|
await page.getByLabel('Password').fill(password);
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
@ -62,8 +62,8 @@ import { test, expect } from '@playwright/test';
|
||||||
import { username, password } from './helper.ts';
|
import { username, password } from './helper.ts';
|
||||||
|
|
||||||
test('example', async ({ page }) => {
|
test('example', async ({ page }) => {
|
||||||
await page.getByLabelText('User Name').fill(username);
|
await page.getByLabel('User Name').fill(username);
|
||||||
await page.getByLabelText('Password').fill(password);
|
await page.getByLabel('Password').fill(password);
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
@ -96,8 +96,8 @@ import { test, expect } from '@playwright/test';
|
||||||
import { username, password } from '@myhelper/credentials';
|
import { username, password } from '@myhelper/credentials';
|
||||||
|
|
||||||
test('example', async ({ page }) => {
|
test('example', async ({ page }) => {
|
||||||
await page.getByLabelText('User Name').fill(username);
|
await page.getByLabel('User Name').fill(username);
|
||||||
await page.getByLabelText('Password').fill(password);
|
await page.getByLabel('Password').fill(password);
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,11 +23,11 @@ If you use DOM Testing Library in the browser (for example, you bundle end-to-en
|
||||||
| [user events](https://testing-library.com/docs/user-event/intro) | [actions](./api/class-locator) |
|
| [user events](https://testing-library.com/docs/user-event/intro) | [actions](./api/class-locator) |
|
||||||
| `await user.click(screen.getByText('Click me'))` | `await component.getByText('Click me').click()` |
|
| `await user.click(screen.getByText('Click me'))` | `await component.getByText('Click me').click()` |
|
||||||
| `await user.click(await screen.findByText('Click me'))` | `await component.getByText('Click me').click()` |
|
| `await user.click(await screen.findByText('Click me'))` | `await component.getByText('Click me').click()` |
|
||||||
| `await user.type(screen.getByLabelText('Password'), 'secret')` | `await component.getByLabelText('Password').fill('secret')` |
|
| `await user.type(screen.getByLabel('Password'), 'secret')` | `await component.getByLabel('Password').fill('secret')` |
|
||||||
| `expect(screen.getByLabelText('Password')).toHaveValue('secret')` | `await expect(component.getByLabelText('Password')).toHaveValue('secret')` |
|
| `expect(screen.getByLabel('Password')).toHaveValue('secret')` | `await expect(component.getByLabel('Password')).toHaveValue('secret')` |
|
||||||
| `screen.findByText('...')` | `component.getByText('...')` |
|
| `screen.findByText('...')` | `component.getByText('...')` |
|
||||||
| `screen.getByTestId('...')` | `component.getByTestId('...')` |
|
| `screen.getByTestId('...')` | `component.getByTestId('...')` |
|
||||||
| `screen.queryByPlaceholderText('...')` | `component.getByPlaceholderText('...')` |
|
| `screen.queryByPlaceholderText('...')` | `component.getByPlaceholder('...')` |
|
||||||
| `screen.getByRole('button', { pressed: true })` | `component.getByRole('button', { pressed: true })`|
|
| `screen.getByRole('button', { pressed: true })` | `component.getByRole('button', { pressed: true })`|
|
||||||
|
|
||||||
## Example
|
## Example
|
||||||
|
|
@ -45,8 +45,8 @@ test('should sign in', async () => {
|
||||||
render(<SignInPage />);
|
render(<SignInPage />);
|
||||||
|
|
||||||
// Perform actions.
|
// Perform actions.
|
||||||
await user.type(screen.getByLabelText('Username'), 'John');
|
await user.type(screen.getByLabel('Username'), 'John');
|
||||||
await user.type(screen.getByLabelText('Password'), 'secret');
|
await user.type(screen.getByLabel('Password'), 'secret');
|
||||||
await user.click(screen.getByText('Sign in'));
|
await user.click(screen.getByText('Sign in'));
|
||||||
|
|
||||||
// Verify signed in state by waiting until "Welcome" message appears.
|
// Verify signed in state by waiting until "Welcome" message appears.
|
||||||
|
|
|
||||||
|
|
@ -307,12 +307,12 @@ export class Frame extends ChannelOwner<channels.FrameChannel> implements api.Fr
|
||||||
return this.locator(Locator.getByAltTextSelector(text, options));
|
return this.locator(Locator.getByAltTextSelector(text, options));
|
||||||
}
|
}
|
||||||
|
|
||||||
getByLabelText(text: string | RegExp, options?: { exact?: boolean }): Locator {
|
getByLabel(text: string | RegExp, options?: { exact?: boolean }): Locator {
|
||||||
return this.locator(Locator.getByLabelTextSelector(text, options));
|
return this.locator(Locator.getByLabelSelector(text, options));
|
||||||
}
|
}
|
||||||
|
|
||||||
getByPlaceholderText(text: string | RegExp, options?: { exact?: boolean }): Locator {
|
getByPlaceholder(text: string | RegExp, options?: { exact?: boolean }): Locator {
|
||||||
return this.locator(Locator.getByPlaceholderTextSelector(text, options));
|
return this.locator(Locator.getByPlaceholderSelector(text, options));
|
||||||
}
|
}
|
||||||
|
|
||||||
getByText(text: string | RegExp, options?: { exact?: boolean }): Locator {
|
getByText(text: string | RegExp, options?: { exact?: boolean }): Locator {
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,7 @@ export class Locator implements api.Locator {
|
||||||
return `attr=[${attrName}=${JSON.stringify(text)}${options?.exact ? 's' : 'i'}]`;
|
return `attr=[${attrName}=${JSON.stringify(text)}${options?.exact ? 's' : 'i'}]`;
|
||||||
}
|
}
|
||||||
|
|
||||||
static getByLabelTextSelector(text: string | RegExp, options?: { exact?: boolean }): string {
|
static getByLabelSelector(text: string | RegExp, options?: { exact?: boolean }): string {
|
||||||
if (!isString(text))
|
if (!isString(text))
|
||||||
return `text=${text}`;
|
return `text=${text}`;
|
||||||
const escaped = JSON.stringify(text);
|
const escaped = JSON.stringify(text);
|
||||||
|
|
@ -77,7 +77,7 @@ export class Locator implements api.Locator {
|
||||||
return Locator.getByAttributeTextSelector('title', text, options);
|
return Locator.getByAttributeTextSelector('title', text, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
static getByPlaceholderTextSelector(text: string | RegExp, options?: { exact?: boolean }): string {
|
static getByPlaceholderSelector(text: string | RegExp, options?: { exact?: boolean }): string {
|
||||||
return Locator.getByAttributeTextSelector('placeholder', text, options);
|
return Locator.getByAttributeTextSelector('placeholder', text, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -215,12 +215,12 @@ export class Locator implements api.Locator {
|
||||||
return this.locator(Locator.getByAltTextSelector(text, options));
|
return this.locator(Locator.getByAltTextSelector(text, options));
|
||||||
}
|
}
|
||||||
|
|
||||||
getByLabelText(text: string | RegExp, options?: { exact?: boolean }): Locator {
|
getByLabel(text: string | RegExp, options?: { exact?: boolean }): Locator {
|
||||||
return this.locator(Locator.getByLabelTextSelector(text, options));
|
return this.locator(Locator.getByLabelSelector(text, options));
|
||||||
}
|
}
|
||||||
|
|
||||||
getByPlaceholderText(text: string | RegExp, options?: { exact?: boolean }): Locator {
|
getByPlaceholder(text: string | RegExp, options?: { exact?: boolean }): Locator {
|
||||||
return this.locator(Locator.getByPlaceholderTextSelector(text, options));
|
return this.locator(Locator.getByPlaceholderSelector(text, options));
|
||||||
}
|
}
|
||||||
|
|
||||||
getByText(text: string | RegExp, options?: { exact?: boolean }): Locator {
|
getByText(text: string | RegExp, options?: { exact?: boolean }): Locator {
|
||||||
|
|
@ -417,12 +417,12 @@ export class FrameLocator implements api.FrameLocator {
|
||||||
return this.locator(Locator.getByAltTextSelector(text, options));
|
return this.locator(Locator.getByAltTextSelector(text, options));
|
||||||
}
|
}
|
||||||
|
|
||||||
getByLabelText(text: string | RegExp, options?: { exact?: boolean }): Locator {
|
getByLabel(text: string | RegExp, options?: { exact?: boolean }): Locator {
|
||||||
return this.locator(Locator.getByLabelTextSelector(text, options));
|
return this.locator(Locator.getByLabelSelector(text, options));
|
||||||
}
|
}
|
||||||
|
|
||||||
getByPlaceholderText(text: string | RegExp, options?: { exact?: boolean }): Locator {
|
getByPlaceholder(text: string | RegExp, options?: { exact?: boolean }): Locator {
|
||||||
return this.locator(Locator.getByPlaceholderTextSelector(text, options));
|
return this.locator(Locator.getByPlaceholderSelector(text, options));
|
||||||
}
|
}
|
||||||
|
|
||||||
getByText(text: string | RegExp, options?: { exact?: boolean }): Locator {
|
getByText(text: string | RegExp, options?: { exact?: boolean }): Locator {
|
||||||
|
|
|
||||||
|
|
@ -572,12 +572,12 @@ export class Page extends ChannelOwner<channels.PageChannel> implements api.Page
|
||||||
return this.mainFrame().getByAltText(text, options);
|
return this.mainFrame().getByAltText(text, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
getByLabelText(text: string | RegExp, options?: { exact?: boolean }): Locator {
|
getByLabel(text: string | RegExp, options?: { exact?: boolean }): Locator {
|
||||||
return this.mainFrame().getByLabelText(text, options);
|
return this.mainFrame().getByLabel(text, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
getByPlaceholderText(text: string | RegExp, options?: { exact?: boolean }): Locator {
|
getByPlaceholder(text: string | RegExp, options?: { exact?: boolean }): Locator {
|
||||||
return this.mainFrame().getByPlaceholderText(text, options);
|
return this.mainFrame().getByPlaceholder(text, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
getByText(text: string | RegExp, options?: { exact?: boolean }): Locator {
|
getByText(text: string | RegExp, options?: { exact?: boolean }): Locator {
|
||||||
|
|
|
||||||
|
|
@ -247,9 +247,9 @@ export class CSharpLanguageGenerator implements LanguageGenerator {
|
||||||
case 'alt':
|
case 'alt':
|
||||||
return toCallWithExact('GetByAltText', body, !!options.exact);
|
return toCallWithExact('GetByAltText', body, !!options.exact);
|
||||||
case 'placeholder':
|
case 'placeholder':
|
||||||
return toCallWithExact('GetByPlaceholderText', body, !!options.exact);
|
return toCallWithExact('GetByPlaceholder', body, !!options.exact);
|
||||||
case 'label':
|
case 'label':
|
||||||
return toCallWithExact('GetByLabelText', body, !!options.exact);
|
return toCallWithExact('GetByLabel', body, !!options.exact);
|
||||||
case 'title':
|
case 'title':
|
||||||
return toCallWithExact('GetByTitle', body, !!options.exact);
|
return toCallWithExact('GetByTitle', body, !!options.exact);
|
||||||
default:
|
default:
|
||||||
|
|
|
||||||
|
|
@ -191,9 +191,9 @@ export class JavaLanguageGenerator implements LanguageGenerator {
|
||||||
case 'alt':
|
case 'alt':
|
||||||
return toCallWithExact(clazz, 'getByAltText', body, !!options.exact);
|
return toCallWithExact(clazz, 'getByAltText', body, !!options.exact);
|
||||||
case 'placeholder':
|
case 'placeholder':
|
||||||
return toCallWithExact(clazz, 'getByPlaceholderText', body, !!options.exact);
|
return toCallWithExact(clazz, 'getByPlaceholder', body, !!options.exact);
|
||||||
case 'label':
|
case 'label':
|
||||||
return toCallWithExact(clazz, 'getByLabelText', body, !!options.exact);
|
return toCallWithExact(clazz, 'getByLabel', body, !!options.exact);
|
||||||
case 'title':
|
case 'title':
|
||||||
return toCallWithExact(clazz, 'getByTitle', body, !!options.exact);
|
return toCallWithExact(clazz, 'getByTitle', body, !!options.exact);
|
||||||
default:
|
default:
|
||||||
|
|
|
||||||
|
|
@ -228,9 +228,9 @@ ${useText ? '\ntest.use(' + useText + ');\n' : ''}
|
||||||
case 'alt':
|
case 'alt':
|
||||||
return toCallWithExact('getByAltText', body, !!options.exact);
|
return toCallWithExact('getByAltText', body, !!options.exact);
|
||||||
case 'placeholder':
|
case 'placeholder':
|
||||||
return toCallWithExact('getByPlaceholderText', body, !!options.exact);
|
return toCallWithExact('getByPlaceholder', body, !!options.exact);
|
||||||
case 'label':
|
case 'label':
|
||||||
return toCallWithExact('getByLabelText', body, !!options.exact);
|
return toCallWithExact('getByLabel', body, !!options.exact);
|
||||||
case 'title':
|
case 'title':
|
||||||
return toCallWithExact('getByTitle', body, !!options.exact);
|
return toCallWithExact('getByTitle', body, !!options.exact);
|
||||||
default:
|
default:
|
||||||
|
|
|
||||||
|
|
@ -246,9 +246,9 @@ with sync_playwright() as playwright:
|
||||||
case 'alt':
|
case 'alt':
|
||||||
return toCallWithExact('get_by_alt_text', body, !!options.exact);
|
return toCallWithExact('get_by_alt_text', body, !!options.exact);
|
||||||
case 'placeholder':
|
case 'placeholder':
|
||||||
return toCallWithExact('get_by_placeholder_text', body, !!options.exact);
|
return toCallWithExact('get_by_placeholder', body, !!options.exact);
|
||||||
case 'label':
|
case 'label':
|
||||||
return toCallWithExact('get_by_label_text', body, !!options.exact);
|
return toCallWithExact('get_by_label', body, !!options.exact);
|
||||||
case 'title':
|
case 'title':
|
||||||
return toCallWithExact('get_by_title', body, !!options.exact);
|
return toCallWithExact('get_by_title', body, !!options.exact);
|
||||||
default:
|
default:
|
||||||
|
|
|
||||||
18
packages/playwright-core/types/types.d.ts
vendored
18
packages/playwright-core/types/types.d.ts
vendored
|
|
@ -2485,7 +2485,7 @@ export interface Page {
|
||||||
* @param text Text to locate the element for.
|
* @param text Text to locate the element for.
|
||||||
* @param options
|
* @param options
|
||||||
*/
|
*/
|
||||||
getByLabelText(text: string|RegExp, options?: {
|
getByLabel(text: string|RegExp, options?: {
|
||||||
/**
|
/**
|
||||||
* Whether to find an exact match: case-sensitive and whole-string. Default to false.
|
* Whether to find an exact match: case-sensitive and whole-string. Default to false.
|
||||||
*/
|
*/
|
||||||
|
|
@ -2503,7 +2503,7 @@ export interface Page {
|
||||||
* @param text Text to locate the element for.
|
* @param text Text to locate the element for.
|
||||||
* @param options
|
* @param options
|
||||||
*/
|
*/
|
||||||
getByPlaceholderText(text: string|RegExp, options?: {
|
getByPlaceholder(text: string|RegExp, options?: {
|
||||||
/**
|
/**
|
||||||
* Whether to find an exact match: case-sensitive and whole-string. Default to false.
|
* Whether to find an exact match: case-sensitive and whole-string. Default to false.
|
||||||
*/
|
*/
|
||||||
|
|
@ -5571,7 +5571,7 @@ export interface Frame {
|
||||||
* @param text Text to locate the element for.
|
* @param text Text to locate the element for.
|
||||||
* @param options
|
* @param options
|
||||||
*/
|
*/
|
||||||
getByLabelText(text: string|RegExp, options?: {
|
getByLabel(text: string|RegExp, options?: {
|
||||||
/**
|
/**
|
||||||
* Whether to find an exact match: case-sensitive and whole-string. Default to false.
|
* Whether to find an exact match: case-sensitive and whole-string. Default to false.
|
||||||
*/
|
*/
|
||||||
|
|
@ -5589,7 +5589,7 @@ export interface Frame {
|
||||||
* @param text Text to locate the element for.
|
* @param text Text to locate the element for.
|
||||||
* @param options
|
* @param options
|
||||||
*/
|
*/
|
||||||
getByPlaceholderText(text: string|RegExp, options?: {
|
getByPlaceholder(text: string|RegExp, options?: {
|
||||||
/**
|
/**
|
||||||
* Whether to find an exact match: case-sensitive and whole-string. Default to false.
|
* Whether to find an exact match: case-sensitive and whole-string. Default to false.
|
||||||
*/
|
*/
|
||||||
|
|
@ -10005,7 +10005,7 @@ export interface Locator {
|
||||||
* @param text Text to locate the element for.
|
* @param text Text to locate the element for.
|
||||||
* @param options
|
* @param options
|
||||||
*/
|
*/
|
||||||
getByLabelText(text: string|RegExp, options?: {
|
getByLabel(text: string|RegExp, options?: {
|
||||||
/**
|
/**
|
||||||
* Whether to find an exact match: case-sensitive and whole-string. Default to false.
|
* Whether to find an exact match: case-sensitive and whole-string. Default to false.
|
||||||
*/
|
*/
|
||||||
|
|
@ -10023,7 +10023,7 @@ export interface Locator {
|
||||||
* @param text Text to locate the element for.
|
* @param text Text to locate the element for.
|
||||||
* @param options
|
* @param options
|
||||||
*/
|
*/
|
||||||
getByPlaceholderText(text: string|RegExp, options?: {
|
getByPlaceholder(text: string|RegExp, options?: {
|
||||||
/**
|
/**
|
||||||
* Whether to find an exact match: case-sensitive and whole-string. Default to false.
|
* Whether to find an exact match: case-sensitive and whole-string. Default to false.
|
||||||
*/
|
*/
|
||||||
|
|
@ -10746,7 +10746,7 @@ export interface Locator {
|
||||||
* An example of typing into a text field and then submitting the form:
|
* An example of typing into a text field and then submitting the form:
|
||||||
*
|
*
|
||||||
* ```js
|
* ```js
|
||||||
* const element = page.getByLabelText('Password');
|
* const element = page.getByLabel('Password');
|
||||||
* await element.type('my password');
|
* await element.type('my password');
|
||||||
* await element.press('Enter');
|
* await element.press('Enter');
|
||||||
* ```
|
* ```
|
||||||
|
|
@ -15260,7 +15260,7 @@ export interface FrameLocator {
|
||||||
* @param text Text to locate the element for.
|
* @param text Text to locate the element for.
|
||||||
* @param options
|
* @param options
|
||||||
*/
|
*/
|
||||||
getByLabelText(text: string|RegExp, options?: {
|
getByLabel(text: string|RegExp, options?: {
|
||||||
/**
|
/**
|
||||||
* Whether to find an exact match: case-sensitive and whole-string. Default to false.
|
* Whether to find an exact match: case-sensitive and whole-string. Default to false.
|
||||||
*/
|
*/
|
||||||
|
|
@ -15278,7 +15278,7 @@ export interface FrameLocator {
|
||||||
* @param text Text to locate the element for.
|
* @param text Text to locate the element for.
|
||||||
* @param options
|
* @param options
|
||||||
*/
|
*/
|
||||||
getByPlaceholderText(text: string|RegExp, options?: {
|
getByPlaceholder(text: string|RegExp, options?: {
|
||||||
/**
|
/**
|
||||||
* Whether to find an exact match: case-sensitive and whole-string. Default to false.
|
* Whether to find an exact match: case-sensitive and whole-string. Default to false.
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
6
packages/playwright-test/types/test.d.ts
vendored
6
packages/playwright-test/types/test.d.ts
vendored
|
|
@ -3078,8 +3078,8 @@ export interface PlaywrightTestArgs {
|
||||||
*
|
*
|
||||||
* test('basic test', async ({ page }) => {
|
* test('basic test', async ({ page }) => {
|
||||||
* await page.goto('/signin');
|
* await page.goto('/signin');
|
||||||
* await page.getByLabelText('User Name').fill('user');
|
* await page.getByLabel('User Name').fill('user');
|
||||||
* await page.getByLabelText('Password').fill('password');
|
* await page.getByLabel('Password').fill('password');
|
||||||
* await page.getByText('Sign in').click();
|
* await page.getByText('Sign in').click();
|
||||||
* // ...
|
* // ...
|
||||||
* });
|
* });
|
||||||
|
|
@ -3277,7 +3277,7 @@ interface LocatorAssertions {
|
||||||
* Ensures the [Locator] points to a checked input.
|
* Ensures the [Locator] points to a checked input.
|
||||||
*
|
*
|
||||||
* ```js
|
* ```js
|
||||||
* const locator = page.getByLabelText('Subscribe to newsletter');
|
* const locator = page.getByLabel('Subscribe to newsletter');
|
||||||
* await expect(locator).toBeChecked();
|
* await expect(locator).toBeChecked();
|
||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -261,7 +261,7 @@ test.describe('cli codegen', () => {
|
||||||
expect(message.text()).toBe('click');
|
expect(message.text()).toBe('click');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should generate getByPlaceholderText', async ({ page, openRecorder }) => {
|
test('should generate getByPlaceholder', async ({ page, openRecorder }) => {
|
||||||
const recorder = await openRecorder();
|
const recorder = await openRecorder();
|
||||||
|
|
||||||
await recorder.setContentAndWait(`<input placeholder="Country"></input>`);
|
await recorder.setContentAndWait(`<input placeholder="Country"></input>`);
|
||||||
|
|
@ -275,19 +275,19 @@ test.describe('cli codegen', () => {
|
||||||
]);
|
]);
|
||||||
|
|
||||||
expect.soft(sources.get('JavaScript').text).toContain(`
|
expect.soft(sources.get('JavaScript').text).toContain(`
|
||||||
await page.getByPlaceholderText('Country').click();`);
|
await page.getByPlaceholder('Country').click();`);
|
||||||
|
|
||||||
expect.soft(sources.get('Python').text).toContain(`
|
expect.soft(sources.get('Python').text).toContain(`
|
||||||
page.get_by_placeholder_text("Country").click()`);
|
page.get_by_placeholder("Country").click()`);
|
||||||
|
|
||||||
expect.soft(sources.get('Python Async').text).toContain(`
|
expect.soft(sources.get('Python Async').text).toContain(`
|
||||||
await page.get_by_placeholder_text("Country").click()`);
|
await page.get_by_placeholder("Country").click()`);
|
||||||
|
|
||||||
expect.soft(sources.get('Java').text).toContain(`
|
expect.soft(sources.get('Java').text).toContain(`
|
||||||
page.getByPlaceholderText("Country").click()`);
|
page.getByPlaceholder("Country").click()`);
|
||||||
|
|
||||||
expect.soft(sources.get('C#').text).toContain(`
|
expect.soft(sources.get('C#').text).toContain(`
|
||||||
await page.GetByPlaceholderText("Country").ClickAsync();`);
|
await page.GetByPlaceholder("Country").ClickAsync();`);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should generate getByAltText', async ({ page, openRecorder }) => {
|
test('should generate getByAltText', async ({ page, openRecorder }) => {
|
||||||
|
|
|
||||||
|
|
@ -248,9 +248,9 @@ it('getBy coverage', async ({ page, server }) => {
|
||||||
await expect(button1).toHaveText('Hello iframe');
|
await expect(button1).toHaveText('Hello iframe');
|
||||||
await expect(button2).toHaveText('Hello iframe');
|
await expect(button2).toHaveText('Hello iframe');
|
||||||
await expect(button3).toHaveText('Hello iframe');
|
await expect(button3).toHaveText('Hello iframe');
|
||||||
const input1 = page.frameLocator('iframe').getByLabelText('Name');
|
const input1 = page.frameLocator('iframe').getByLabel('Name');
|
||||||
await expect(input1).toHaveValue('');
|
await expect(input1).toHaveValue('');
|
||||||
const input2 = page.frameLocator('iframe').getByPlaceholderText('Placeholder');
|
const input2 = page.frameLocator('iframe').getByPlaceholder('Placeholder');
|
||||||
await expect(input2).toHaveValue('');
|
await expect(input2).toHaveValue('');
|
||||||
const input3 = page.frameLocator('iframe').getByAltText('Alternative');
|
const input3 = page.frameLocator('iframe').getByAltText('Alternative');
|
||||||
await expect(input3).toHaveValue('');
|
await expect(input3).toHaveValue('');
|
||||||
|
|
|
||||||
|
|
@ -37,26 +37,26 @@ it('getByText should work', async ({ page }) => {
|
||||||
expect(await page.getByText('ye', { exact: true }).first().evaluate(e => e.outerHTML)).toContain('> ye </div>');
|
expect(await page.getByText('ye', { exact: true }).first().evaluate(e => e.outerHTML)).toContain('> ye </div>');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('getByLabelText should work', async ({ page }) => {
|
it('getByLabel should work', async ({ page }) => {
|
||||||
await page.setContent(`<div><label for=target>Name</label><input id=target type=text></div>`);
|
await page.setContent(`<div><label for=target>Name</label><input id=target type=text></div>`);
|
||||||
expect(await page.getByText('Name').evaluate(e => e.nodeName)).toBe('LABEL');
|
expect(await page.getByText('Name').evaluate(e => e.nodeName)).toBe('LABEL');
|
||||||
expect(await page.getByLabelText('Name').evaluate(e => e.nodeName)).toBe('INPUT');
|
expect(await page.getByLabel('Name').evaluate(e => e.nodeName)).toBe('INPUT');
|
||||||
expect(await page.mainFrame().getByLabelText('Name').evaluate(e => e.nodeName)).toBe('INPUT');
|
expect(await page.mainFrame().getByLabel('Name').evaluate(e => e.nodeName)).toBe('INPUT');
|
||||||
expect(await page.locator('div').getByLabelText('Name').evaluate(e => e.nodeName)).toBe('INPUT');
|
expect(await page.locator('div').getByLabel('Name').evaluate(e => e.nodeName)).toBe('INPUT');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('getByPlaceholderText should work', async ({ page }) => {
|
it('getByPlaceholder should work', async ({ page }) => {
|
||||||
await page.setContent(`<div>
|
await page.setContent(`<div>
|
||||||
<input placeholder='Hello'>
|
<input placeholder='Hello'>
|
||||||
<input placeholder='Hello World'>
|
<input placeholder='Hello World'>
|
||||||
</div>`);
|
</div>`);
|
||||||
await expect(page.getByPlaceholderText('hello')).toHaveCount(2);
|
await expect(page.getByPlaceholder('hello')).toHaveCount(2);
|
||||||
await expect(page.getByPlaceholderText('Hello', { exact: true })).toHaveCount(1);
|
await expect(page.getByPlaceholder('Hello', { exact: true })).toHaveCount(1);
|
||||||
await expect(page.getByPlaceholderText(/wor/i)).toHaveCount(1);
|
await expect(page.getByPlaceholder(/wor/i)).toHaveCount(1);
|
||||||
|
|
||||||
// Coverage
|
// Coverage
|
||||||
await expect(page.mainFrame().getByPlaceholderText('hello')).toHaveCount(2);
|
await expect(page.mainFrame().getByPlaceholder('hello')).toHaveCount(2);
|
||||||
await expect(page.locator('div').getByPlaceholderText('hello')).toHaveCount(2);
|
await expect(page.locator('div').getByPlaceholder('hello')).toHaveCount(2);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('getByAltText should work', async ({ page }) => {
|
it('getByAltText should work', async ({ page }) => {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue