代码之家  ›  专栏  ›  技术社区  ›  Hars

使用Selenium IDE将html测试导出到Junit4/Webdriver时出错

  •  1
  • Hars  · 技术社区  · 11 年前

    当导出到JUnit4(Webdriver)时,我有以下selenium IDE代码返回错误。

    虽然当我将其导出为Selenium RC时,它工作得很好。

    请告诉我以下错误的等效网络驱动程序--

    IDE代码:

    <tr>
    <td>deleteAllVisibleCookies</td>
    <td></td>
    <td></td>
    </tr>
    
    <tr>
    <td>open</td>
    <td>/index.html</td>
    <td></td>
    </tr>
    
    <tr>
    <td>selectFrame</td>
    <td>content</td>
    <td></td>
    </tr>
    
    <tr>
    <td>select</td>
    <td>librarySelect</td>
    <td>label=XYZ Software Inc.</td>
    </tr>
    
    <tr>
    <td>type</td>
    <td>userNameInput</td>
    <td>demoUser</td>
    </tr>
    
    <tr>
    <td>type</td>
    <td>passwordInput</td>
    <td>demoPassword</td>
    </tr>
    
    <tr>
    <td>clickAndWait</td>
    <td>submitButton</td>
    <td></td>
    </tr>
    .......
    <tr>
    <td>clickAndWait</td>
    <td>link=Admin</td>
    <td></td>
    </tr>
    .......
    

    导出的Web驱动程序代码:[包含错误]

    @Test
    public void testArchivalLogReport() throws Exception {
    // ERROR: Caught exception [ERROR: Unsupported command [deleteAllVisibleCookies |  | ]]
    driver.get(baseUrl + "/index.html");
    // ERROR: Caught exception [ERROR: Unsupported command [selectFrame | content | ]]
    // ERROR: Caught exception [Error: locator strategy either id or name must be specified explicitly.]
    // ERROR: Caught exception [Error: locator strategy either id or name must be specified explicitly.]
    // ERROR: Caught exception [Error: locator strategy either id or name must be specified explicitly.]
    // ERROR: Caught exception [Error: locator strategy either id or name must be specified explicitly.]
    // ERROR: Caught exception [ERROR: Unsupported command [selectFrame | relative=up | ]]
    // ERROR: Caught exception [ERROR: Unsupported command [selectFrame | menu | ]]
    driver.findElement(By.linkText("Admin")).click();
    // ERROR: Caught exception [ERROR: Unsupported command [selectFrame | relative=up | ]]
    // ERROR: Caught exception [ERROR: Unsupported command [selectFrame | content | ]]
    driver.findElement(By.xpath("//td[11]/span/b")).click();
    // ERROR: Caught exception [Error: locator strategy either id or name must be specified explicitly.]
    // ERROR: Caught exception [ERROR: Unsupported command [selectWindow | name=content | ]]
    // ERROR: Caught exception [ERROR: Unsupported command [selectFrame | name=content | ]]
    // Warning: verifyTextPresent may require manual changes
    try {
      assertTrue(driver.findElement(By.cssSelector("BODY")).getText().matches("^[\\s\\S]*Data Extract[\\s\\S]*$"));
    } catch (Error e) {
      verificationErrors.append(e.toString());
    }
    // ERROR: Caught exception [ERROR: Unsupported command [selectFrame | relative=up | ]]
    // ERROR: Caught exception [ERROR: Unsupported command [selectFrame | menu | ]]
    driver.findElement(By.xpath("//a/font")).click();
    }
    

    导出的RC代码很好,看起来像:

    @Test
    public void testArchival Log Report() throws Exception {
        selenium.deleteAllVisibleCookies();
        selenium.open("/index.html");
        selenium.selectFrame("content");
        selenium.select("librarySelect", "label=XYZ Software Inc.");
        selenium.type("userNameInput", "demoUser");
        selenium.type("passwordInput", "demoPassword");
        selenium.click("submitButton");
        selenium.waitForPageToLoad("30000");
        selenium.selectFrame("relative=up");
        selenium.selectFrame("menu");
        selenium.click("link=Admin");
    ..........
     }
    

    我如何导出? 我正在使用Java/Juit 4/Webdriver

    我能看见 Java/Juit 4/Webdriver支持 可选地, 我应该这么做吗?? 它给了我与Selenium RC选项相同的导出文件,唯一的变化是我们如何获取webdriver。

    1 回复  |  直到 11 年前
        1
  •  1
  •   Hars    11 年前

    我使用Webdriver API解决了这个问题:

     @Test
     public void testArchivalLogReport()
        throws Exception
     {
    
        driver.manage().deleteAllCookies();
    
        driver.get(baseUrl + "/index.html");
        driver.switchTo().frame("content");
        Select library = new Select(driver.findElement(By.id("librarySelect")));
        library.selectByVisibleText("XYZ Software Inc.");
        driver.findElement(By.name("userInput")).sendKeys("username");
        driver.findElement(By.name("passwordInput")).sendKeys("password");
        driver.findElement(By.name("submitButton")).click();
    
        WebDriverWait wait = new WebDriverWait(driver, 120);
        wait.until(ExpectedConditions.elementToBeClickable(By
            .linkText("Admin")));
    
        // Store the window handle of the parent window, so that you can switch
        // back to it later.
        String wHandle = driver.getWindowHandle();
    
        driver.findElement(By.linkText("XYZ")).click();
        driver.findElement(By.xpath("//td[11]/span/b")).click();
        driver.findElement(By.id("someLink")).click();
    
        try
        {
            assertTrue(driver.findElement(By.cssSelector("BODY")).getText()
                .matches("^[\\s\\S]*Data Extract[\\s\\S]*$"));
        }
        catch (Error e)
        {
            verificationErrors.append(e.toString());
        }
    
        // Switch back to parent window using stored window handle
        driver.switchTo().window(wHandle);
        driver.switchTo().frame("menu");
        driver.findElement(By.xpath("//a/font")).click();
    
    }