从Excel获取数据

时间:2015-08-12 11:38:58

标签: selenium-webdriver webdriver apache-poi

我需要测试一个会员网站, 场景是,单击链接,新窗口打开,从新的开源代码获取密钥,并与实际密钥与预期密钥进行比较,

我已经完成了,但问题是有太多的链接被捕获,所以我建议将所有链接xpath,预期值,从页面源接收的实际值到Excel文件并使用Apache POI运行我的测试案例。

这是我正在处理的代码:

public void test() throws Exception
{
    String home_logo_url="158321";
    String enough_talk_promo="1057406";

    System.out.println("Check for home_logo_url");  
    driver.get(baseUrl);
    String SiteWindow = driver.getWindowHandle(); // get the current window handle
    driver.findElement(By.xpath("//*[@id='logo']/a")).click();
    for (String PromoWindow : driver.getWindowHandles()) 
    {
        driver.switchTo().window(PromoWindow); // switch focus of     WebDriver to the next found window handle (that's your newly opened window)
    }
        String script = "return rlSerial;";
        String value = (String) ((JavascriptExecutor)driver).executeScript(script);
        Assert.assertEquals(value,home_logo_url);
        driver.close();
        driver.switchTo().window(SiteWindow);
        System.out.println("Pass");

        System.out.println("Check for enough_talk_promo");
        driver.get(baseUrl + "/category/tournaments/");
        driver.findElement(By.xpath("//*[@id='content']/div/div[4]/aside/div/div/p[1]/a")).click();
        for (String PromoWindow : driver.getWindowHandles())
        {
            driver.switchTo().window(PromoWindow); // switch focus of WebDriver to the next found window handle (that's your newly opened window)
        }
        String sr_enough_talk_promo = (String) ((JavascriptExecutor)driver).executeScript(script);
        Assert.assertEquals(sr_enough_talk_promo,enough_talk_promo);
        driver.close();
        driver.switchTo().window(SiteWindow);
        System.out.println("Pass");


  }

没有得到如何处理,非常感谢示例代码,谢谢

我的Excel资料表是:

I had Attached my excel data source for clearing my test cases

0 个答案:

没有答案