2016-09-10 89 views
1

以下MWE(由Packt publishers出版的Unmesh Gundecha的「Selenium Testing Tools Cookbook,2nd ed。」中描述)是使用Selenium測試框架的網站測試。這個測試用例(使用Selenium WebDriver編寫的Java)如何看起來像是使用了Conductor框架?

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> 

指揮框架是建立在硒這將減少在Java中硒編碼的框架。

AFAIK除了在https://github.com/conductor-framework/conductor處的頁面外,沒有關於導體的文檔。

如果使用Conductor框架,TableExample類中的testWebTable如何看起來像? - 是否有更多有關導體的文檔,無論以何種形式?

回答

2

通過試驗和錯誤我發現使用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(); 
     } 
    } 
} 
+1

您的兩個測試(Selenium問題和Conductor答案)看起來非常相似,除了配置註釋。我來到這裏是因爲你的reddit-post,在那裏你想知道Conductor是否比純硒有什麼優勢 - 在你嘗試兩種方法之後,你有沒有什麼見解可以分享? – Hervian

相關問題