1
我使用硒。我使用它通过使用Firefox插件。但我有问题利用它。例如,我需要做一个100个帖子(我需要他们有不同的标题,范围从1到100),而不必复制粘贴上一个命令并更改其属性值当我们在Firefox中使用硒插件时,我们如何设置动态输入如时间戳?
如果我的描述是太模糊了。简而言之,就是如何在输入是动态的情况下创建单位套装。是否有可能使用硒插件?
我使用硒。我使用它通过使用Firefox插件。但我有问题利用它。例如,我需要做一个100个帖子(我需要他们有不同的标题,范围从1到100),而不必复制粘贴上一个命令并更改其属性值当我们在Firefox中使用硒插件时,我们如何设置动态输入如时间戳?
如果我的描述是太模糊了。简而言之,就是如何在输入是动态的情况下创建单位套装。是否有可能使用硒插件?
您需要将IDE测试用例从IDE导出到您选择的编程语言中,然后对其进行调整。
考虑这个样品的Selenese测试 - 在硒IDE重新排序,它导航到一些论坛,点击“新话题”按钮,进入标题为“标题50”,然后点击“发布”按钮:
open | /viewforum.php?f=19 | |
clickAndWait | btnNewPost | |
type | subject | Title 50 |
clickAndWait | btnPost | |
在此之后,你这个测试导出为Java的JUnit的(例如)
,你会得到下面的代码:
package com.example.tests;
import com.thoughtworks.selenium.*;
import java.util.regex.Pattern;
public class PostTest extends SeleneseTestCase {
public void setUp() throws Exception {
setUp("http://www.forum.com/", "*chrome");
}
public void testCreatePost() throws Exception {
selenium.open("/viewforum.php?f=19");
selenium.click("btnNewPost");
selenium.waitForPageToLoad("30000");
selenium.type("subject", "Title 50");
selenium.click("btnPost");
selenium.waitForPageToLoad("30000");
}
}
所以,你需要做的就是添加一个循环,将创建主题的帖子“标题001 “至”Title 100“:
public void testCreatePost() throws Exception {
for (int i=1; i<=100; i++) {
selenium.open("/viewforum.php?f=19");
selenium.click("btnNewPost");
selenium.waitForPageToLoad("30000");
selenium.type("subject", String.format("Title %03d", i));
selenium.click("btnPost");
selenium.waitForPageToLoad("30000");
}
}
您需要硒RC运行这个测试 - 请参考[使用Selenium IDE使用随机值]的Selenium documentation
可能重复(http://stackoverflow.com/questions/161984/using-selenium -ide与 - 随机值) – 2010-08-04 09:52:42