开发者

perl-selenium: how to extend Test::WWW::Selenium object with custom methods?

Using perl and TAP, I have written a lot of selenium tests and saved them in *.t files.

I have created some helper functions, put them into a non-object oriented package, say My::Util::SeleniumHelper.

All functions are exported from this module. In the beginning, one package was sufficient, now the single-module API contains quite a few unrelated functions. These functions are called, for example make_sel(), head_ok(), cms_logout(), cms_login(), cms_clickthru_simple(), selenium_rc_running(), treecontrol_toggles() - you get the idea.

Moreover, many blocks of code in the t-files are still redundant, making the .t file look like a template.

Thus, I want to give my *.t code a more OO design.

Any ideas on how to design the new API?

Essentially, I am also looking for code examples (here, or on the internet) where someone has extended the selenium object in a clever way. It does not have to be in perl.

Would it be useful to add methods to the Test::WWW::Selenium object $sel?

$sel->my_click_ok()

I should I try to override the $sel object?, Deriving a Test::WWW::Selenium::Customized class from Test::WWW::Selenium

This would violate the "Prefer composition over inheritance" idiom

Should I wrap the selenium object into another object using composition?

$myobj->{sel}->click_ok()

Here are some more requirements or thoughts:

I also want to use the pageObjects Pattern/Idiom. Not doing so yet. Maybe so

$myobj->{current_page}->loginbox

or

$myobj->do_stuff($current_page->loginbox)

I noted that in most cases, basically,开发者_高级运维 I'd like to give the selenium method something like an Moose's around() modifier. Do th standard thing, but do some things before and after.

However, I prefer to not use Moose here because the tests need to run on a few different machines, and don't want to install Moose and all its dependencies on all these PCs. I am not saying that is impossible to use moose, however I did not yet use non-moose objects (Test::WWW::Selenium) and moose objects together.


I'm using Moose and delegation to extend Test::WWW::Selenium. The only thing thats in the extension is configuration stuff (host, port, browser, etc). Everything else is in roles.


Making a custom class inheriting from the Selenium one seems completely reasonable in this case. Eric's Moose delegation solution is a little cleaner; but a bit more complicated too.


I'm subclassing Test::WWW::Selenium. new {} needs to call SUPER, but then on, it looks and tastes like the parent. I've got a new open() that lints the HTML and checks links (memoized of course).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