2016-09-10 5 views
1

次のMWE(Packetパブリッシャーが発行するUnmesh Gundechaの「Selenium Testing Tools Cookbook、2nd ed。」に記載されています)は、Selenium Test Frameworkを使用したWebサイトテストです。このテストケース(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(); 
    } 
} 

<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> 

指揮FrameworkはJavaでSeleniumのコーディングを最小限に抑えることを約束セレンの上に構築されたフレームワークであり、次のMavenのpom.xmlを使用してください。

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

あなたの2つのテスト(質問のSeleniumと回答のConductor)は、Config-annotationを除いて非常に似ています。あなたのレッドポストのために私はここに来ました。コンダクターが純粋なセレンに対して何らかの利点を提供してくれるのか疑問に思っていました。 – Hervian

関連する問題