我们如何在firefox中使用selenium插件时输入动态输入,如时间戳?
i'm use selenium. i use it by using firefox plugin. but i have problem to utilize it. For example, i need to make a 100 post(I need them has different title, range from 1-100) without i have to copy-paste previous command and change its property value
i'm sorry if my description is too vague. In nutshell, it's about how to create unit suits where the input is dynamic. is it possible using selenium pluggin?
我使用的是selenium。 我通过使用firefox插件使用它。 但我有利用它的问题。 例如,我需要发一个100帖子(我需要它们有不同的标题,范围从1-100)没有我必须复制粘贴上一个命令并更改其属性值 p>
我 对不起,如果我的描述太模糊了。 简而言之,它是关于如何创建输入是动态的单位套装。 是否可以使用selenium pluggin? p> div>
You will need to export the Selenium test case from the IDE into the programming language of your choice and then tweak it.
Consider this sample Selenese test - reordered in Selenium IDE, it navigates to the some forum, clicks "New Post" button, enters the title as "Title 50" and then clicks the "Post" button:
open | /viewforum.php?f=19 | |
clickAndWait | btnNewPost | |
type | subject | Title 50 |
clickAndWait | btnPost | |
After that you export this test as Java JUnit (for example) and you get the following code:
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");
}
}
So what you need to do is to add a loop that will create posts with titles "Title 001" to "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");
}
}
You will need Selenium RC to run this tests - please refer to the Selenium documentation