Page Objects with Selenide

1,129 views
Skip to first unread message

Andrei Solntsev

unread,
Oct 16, 2014, 5:49:21 PM10/16/14
to sele...@googlegroups.com

Good evening!
People often ask:
can I write Page Objects with Selenide?

Answer is: yes, you can

Moreover, with Selenide your Page Objects get concise and readable comparing to the classical Selenium notation. 

Read more details in the new topic selenide.org -> "Docs":


Andrei Solntsev

pvi...@gmail.com

unread,
Jul 16, 2015, 5:36:10 PM7/16/15
to sele...@googlegroups.com
Hi Andrei,
Good stuff.
I'm just getting started with Selenium & Selenide.
Question on maintainability...if a page object is used in more than one place (methods), if we don't have Page Factory, then how do you handle any change?
Rgds.

Andrei Solntsev

unread,
Jul 16, 2015, 6:06:13 PM7/16/15
to pvi...@gmail.com, sele...@googlegroups.com
Hi!
I am not sure I correctly understand your question.

Yes, with Selenide you don't need a page factory. Every time you need a page object, you just create it.

Another option that someone can find convenient is using page method:
return page(GoogleResultsPage.class);

Andrei Solntsev


--
You received this message because you are subscribed to the Google Groups "selenide" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenide+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

pvi...@gmail.com

unread,
Jul 17, 2015, 11:33:55 AM7/17/15
to sele...@googlegroups.com
Thx Andrei.
I'm just beginning...so may not have full handle over how Selenide works, give me bit of slack there...:)

Ok, what I'm getting at...try to describe below using 2 methods...1st one just copied from your tutorial, 2nd one is just an example (not sure of the syntax)
The point here is that search field attribute 'name' has value 'q' & it's used in 2 methods. If the value is changed, it'll need to be changed in both places; imagine if this field attribute is used in many more methods, we'll have to update all over. The example used is simple google search, while other applications have more fields on a page...like advanced search & registration forms.
Bottomline is that if Page Factory is used to define all this page objects at one place & then used, the change/maintainence can be done at one place & the change is effective all over.

1] public GoogleResultsPage search(String query) {
$(By.name("q")).setValue(query).pressEnter();
return page(GoogleResultsPage.class);
}
2] public GoogleResultsPage getSearchValue(String query) {
return $(By.name("q")).getValue(query);
}

Let me know if I'm not clear.

Andrei Solntsev

unread,
Jul 20, 2015, 3:20:23 AM7/20/15
to Vinod P, sele...@googlegroups.com
Ok, I understand that you worry about duplication of "q" locator?

Ok, there are 3 strategies to resolve this problem. You decide which strategy you choose depending on your application.

1. We can claim that "q" field on search page and "q" field on "results" page are different fields. 
    In this case, it's ok to have duplicated "q" locator. It's quite possible that developers will change name of "q" field on one page, but leave it unchanged on another page.

2. We can claim that "search" page and "results" age is actually the same page. 
  The "search" page is actually that same "results" page, just with empty result list.
  In this case, we can just drop GoogleSearchPage, and use only GoogleResultsPage. 

3. (the most complex)
  We claim that "search" and "results" page are different pages, but they use the same component ("q" field) that we don't want to duplicate. 
  In this case, you can create a separate "component" class (say, SearchBox) that would include "q" field. And include this component to both pages. Look at this test for example.There is SelectsPage that includes StatusBlock component. Class StatusBlock extends ElementsContainer. 
  

In case of Google search, I think the 2nd strategy is good. 

Andrei Solntsev

--
You received this message because you are subscribed to the Google Groups "selenide" group.

pvi...@gmail.com

unread,
Jul 20, 2015, 9:58:46 AM7/20/15
to sele...@googlegroups.com, pvi...@gmail.com
Thx for the detailed response.
Actually the way I interpreted was that one can work w/o Page Objects, hence my question about repeating the "q" locator. Now I was not thinking of duplication on different pages as you described...'Search page' & 'Results page'.
My concern was that if we do use locators in methods directly then even within the same page, if we have 2 different methods, say one for setting a search value (assuming we are searching using the Results page) & another for verifying that after a search the field retains the search value, then we have 2 methods using the 'q' locator.
From your example I understand that we'll be having the 'q' locator in a class & using the reference of that definition...which is the conventional way of structuring in OOP.
So, my question is, then how is this different from the regular OOP design?

