Announce: lightweight page object library

258 views
Skip to first unread message

Bryan Oakley

unread,
May 22, 2016, 10:23:16 PM5/22/16
to robotframework-users
I've just made available a beta release of a new, lightweight page object library. 

More information is available at the following locations:

There is already a page object library for robot [1] which I used at a previous employer with great success. However, the package was abandoned by the original author, and I found it to be more complex than it needed to be. This new library is 1/4 the size, weighing in at only 400 or so lines of code and comments -- small enough for anyone to be able to dig in and understand the implementation. 

Comments and bug reports would be appreciated!

--
Bryan Oakley





Gu Ru

unread,
May 24, 2016, 3:51:49 AM5/24/16
to robotframework-users
Thank you very much, I will give a try during the weekend

Cheers n regards,

Pekka Klärck

unread,
May 25, 2016, 4:18:05 AM5/25/16
to Bryan Oakley, robotframework-users
2016-05-23 5:23 GMT+03:00 Bryan Oakley <bryan....@gmail.com>:
> I've just made available a beta release of a new, lightweight page object
> library.

This sounds very interesting. I don't do much real web testing myself,
but my understanding is that the page object model and creating also
the domain specific keywords in libraries is generally a good approach
especially in larger web testing projects. It is really cool that
there's now the older (and unfortunately unmaintained) page object
library and this newer and lighter one. I hope the wider Robot
Framework web testing community will give these libraries a spin, and
they can then be enhanced or new libraries created based on real life
experiences.

Cheers,
.peke
--
Agile Tester/Developer/Consultant :: http://eliga.fi
Lead Developer of Robot Framework :: http://robotframework.org

binithb

unread,
Jun 5, 2016, 5:17:58 PM6/5/16
to robotframework-users
Hi,

Great to see a new library in this area.

Do you have plans to add support for representations of sub components(or sections ) of a page object similar to what's available in the other, existing robotframework-pageobjects library?
For me that's very useful, being able to separate logic when the page grows in functionality.

-binith

Bryan Oakley

unread,
Jun 5, 2016, 8:59:51 PM6/5/16
to bin...@gmail.com, robotframework-users
Are you referring to the "page components" of the robotframework-pageobjects library? https://github.com/ncbi/robotframework-pageobjects#page-components

Probably not, I'm not sure there's a need.  You can use class mixins to share keywords between page objects, so I'm not sure what adding explicit support would get you that you couldn't already do. One of my reservations about that other page object library is that it was difficult to learn how to use. I'm purposefully keeping my page object library simple, while still allowing you to do virtually everything you could do with the other library.

Mixins are extremely powerful, and incredibly simple. My team uses this concept extensively. We have half a dozen mixin classes, and when we built a new page object we just pick and choose the components that are on that page from the available mixins. This allows us to focus on what's unique about the new page, without having to copy and paste a bunch of duplicate code.

I wrote a short blog post that shows how to create mixin classes for shared keywords: https://goo.gl/bompP5

If you could show me how adding explicit support for page components would help, I'll be glad to consider it. As it stands now, I just don't see the need.

--bryan


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

Nesat Ufuk

unread,
Jun 8, 2017, 7:34:53 AM6/8/17
to robotframe...@googlegroups.com
Hi Bryan,

I have just started to using your pageobject-library. It seems that I can use it on my new web tests.
I have a couple of questions about usage and mixins, thanks in advance.

My SUT is like a normal dashboard (main navigation items on the left side and some basic stuffs on the header (logout etc.) )

- Is it feasible to add mixin for the left navigation bar completely or divide them one mixin per navigation item ?
- While using mixins do I have to import that at the top of page object ?
    Suppose that I have a Campaign pageobject and a CreateCampaign mixin:
    To use that mixin do I have to include (from CreateCampaignMixin import CreateCampaign) it at the top of Campaign pageobject to use it like
     class(CreateCampaign, Pageobject)

- Is it possible also using more than one mixin for same page object ?
   I mean, usage like this  class (CreateCampaignMixin, HeaderMixin, PageObject)

- Do you have a real world code snipset for usage of Pageobject and mixins, that you can share publicly ?

Thaks again for your work done about pageobjects,
Nesat

Bryan Oakley

unread,
Jun 8, 2017, 8:25:42 AM6/8/17
to nes...@gmail.com, robotframework-users
You can make mixins for the whole left navigation, or one per navigation item. Whatever makes your job easier. If the exact same navigation bar is on every page it might make sense to make a single mixin, but that depends at least a little on how big that navigation mixin is.

A mixin is just a normal python class, so all of the normal rules apply. If you want to use it, you need to import it.

On Thu, Jun 8, 2017 at 6:34 AM, Nesat Ufuk <nes...@gmail.com> wrote:
Hi Bryan,

I have just started to using your pageobject-library. It seems that I can use it on my new web tests.
I have a couple of questions about usage and mixins, thanks in advance.

My SUT is like a normal dashboard (main navigation items on the left side and some basic stuffs on the header (logout etc.) )

