使用Selenium RC,Excel(数据驱动)和SeleniumException

时间:2012-06-11 17:46:29

标签: excel selenium selenium-rc data-driven-tests

我正在开展一个自动化项目,即在特定网站上创建一个帐户。 需要检查不同的规则集。需要有一组数据,其中缺少某些必填字段,用于在帐户上创建的电子邮件地址已在系统上使用,最后一组是可以创建帐户的位置。该过程的一般流程是:

  1. 运行SeleniumRC
  2. 从ExcelFile获取数据

    Excel数据由不同的集合组成。 设置A:缺少必需的Fille 设置B:已使用电子邮件地址 设置B:完整/正确的数据

  3. 访问网站。

  4. 输入所有数据。

    如果设置为A:

    Then creation will not process.
    It will provide output:
        Row Number - Error
    

    如果设置为B:

    Then creation will not process.
    It will provide output:
        Row Number - Error
    

    如果设置为C:

    It will create account.
    

    提供屏幕截图盎司登录

  5. 返回步骤2,直到完全检查Excel文件中找到的所有行。

  6. 输出将放在另一个Excel文件
  7. 我可以运行该过程,但是如果我在Excel文件中为每个条目使用一个标志。这确实违背了检查创建过程按预期工作的目的。 我的Selenium命令是这样的:

       public void test_CreateAccount() throws Exception {
    
        //Some code to data from Excel Sheet
        totalrows = s.getRows();
        int i = 1;
    
        while(i<totalrows){
        //Some command to set data to string names
        RowNum = s.getCell(0, i).getContents();
        FName = s.getCell(1, i).getContents();
    
        selenium.open // Go to a specific site
        selenium.click("css=a > img"); // click create account
                        selenium.waitForPageToLoad("60000");
                        selenium.type("name=q1557", FName);
                        selenium.type("name=q1558", LName);
                        selenium.type("name=q1578", JobTitle);
                        selenium.type("name=q1579", email1);
                        selenium.type("name=email_confirm", email2);
                        selenium.type("name=q1583", phone);
                        selenium.type("name=q1584", ext);
                        selenium.type("name=q1585", fax);
                        selenium.type("name=q1587", company);
                        selenium.select("name=q1588", organization);
                        selenium.type("name=q1591", address1);
                        selenium.type("name=q1592", address2);
                        selenium.type("name=q1593", city);
                        selenium.select("name=q1594",state);
                        selenium.type("name=q1595", other);
                        selenium.type("name=q1598", zip);
                        selenium.select("name=q1596", country);
                        selenium.type("name=q1599", password1);
                        selenium.type("name=password_confirm", password2);
                        selenium.type("name=q1600", question);
                        selenium.type("name=q1601", answer);
        selenium.click("name=submit_signup");    // click submit
    
    
        i = i + 1;
        }
    
    }
    

    当我运行上面的命令时,这确实有效。如果数据是SET A或B,则发生错误。如果数据是SET C,那么它将创建然后完成。

    为了检查Excel文件中的所有数据或继续直到总计结束,我放置了一个标志。

    在命令的中间我放置了类似

    的内容
    if(flag=1){ //input process only until submit button. }else
    if(flag=2){ //input process only until submit button. }else{ create
    }
    

    我尝试使用try和catch SeleniumException然而它仍然无效。你能告诉我如何做到这一点。

0 个答案:

没有答案