0

私はセレンを初めて使用し、ブラウザーを開いているが Excel シートから URL を開いていない Excel シートから情報を取得する必要があるコードを作成しました。適切な Excel パスと、行番号と列番号を設定しました。私はtestngを使用してテストケースを書いています。

Excel プログラムは次のとおりです。

    public class Excel {
        public static int getRowCount(String xlPath,String shName){
            try{
                FileInputStream fis = new FileInputStream(xlPath);
                Workbook wb = WorkbookFactory.create(fis);
                Sheet sh = wb.getSheet(shName);
                return sh.getLastRowNum()+1;

            }catch(Exception e){
                Reporter.log(e.getMessage());
                return -1;
            }


        }

        public static String getCellData(String xlPath,String shName,int row,int cell)
        {
            try{
                FileInputStream fis = new FileInputStream(xlPath);
                Workbook wb = WorkbookFactory.create(fis);
                Sheet sh = wb.getSheet(shName);
                        return sh.getRow(row).getCell(cell).getStringCellValue();

                }catch (Exception e){
                Reporter.log(e.getMessage());
                return " ";
            }

        }

    }

セルデータを取得するプログラムは次のとおりです。

        public class Config {
            public WebDriver driver;
            public ProjectSpecific ps;
            @BeforeMethod
            public void preCondition() {
            String browser = Excel.getCellData("D:\\AutomationFW\\Actitime\\testdata\\config.ods", "Sheet1", 0, 0);
          if (browser.equals("ie"))
          {
                 System.getProperty("WebDriver.ie.Driver","D:\\AutomationFW\\Actitime\\drivers\\IE8-WindowsXP-x86-ENU.exe");
              driver = new InternetExplorerDriver();

          }else if (browser.equals("chrome"))
          {
              System.getProperty("WebDriver.chrome.Driver","D:\\AutomationFW\\Actitime\\drivers\\Firefox Setup Stub 24.0.exe");
              driver = new ChromeDriver();
          }else
          {
              driver = new FirefoxDriver();
          }


      String url=Excel.getCellData("D:\\AutomationFW\\Actitime\\testdata\\config.ods", "Sheet2", 0, 0);
      System.out.println("url is " +url);
      driver.get(url);
      Reporter.log("app is opening");
      driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
      ps = new ProjectSpecific(driver);

    }

      @AfterMethod
      public void afterMethod() {
          driver.close();
          Reporter.log("app closed");

      }


    }

セレンメソッドのプログラムは次のとおりです。

            public class ProjectSpecific {
        WebDriver driver;
        ProjectSpecific(WebDriver driver){
            this.driver = driver;
        }
        public void login(String un,String pwd)
        {
            driver.findElement(By.name("username")).sendKeys(un);
            driver.findElement(By.name("pwd")).sendKeys(pwd);
            driver.findElement(By.id("loginButton")).click();
            Reporter.log("logged in");
        }
        public void logout(){
            driver.findElement(By.className("logout")).click();
            Reporter.log("logged out");
        }

        public void verifyTitle(String expTitle)
        {
            String actTitle = driver.getTitle();
            Assert.assertEquals(actTitle, expTitle);
        }

        public void navigateToCustomers()
        {
            driver.findElement(By.className("label")).click();
            driver.findElement(By.linkText("Projects & Customers")).click();

            Reporter.log("navigated to Project&Customers");
        }

        public void ClickAddNewCustomer()
        {
             driver.findElement(By.xpath("//input [@value = 'Create New Customer']")).click();
        }

        public void addNewCustomer(String customerName)
        {
            driver.findElement(By.name("name")).sendKeys(customerName);
            driver.findElement(By.name("createCustomerSubmit")).click();
        }

        public void verifySuccessMessage(String expectedMsg)
        {
            String actualMsg =                     driver.findElement(By.className("successmsg")).getText();
            Assert.assertEquals(actualMsg, expectedMsg);
            Reporter.log("verify success Message");

        }

    }

最初のテスト ケースは次のとおりです。

    public class Testcase1 extends Config {
      @Test
      public void testCase1() {
         ps.login("admin", "uTASuga7");
         //Reporter.log("logged in");
         ps.verifyTitle("actiTIME - Login");
         //Reporter.log("verified Title");
         ps.logout();
         //Reporter.log("logged out");
      }
    }

どこで間違ったのか知りたいです。

4

1 に答える 1

0

I have thought about it and tinkered around and it seems to me to be that you are using an .ods file. If I try the Excel getCellData method calling an .xls file, I can find the link. If I try with an .ods file containing the same material, I find an empty cell.

I am assuming you are using POI and it is a limitation of POI that is causing your problems, not really a selenium problem.

于 2014-01-09T20:57:26.577 に答える