Getting Data from Excel

2020-05-08 19:39发布

问题:

I need to Test an Affiliate Site , Scenario is , Click on Link , New Window get Open , Get Key from that new open source code and compare with Actual Key with Expected Key ,

I had done it , but problem is there is too many link to be capture , so what i suggested to put all link xpath , Expected Value , Actual value received from page source to an Excel File and use Apache POI to run my test cases .

Here is my code which i am working on :

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");


  }

Not getting how to proceed , a sample code is much appreciated , Thanks

My Excel Source Sheet is :