andrei....@gmail.com

unread,
Jul 20, 2015, 12:03:23 PM7/20/15
to Vinod P, sele...@googlegroups.com, Vinod P
Hi!
ok, if you want to avoid duplication of "q" inside a page object, then you can declare a field. Like it's typically done in classical "selenium"-style page objects. There is no problems with this approach, except it requires too much code. Probably it takes less time and resources to use "q" twice inside a class and replace it when locator changes.

So, my question is, then how is this different from the regular OOP design?

It is not different from OOP. Why it should be different?

Sent from my HTC

Thx for the detailed response.
Actually the way I interpreted was that one can work w/o Page Objects, hence my question about repeating the "q" locator. Now I was not thinking of duplication on different pages as you described...'Search page' & 'Results page'.
My concern was that if we do use locators in methods directly then even within the same page, if we have 2 different methods, say one for setting a search value (assuming we are searching using the Results page) & another for verifying that after a search the field retains the search value, then we have 2 methods using the 'q' locator.
From your example I understand that we'll be having the 'q' locator in a class & using the reference of that definition...which is the conventional way of structuring in OOP.
So, my question is, then how is this different from the regular OOP design?

-- 
You received this message because you are subscribed to the Google Groups "selenide" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenide+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

pvi...@gmail.com

unread,
Jul 20, 2015, 3:42:52 PM7/20/15
to sele...@googlegroups.com, pvi...@gmail.com
I was not saying it should be different from OOP; just that I thought you were saying this is different.
From your answer I realize that you personally do not follow the classical selenium style page objects...instead repeat the locator within methods as needed AND update them when change occurs.
I'm liking this idea...from your experience in implementing this, how easy is it to implement changes & what are the complications you faced for NOT having page objects defined?
Hoping this discussion will help others to come to a conclusion in using Selenide as a wrapper for Selenium.
Thx for your time.

andrei....@gmail.com

unread,
Jul 22, 2015, 1:45:52 PM7/22/15
to Vinod P, sele...@googlegroups.com, Vinod P
Hi!
First of all, I want to emphasize that using or not using PageObject pattern should not affect decision to use/not use Selenide. With Selenide, it's easy to write test with PageObjects, and it's easy to write tests without PageObjects.

what are the complications you faced for NOT having page objects defined?

We have NOT faced any complications. Moreover, we tried to use PageObjects (because it's widely used), and hav not noticed any benefits.

Probably one of the reason is that in our company we don't have testers. Developers write both code and tests (both unit- and UI-tests). We use simple selectors, create mocks for slow services and make applications easy to test. 

And the most important, we do not write a lot of UI tests. Instead, we cover combinations by unit-tests, leaving UI tests only basic paths. That's why we don't need to reuse CSS selectors a lot (this is the basic reason to use PageObjects).

I hope it helps.

Sent from my HTC

----- Reply message -----
From: pvi...@gmail.com
To: <sele...@googlegroups.com>
Cc: <pvi...@gmail.com>
Subject: Page Objects with Selenide

I was not saying it should be different from OOP; just that I thought you were saying this is different.
From your answer I realize that you personally do not follow the classical selenium style page objects...instead repeat the locator within methods as needed AND update them when change occurs.
I'm liking this idea...from your experience in implementing this, how easy is it to implement changes & what are the complications you faced for NOT having page objects defined?
Hoping this discussion will help others to come to a conclusion in using Selenide as a wrapper for Selenium.
Thx for your time.

-- 
You received this message because you are subscribed to the Google Groups "selenide" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenide+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Message has been deleted

Andrei Solntsev

unread,
May 28, 2021, 11:22:07 AM5/28/21
to Onkar Singh, selenide
Hi Onkar!
Welcome to the club!

This is the method "page" in class "com.codeborne.selenide.Selenide". Simple. 


Andrei Solntsev


пт, 28 мая 2021 г. в 17:49, Onkar Singh <awesomede...@gmail.com>:
Hi Andrei,
I recently started using Selenide, and I need your help to know what import is required to use the page(GoogleResultsPage.class). For me eclipse doesn't seem to recognize the page() method to create a page object automatically.
I'd appreciate any help, thank you!!

Onkar

Reply all
Reply to author
Forward
0 new messages