perl-selenium:如何使用自定义方法扩展 Test::WWW::Selenium 对象?

发布于 2024-10-27 14:31:24 字数 1489 浏览 4 评论 0原文

使用perl和TAP,我编写了很多selenium测试并将它们保存在*.t文件中。

我创建了一些辅助函数,将它们放入非面向对象的包中,例如 My::Util::SeleniumHelper。

所有功能均从此模块导出。 一开始,一个包就足够了,现在单模块 API 包含了相当多不相关的功能。调用这些函数,例如make_sel(), head_ok(), cms_logout(), CMS_登录(), cms_clickthru_simple(), selenium_rc_running(), treecontrol_toggles() - 你明白了。

此外,t 文件中的许多代码块仍然是多余的,使得 .t 文件看起来像一个模板。

因此,我想给我的*.t代码更多的OO设计。

关于如何设计新 API 有什么想法吗?

本质上,我也在寻找代码示例(在这里或在互联网上),其中有人以巧妙的方式扩展了 selenium 对象。它不必在 perl 中。

向 Test::WWW::Selenium 对象 $sel 添加方法会有用吗?

$sel->my_click_ok()

我应该尝试覆盖 $sel 对象吗?从 Test::WWW::Selenium 派生 Test::WWW::Selenium::Customized 类

这会违反 “更喜欢组合而不是继承”习惯用法

我应该使用组合将 selenium 对象包装到另一个对象中吗?

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

以下是更多要求或想法:

我还想使用 pageObjects Pattern/Idiom。还没有这样做。 也许是这样

$myobj->{current_page}->loginbox

,或者

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

我注意到,在大多数情况下,基本上,我想给 selenium 方法一些类似于 Moose 的 around() 修饰符的东西。做标准的事情,但在之前和之后做一些事情。

然而,我不想在这里使用 Moose,因为测试需要在几台不同的机器上运行,并且不想在所有这些 PC 上安装 Moose 及其所有依赖项。我并不是说不可能使用 moose,但是我还没有同时使用非 moose 对象 (Test::WWW::Selenium) 和 moose 对象。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

逆光下的微笑 2024-11-03 14:31:24

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

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.

心安伴我暖 2024-11-03 14:31:24

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

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.

过气美图社 2024-11-03 14:31:24

我正在对 Test::WWW::Selenium 进行子类化。 new {} 需要调用 SUPER,但随后,它看起来和尝起来都像父级。我有一个新的 open() 来检查 HTML 并检查链接(当然是记忆的)。

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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文