dongshou9878 2010-08-04 08:50
浏览 82
已采纳

我们如何在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?

  • 写回答

1条回答 默认 最新

  • dqqyp90576 2010-08-04 09:37
    关注

    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)