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