docs: Update pom.md to use locators (#12592)

This commit is contained in:
Meir Blachman 2022-03-08 22:39:40 +02:00 committed by GitHub
parent 30c954a3ba
commit 7e53facf1e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -30,13 +30,14 @@ class SearchPage {
*/ */
constructor(page) { constructor(page) {
this.page = page; this.page = page;
this.searchTermInput = page.locator('[aria-label="Enter your search term"]');
} }
async navigate() { async navigate() {
await this.page.goto('https://bing.com'); await this.page.goto('https://bing.com');
} }
async search(text) { async search(text) {
await this.page.fill('[aria-label="Enter your search term"]', text); await this.searchTermInput.fill(text);
await this.page.press('[aria-label="Enter your search term"]', 'Enter'); await this.searchTermInput.press('Enter');
} }
} }
module.exports = { SearchPage }; module.exports = { SearchPage };
@ -50,9 +51,11 @@ import com.microsoft.playwright;
public class SearchPage { public class SearchPage {
private final Page page; private final Page page;
private final Locator searchTermInput;
public SearchPage(Page page) { public SearchPage(Page page) {
this.page = page; this.page = page;
this.searchTermInput = page.locator("[aria-label='Enter your search term']");
} }
public void navigate() { public void navigate() {
@ -60,8 +63,8 @@ public class SearchPage {
} }
public void search(String text) { public void search(String text) {
page.fill("[aria-label='Enter your search term']", text); searchTermInput.fill(text);
page.press("[aria-label='Enter your search term']", "Enter"); searchTermInput.press("Enter");
} }
} }
``` ```
@ -71,13 +74,14 @@ public class SearchPage {
class SearchPage: class SearchPage:
def __init__(self, page): def __init__(self, page):
self.page = page self.page = page
self.search_term_input = page.locator('[aria-label="Enter your search term"]')
async def navigate(self): async def navigate(self):
await self.page.goto("https://bing.com") await self.page.goto("https://bing.com")
async def search(self, text): async def search(self, text):
await self.page.fill('[aria-label="Enter your search term"]', text) await self.search_term_input.fill(text)
await self.page.press('[aria-label="Enter your search term"]', "Enter") await self.search_term_input.press("Enter")
``` ```
```python sync ```python sync
@ -85,13 +89,14 @@ class SearchPage:
class SearchPage: class SearchPage:
def __init__(self, page): def __init__(self, page):
self.page = page self.page = page
self.search_term_input = page.locator('[aria-label="Enter your search term"]')
def navigate(self): def navigate(self):
self.page.goto("https://bing.com") self.page.goto("https://bing.com")
def search(self, text): def search(self, text):
self.page.fill('[aria-label="Enter your search term"]', text) self.search_term_input.fill(text)
self.page.press('[aria-label="Enter your search term"]', "Enter") self.search_term_input.press("Enter")
``` ```
```csharp ```csharp
@ -103,10 +108,12 @@ namespace BigEcommerceApp.Tests.Models
public class SearchPage public class SearchPage
{ {
private readonly IPage _page; private readonly IPage _page;
private readonly ILocator _searchTermInput;
public SearchPage(IPage page) public SearchPage(IPage page)
{ {
_page = page; _page = page;
_searchTermInput = page.Locator("[aria-label='Enter your search term']");
} }
public async Task Goto() public async Task Goto()
@ -116,8 +123,8 @@ namespace BigEcommerceApp.Tests.Models
public async Task Search(string text) public async Task Search(string text)
{ {
await _page.FillAsync("[aria-label='Enter your search term']", text); await _searchTermInput.FillAsync(text);
await _page.PressAsync("[aria-label='Enter your search term']", "Enter"); await _searchTermInput.PressAsync("Enter");
} }
} }
} }