You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: website_and_docs/content/documentation/test_practices/encouraged/page_object_models.ja.md
+17-22
Original file line number
Diff line number
Diff line change
@@ -199,13 +199,15 @@ requests from the test.
199
199
200
200
## Page Component Objects
201
201
A page object does not necessarily need to represent all the parts of a
202
-
page itself. The same principles used for page objects can be used to
203
-
create "Page _Component_ Objects" that represent discrete chunks of the
204
-
page and can be included in page objects. These component objects can
202
+
page itself. This was [noted by Martin Fowler](https://martinfowler.com/bliki/PageObject.html#footnote-panel-object) in the early days, while first coining the term "panel objects".
203
+
204
+
The same principles used for page objects can be used to
205
+
create "Page _Component_ Objects", as it was later called, that represent discrete chunks of the
206
+
page and **can be included in page objects**. These component objects can
205
207
provide references to the elements inside those discrete chunks, and
206
-
methods to leverage the functionality provided by them.
208
+
methods to leverage the functionality or behavior provided by them.
207
209
208
-
For example, a Product page has multiple products.
210
+
For example, a Products page has multiple products.
209
211
210
212
```html
211
213
<!-- Products Page -->
@@ -243,7 +245,7 @@ Each product is a component of the Products page.
243
245
</div>
244
246
```
245
247
246
-
The Product page HAS-A list of products. This relationship is called Composition. In simpler terms, something is _composed of_ another thing.
248
+
The Products page HAS-A list of products. This object relationship is called Composition. In simpler terms, something is _composed of_ another thing.
247
249
248
250
```java
249
251
publicabstractclassBasePage {
@@ -326,7 +328,7 @@ So now, the products test would use the page object and the page component objec
326
328
publicclassProductsTest {
327
329
@Test
328
330
publicvoidtestProductInventory() {
329
-
var productsPage =newProductsPage(driver);
331
+
var productsPage =newProductsPage(driver);// page object
330
332
var products = productsPage.getProducts();
331
333
assertEquals(6, products.size()); // expected, actual
332
334
}
@@ -337,7 +339,7 @@ public class ProductsTest {
337
339
338
340
// Pass a lambda expression (predicate) to filter the list of products
339
341
// The predicate or "strategy" is the behavior passed as parameter
340
-
var backpack = productsPage.getProduct(p -> p.getName().equals("Backpack"));
342
+
var backpack = productsPage.getProduct(p -> p.getName().equals("Backpack"));// page component object
341
343
var bikeLight = productsPage.getProduct(p -> p.getName().equals("Bike Light"));
@@ -355,8 +357,7 @@ components used throughout the site (e.g. a navigation bar), then it
355
357
may improve maintainability and reduce code duplication.
356
358
357
359
## Other Design Patterns Used in Testing
358
-
There are other design patterns that also may be used in testing. Some use a
359
-
Page Factory for instantiating their page objects. Discussing all of these is
360
+
There are other design patterns that also may be used in testing. Discussing all of these is
360
361
beyond the scope of this user guide. Here, we merely want to introduce the
361
362
concepts to make the reader aware of some of the things that can be done. As
362
363
was mentioned earlier, many have blogged on this topic and we encourage the
@@ -367,11 +368,11 @@ reader to search for blogs on these topics.
367
368
368
369
PageObjects can be thought of as facing in two directions simultaneously. Facing toward the developer of a test, they represent the **services** offered by a particular page. Facing away from the developer, they should be the only thing that has a deep knowledge of the structure of the HTML of a page (or part of a page) It's simplest to think of the methods on a Page Object as offering the "services" that a page offers rather than exposing the details and mechanics of the page. As an example, think of the inbox of any web-based email system. Amongst the services it offers are the ability to compose a new email, choose to read a single email, and list the subject lines of the emails in the inbox. How these are implemented shouldn't matter to the test.
369
370
370
-
Because we're encouraging the developer of a test to try and think about the services they're interacting with rather than the implementation, PageObjects should seldom expose the underlying WebDriver instance. To facilitate this, methods on the PageObject should return other PageObjects. This means we can effectively model the user's journey through our application. It also means that should the way that pages relate to one another change (like when the login page asks the user to change their password the first time they log into a service when it previously didn't do that), simply changing the appropriate method's signature will cause the tests to fail to compile. Put another way; we can tell which tests would fail without needing to run them when we change the relationship between pages and reflect this in the PageObjects.
371
+
Because we're encouraging the developer of a test to try and think about the services they're interacting with rather than the implementation, PageObjects should seldom expose the underlying WebDriver instance. To facilitate this, **methods on the PageObject should return other PageObjects**. This means we can effectively model the user's journey through our application. It also means that should the way that pages relate to one another change (like when the login page asks the user to change their password the first time they log into a service when it previously didn't do that), simply changing the appropriate method's signature will cause the tests to fail to compile. Put another way; we can tell which tests would fail without needing to run them when we change the relationship between pages and reflect this in the PageObjects.
371
372
372
373
One consequence of this approach is that it may be necessary to model (for example) both a successful and unsuccessful login; or a click could have a different result depending on the app's state. When this happens, it is common to have multiple methods on the PageObject:
The code presented above shows an important point: the tests, not the PageObjects, should be responsible for making assertions about the state of a page. For example:
391
392
392
-
```
393
+
```java
393
394
publicvoid testMessagesAreReadOrUnread() {
394
395
Inbox inbox =newInbox(driver);
395
396
inbox.assertMessageWithSubjectIsUnread("I like cheese");
@@ -399,7 +400,7 @@ public void testMessagesAreReadOrUnread() {
399
400
400
401
could be re-written as:
401
402
402
-
```
403
+
```java
403
404
publicvoid testMessagesAreReadOrUnread() {
404
405
Inbox inbox =newInbox(driver);
405
406
assertTrue(inbox.isMessageWithSubjectIsUnread("I like cheese"));
@@ -422,7 +423,7 @@ Finally, a PageObject need not represent an entire page. It may represent a sect
422
423
423
424
## Example
424
425
425
-
```
426
+
```java
426
427
publicclassLoginPage {
427
428
privatefinalWebDriver driver;
428
429
@@ -491,10 +492,4 @@ public class LoginPage {
491
492
return submitLogin();
492
493
}
493
494
}
494
-
495
-
```
496
-
497
-
498
-
## Support in WebDriver
499
-
500
-
There is a PageFactory in the support package that provides support for this pattern and helps to remove some boiler-plate code from your Page Objects at the same time.
Copy file name to clipboardExpand all lines: website_and_docs/content/documentation/test_practices/encouraged/page_object_models.pt-br.md
+17-22
Original file line number
Diff line number
Diff line change
@@ -199,13 +199,15 @@ requests from the test.
199
199
200
200
## Page Component Objects
201
201
A page object does not necessarily need to represent all the parts of a
202
-
page itself. The same principles used for page objects can be used to
203
-
create "Page _Component_ Objects" that represent discrete chunks of the
204
-
page and can be included in page objects. These component objects can
202
+
page itself. This was [noted by Martin Fowler](https://martinfowler.com/bliki/PageObject.html#footnote-panel-object) in the early days, while first coining the term "panel objects".
203
+
204
+
The same principles used for page objects can be used to
205
+
create "Page _Component_ Objects", as it was later called, that represent discrete chunks of the
206
+
page and **can be included in page objects**. These component objects can
205
207
provide references to the elements inside those discrete chunks, and
206
-
methods to leverage the functionality provided by them.
208
+
methods to leverage the functionality or behavior provided by them.
207
209
208
-
For example, a Product page has multiple products.
210
+
For example, a Products page has multiple products.
209
211
210
212
```html
211
213
<!-- Products Page -->
@@ -243,7 +245,7 @@ Each product is a component of the Products page.
243
245
</div>
244
246
```
245
247
246
-
The Product page HAS-A list of products. This relationship is called Composition. In simpler terms, something is _composed of_ another thing.
248
+
The Products page HAS-A list of products. This object relationship is called Composition. In simpler terms, something is _composed of_ another thing.
247
249
248
250
```java
249
251
publicabstractclassBasePage {
@@ -326,7 +328,7 @@ So now, the products test would use the page object and the page component objec
326
328
publicclassProductsTest {
327
329
@Test
328
330
publicvoidtestProductInventory() {
329
-
var productsPage =newProductsPage(driver);
331
+
var productsPage =newProductsPage(driver);// page object
330
332
var products = productsPage.getProducts();
331
333
assertEquals(6, products.size()); // expected, actual
332
334
}
@@ -337,7 +339,7 @@ public class ProductsTest {
337
339
338
340
// Pass a lambda expression (predicate) to filter the list of products
339
341
// The predicate or "strategy" is the behavior passed as parameter
340
-
var backpack = productsPage.getProduct(p -> p.getName().equals("Backpack"));
342
+
var backpack = productsPage.getProduct(p -> p.getName().equals("Backpack"));// page component object
341
343
var bikeLight = productsPage.getProduct(p -> p.getName().equals("Bike Light"));
@@ -355,8 +357,7 @@ components used throughout the site (e.g. a navigation bar), then it
355
357
may improve maintainability and reduce code duplication.
356
358
357
359
## Other Design Patterns Used in Testing
358
-
There are other design patterns that also may be used in testing. Some use a
359
-
Page Factory for instantiating their page objects. Discussing all of these is
360
+
There are other design patterns that also may be used in testing. Discussing all of these is
360
361
beyond the scope of this user guide. Here, we merely want to introduce the
361
362
concepts to make the reader aware of some of the things that can be done. As
362
363
was mentioned earlier, many have blogged on this topic and we encourage the
@@ -367,11 +368,11 @@ reader to search for blogs on these topics.
367
368
368
369
PageObjects can be thought of as facing in two directions simultaneously. Facing toward the developer of a test, they represent the **services** offered by a particular page. Facing away from the developer, they should be the only thing that has a deep knowledge of the structure of the HTML of a page (or part of a page) It's simplest to think of the methods on a Page Object as offering the "services" that a page offers rather than exposing the details and mechanics of the page. As an example, think of the inbox of any web-based email system. Amongst the services it offers are the ability to compose a new email, choose to read a single email, and list the subject lines of the emails in the inbox. How these are implemented shouldn't matter to the test.
369
370
370
-
Because we're encouraging the developer of a test to try and think about the services they're interacting with rather than the implementation, PageObjects should seldom expose the underlying WebDriver instance. To facilitate this, methods on the PageObject should return other PageObjects. This means we can effectively model the user's journey through our application. It also means that should the way that pages relate to one another change (like when the login page asks the user to change their password the first time they log into a service when it previously didn't do that), simply changing the appropriate method's signature will cause the tests to fail to compile. Put another way; we can tell which tests would fail without needing to run them when we change the relationship between pages and reflect this in the PageObjects.
371
+
Because we're encouraging the developer of a test to try and think about the services they're interacting with rather than the implementation, PageObjects should seldom expose the underlying WebDriver instance. To facilitate this, **methods on the PageObject should return other PageObjects**. This means we can effectively model the user's journey through our application. It also means that should the way that pages relate to one another change (like when the login page asks the user to change their password the first time they log into a service when it previously didn't do that), simply changing the appropriate method's signature will cause the tests to fail to compile. Put another way; we can tell which tests would fail without needing to run them when we change the relationship between pages and reflect this in the PageObjects.
371
372
372
373
One consequence of this approach is that it may be necessary to model (for example) both a successful and unsuccessful login; or a click could have a different result depending on the app's state. When this happens, it is common to have multiple methods on the PageObject:
The code presented above shows an important point: the tests, not the PageObjects, should be responsible for making assertions about the state of a page. For example:
391
392
392
-
```
393
+
```java
393
394
publicvoid testMessagesAreReadOrUnread() {
394
395
Inbox inbox =newInbox(driver);
395
396
inbox.assertMessageWithSubjectIsUnread("I like cheese");
@@ -399,7 +400,7 @@ public void testMessagesAreReadOrUnread() {
399
400
400
401
could be re-written as:
401
402
402
-
```
403
+
```java
403
404
publicvoid testMessagesAreReadOrUnread() {
404
405
Inbox inbox =newInbox(driver);
405
406
assertTrue(inbox.isMessageWithSubjectIsUnread("I like cheese"));
@@ -422,7 +423,7 @@ Finally, a PageObject need not represent an entire page. It may represent a sect
422
423
423
424
## Example
424
425
425
-
```
426
+
```java
426
427
publicclassLoginPage {
427
428
privatefinalWebDriver driver;
428
429
@@ -491,10 +492,4 @@ public class LoginPage {
491
492
return submitLogin();
492
493
}
493
494
}
494
-
495
-
```
496
-
497
-
498
-
## Support in WebDriver
499
-
500
-
There is a PageFactory in the support package that provides support for this pattern and helps to remove some boiler-plate code from your Page Objects at the same time.
0 commit comments