开发者

how we put dynamic input such as timestamp when using selenium plugin in firefox?

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?


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