以下MWE(由Packt出版商Unmesh Gundecha在“ Selenium Testing Tools Cookbook,第二版”中进行了描述)是使用Selenium Test Framework的网站测试。

package locators;

import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.WebElement;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;

public class TableExample {

    protected WebDriver driver;

    @Before
    public void setUp() {
        driver = new ChromeDriver();
        driver.get("http://dl.dropbox.com/u/55228056/Locators.html");
    }

    @Test
    public void testWebTable() {

        WebElement simpleTable = driver.findElement(By.id("items"));

        //Get all rows
        List<WebElement> rows = simpleTable.findElements(By.tagName("tr"));
        assertEquals(3, rows.size());

        //Print data from each row
        for (WebElement row : rows) {
            List<WebElement> cols = row.findElements(By.tagName("td"));
            for (WebElement col : cols) {
                System.out.print(col.getText() + "\t");
            }
            System.out.println();
        }
    }

    @After
    public void tearDown() {
        driver.close();
    }
}


使用以下Maven pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>getting-started-with-selenium</groupId>
  <artifactId>getting-started-with-selenium</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <name>getting-started-with-selenium</name>
  <description>A quick and easy start-up browser automation framework using Selenium</description>

  <properties>
    <selenium_version>2.43.1</selenium_version>
  </properties>

  <build>
    <sourceDirectory>src/main/java</sourceDirectory>
    <testSourceDirectory>src/main/java</testSourceDirectory>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.1</version>
      </plugin>
    </plugins>
  </build>

  <dependencies>
    <dependency>
      <groupId>io.ddavison</groupId>
      <artifactId>conductor</artifactId>
      <version>[1,)</version>
    </dependency>

    <dependency>
      <groupId>org.apache.commons</groupId>
      <artifactId>commons-lang3</artifactId>
      <version>3.1</version>
    </dependency>
  </dependencies>
</project>


Conductor Framework是建立在Selenium之上的框架,该框架有望最小化Java中的Selenium编码。

AFAIK没有导体的文档,除了https://github.com/conductor-framework/conductor中的页面。

如果使用了Conductor框架,TableExample类中的testWebTable(请参见上面的测试)将如何? -是否有更多有关Conductor的文档,无论采用哪种形式?

最佳答案

通过反复试验,我发现使用Conductor框架,以下类可以正常工作。

import io.ddavison.conductor.Browser;
import io.ddavison.conductor.Config;
import io.ddavison.conductor.Locomotive;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;

import java.util.List;

import static org.junit.Assert.assertEquals;

// nilostep
@Config(
    url = "http://dl.dropbox.com/u/55228056/Locators.html", // base url that the test launches against
    browser = Browser.CHROME, // the browser to use.
    hub = "" // you can specify a hub hostname / ip here.
)

    public class TableExample2 extends Locomotive {

    @Test
    public void testWebTable2() {
        WebElement simpleTable = waitForElement(By.id("items"));

        //Get all rows
        List<WebElement> rows = simpleTable.findElements(By.tagName("tr"));
        assertEquals(3, rows.size());

        //Print data from each row
        for (WebElement row : rows) {
            List<WebElement> cols = row.findElements(By.tagName("td"));
            for (WebElement col : cols) {
                System.out.print(col.getText() + "\t");
            }
            System.out.println();
        }
    }
}

10-05 23:36