Mic*_*ann 5 javascript python java selenium webdriver
I am developing a library that extends Selenium 2 with some custom commands. The library should be usable from Selenium's Java and Python bindings as well as in Selenium IDE. From my research, these three target bindings should cover at least 80% of all Selenium 2 scripts.
In order to implement my custom commands for Selenium IDE, I think I need to write a plugin for it in JavaScript.
My question is this: If I already have an implementation of my custom commands in JavaScript, is it safe to re-use this implementation for the Java- and Python bindings of my library?
I am thinking of an approach that injects the JavaScript implementation of my commands via WebDriver#executeScript. Here is a pseudocode implementation of what I am thinking of.
In Java:
public void fooJava() {
executeScript("Inject code.js");
executeScript("fooJavaScript();");
}
Run Code Online (Sandbox Code Playgroud)
In code.js:
function fooJavaScript() {
// Implementation of command "foo" from Selenium IDE plugin.
}
Run Code Online (Sandbox Code Playgroud)
So, to execute my custom command fooJava() in Java, my library's code.js would be injected into the browser via executeScript. This would contain a JavaScript implementation of foo, say fooJavaScript. In a next executeScript call, this fooJavaScript would then be called.
While this approach would prevent me from having to implement my custom commands three times (Java, Python, Selenium IDE), I have a few concerns:
code.js, am I in danger of destroying global state of the web site?HtmlUnit?Your real-life experiences with this would be much appreciated.
原则指出,如果您只是使用 WebDriver 传递有效负载,则不应使用 JS 作为测试机制。
WebDriver = 集成测试
JS = 如果你想要单元测试
我不太清楚你的用例,但是:
如果您尝试运行集成测试,请坚持使用 WebDriver 以最好地模拟用户交互。您还可以通过依赖 WebDriver 挂钩与页面交互来避免将来出现跨浏览器 JS 问题,例如,您最好依赖社区为每个浏览器提供可靠的基本 DOM 交互 API。如果您无法通过浏览器交互触发测试条件,那么您将进入单元/代码测试领域,而不是集成测试。
如果您尝试运行 JS 主要是为了测试单个函数或一段代码而不是集成交互,那么您正在尝试运行单元测试。单元测试最好在 JS 中使用 Jasmine 之类的东西(在这里命名任何框架)来完成。
推理:
集成测试应尽可能独立于实现编写。您不需要知道函数名称来触发集成测试,因为将来有人可能会更改函数名称或重组代码。
由于您正在担任 QE/测试人员角色,因此您不想在代码更改时负责破坏集成测试 - 如果您使用此功能并负责,那么每次代码重组时您都需要更改测试。
资料来源:在 10,000 多名员工的软件公司担任 QE 的经验。
| 归档时间: |
|
| 查看次数: |
502 次 |
| 最近记录: |