如何编写selenium web驱动程序代码以使用数据驱动测试验证多个用户帐户(娱乐)?

时间:2013-10-07 08:57:57

标签: selenium-webdriver

在该代码中,例如,如果用户无法访问娱乐网站,则它将显示“立即升级”或“立即订阅”页面(相关的有线电视提供商订阅页面)。

我不知道如何编写下面提到的场景的逻辑。请帮助我(我是java和Web驱动程序的初学者)

场景1:。在Excel工作表中,我首先提到第二列(订阅页面帐户)中的可访问帐户(第1列),第3列(能够观看/访问)帐户)然后在第4列(订阅帐户)..

场景2:验证并在Excel工作表中打印。 请帮我怎么写逻辑。

@Test
    public void PlayOnCheck() throws ArrayIndexOutOfBoundsException,
            BiffException, IOException, Exception {

        FileInputStream f = new FileInputStream(
                "D:\\Eclipse Screenshots\\DataDrive.xls");

        Workbook w = Workbook.getWorkbook(f);
        s = w.getSheet(0);

        System.out.println(s.getRows());



        for (int row = 1; row <= s.getRows() - 1; row++) {

            driver.findElement(By.xpath("/html/body/div/div[3]/div/div[2]/div[2]/div[2]/a")).click();
            driver.switchTo().frame(driver.findElement(By.xpath("//iframe[@id ='videoPlayer']")));
            WebElement we = driver.findElement(By.xpath("//body//div[@class = 'player']//a[@class = 'signinButton med2pxRound']"));
            we.click();

            String username = s.getCell(0, row).getContents();
            System.out.println("Username " + username);

            driver.findElement(By.name("user")).sendKeys(username);

            String password = s.getCell(1, row).getContents();

            System.out.println("Password " + password);

            driver.findElement(By.name("passwd")).sendKeys(password);
            driver.findElement(By.id("sign_in")).click();



             if(driver.getCurrentUrl().matches(" subscription page url")){

                    if(driver.findElement(By.xpath("//div[@id = 'content']//a[@class = 'button']")).isDisplayed()){

                        WebElement a = driver.findElement(By.xpath("/html/body/div[3]/div/h1"));
                        System.out.println("Subscribe Now Button is displayed   " +  a.getText());
                    }


                    continue;
                }

             else if(driver.findElement(By.xpath("//div[@class = 'mainVideoContainer']")).isEnabled()){

                driver.switchTo().frame(driver.findElement(By.xpath("//iframe[@id ='videoPlayer']")));

                if(driver.findElement(By.xpath("//body//div[@class = 'player']//*[@id='StrobeMediaPlayback'] ")).isEnabled()){

                    System.out.println("Video Player enabled and Video starts playing");

                }
                driver.switchTo().defaultContent();
                driver.findElement(By.linkText("Sign Out")).click();
            }


            else if (driver.findElement(By.linkText("Sign Out")).isDisplayed()) {

                System.out.println("User is logged in");


            }
            else{
                System.out.println("OOPS!!!!! Something has happened and Video not starts playing at the moment");
            }

        }

如果我运行上面的代码,我能够识别订阅页面帐户,但在执行订阅帐户后,我无法切换到能够观看帐户。请帮助我。

0 个答案:

没有答案