- Is it feasible to add mixin for the left navigation bar completely or divide them one mixin per navigation item ?
- While using mixins do I have to import that at the top of page object ?
On Monday, 23 May 2016 05:23:16 UTC+3, Bryan Oakley wrote:
I've just made available a beta release of a new, lightweight page object library. 

More information is available at the following locations:

There is already a page object library for robot [1] which I used at a previous employer with great success. However, the package was abandoned by the original author, and I found it to be more complex than it needed to be. This new library is 1/4 the size, weighing in at only 400 or so lines of code and comments -- small enough for anyone to be able to dig in and understand the implementation. 

Comments and bug reports would be appreciated!

--
Bryan Oakley





--
You received this message because you are subscribed to the Google Groups "robotframework-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robotframework-users+unsub...@googlegroups.com.
To post to this group, send email to robotframework-users@googlegroups.com.

Nesat Ufuk

unread,
Jun 8, 2017, 8:30:35 AM6/8/17
to robotframework-users
Thank you Bryan,

Sorry for the inconvinience but I have edited my post I guess after you replied it.
Can you please also answer the below questions that I added


- Is it possible also using more than one mixin for same page object ?
   I mean, usage like this  class (CreateCampaignMixin, HeaderMixin, PageObject)

- Do you have a real world code snipset for usage of Pageobject and mixins, that you can share publicly ?


Thanks in advance


On Monday, 23 May 2016 05:23:16 UTC+3, Bryan Oakley wrote:

Bryan Oakley

unread,
Jun 8, 2017, 9:59:29 AM6/8/17
to nes...@gmail.com, robotframework-users
Yes, it's possible and very common to use more than one mixin. 

I don't know of any real world tests that are publicly available. The page object library itself has a demo that uses page objects, though they don't use mixins. 

I wrote a blog post about using mixins, maybe you'll find it useful: https://agiletoolsmith.wordpress.com/2016/06/05/using-mixins-with-page-objects/


--

Nesat Ufuk

unread,
Jun 15, 2017, 8:54:48 AM6/15/17
to robotframework-users
Hi Bryan,

Thank you for your response.
I come with an another question?

I want to implement the ActionChains with page-objects, how can I do this?
I can do this without page object like below,

from selenium.webdriver import ActionChains

brand_dropdown
=self.driver.find_element_by_xpath('//*[@id="main"]/div[2]/div/div/form/div[3]/div/div/div/div/div[1]')
ActionChains(browser).move_to_element(brand_dropdown).click().send_keys(brand).send_keys(Keys.ENTER).perform()



I am not able to use
self.browser
after I
import from selenium.webdriver import ActionChains


Thanks in advance





On Monday, 23 May 2016 05:23:16 UTC+3, Bryan Oakley wrote:

Bryan Oakley

unread,
Jun 15, 2017, 9:12:19 AM6/15/17
to Nesat Ufuk, robotframework-users
I do not understand the statement "I am not able to use self.browser after I import from selenium.webdriver import ActionChains". Why are you not able to use self.browser? Are you getting an error?


--

Nesat Ufuk

unread,
Jun 15, 2017, 9:32:00 AM6/15/17
to robotframework-users
Hi Bryan,

First of all, thank you for your quick responses.

I got an error:
NameError: global name 'ActionChains' is not defined

self.browser.ActionChains.move_to_element(brand_dropdown).click().send_keys(brand).send_keys(Keys.ENTER).perform()

or

ActionChains(self.browser).move_to_element(brand_dropdown).click().send_keys(brand).send_keys(Keys.ENTER).perform()

And also I am using Keys method which requires to import
from selenium.webdriver.common.keys import Keys

Regards,
Nesat




On Monday, 23 May 2016 05:23:16 UTC+3, Bryan Oakley wrote:

Bryan Oakley

unread,
Jun 15, 2017, 10:00:40 AM6/15/17
to Nesat Ufuk, robotframework-users
Before you can use ActionChains you have to import it.

--

Nesat Ufuk

unread,
Jun 15, 2017, 10:36:35 AM6/15/17
to robotframework-users
Thanks man,

Last question.
Given that I have a locators dictionary in a pageobject

_locators: {"dropdown": 'xpath=//*[@id="main"]/div[2]' }


How can I access the locator's value with self.locator to use it in a selenium instance.

I mean, when I want to get the value of locator which defined in _locators dictionary to use it at selenium instance like
self.browser.get_element_by_xpath(self.locator.dropdown)

it returns the value like xpath=//*[@id]/div[2] as it should be, but as you know, selenium instances are accepting only the locator like for xpath //**[@id]/div[2]

Do you have any suggestions ?

Best regards,

Nesat

On Monday, 23 May 2016 05:23:16 UTC+3, Bryan Oakley wrote:

Bryan Oakley

unread,
Jun 15, 2017, 11:08:20 AM6/15/17
to Nesat Ufuk, robotframework-users
You can put anything you want in _locators. If you need to put a raw xpath in there for use with selenium commands, then do that. 

For example:

    _locators: {"dropdown_xpath": "//*[@id='main']/div[2]"}
    ...
    element = self.browser.find_element_by_xpath(self.locators.dropdown_xpath)

Of course, _locators is there simply for convenience. You can use any variables that you want. 

--
Reply all
Reply to author
Forward
0 new messages