0

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.

4

3 回答 3

1

在这种情况下,创建一个从 Selenium 继承的自定义类似乎是完全合理的。Eric 的 Moose 委托解决方案更简洁一些;但也有点复杂。

于 2011-06-10T08:58:34.340 回答
1

我正在继承 Test::WWW::Selenium。new {} 需要调用 SUPER,但随后,它的外观和味道都像父级。我有一个新的 open() 可以检查 HTML 并检查链接(当然要记住)。

于 2012-05-18T12:40:13.847 回答
1

我正在使用 Moose 和委托来扩展 Test::WWW::Selenium。扩展中唯一的东西是配置内容(主机、端口、浏览器等)。其他一切都在角色中。

于 2011-06-10T07:54:16.343 回答