Как будет выглядеть этот тестовый сценарий (написанный на Java с использованием Selenium WebDriver), если используется среда Conductor?
Следующее MWE (описанное в "Сборнике инструментов для тестирования Selenium, 2-е изд." Unmesh Gundecha, опубликованном издателями Packt) представляет собой тестирование веб-сайта с использованием 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, который обещает минимизировать кодирование Selenium в Java.
AFAIK нет документации для Conductor, за исключением страницы по адресу https://github.com/conductor-framework/conductor.
Как будет выглядеть testWebTable в классе TableExample (см. Тест выше), если используется среда Conductor? - Есть ли еще документация о проводнике, в какой бы то ни было форме?
1 ответ
Методом проб и ошибок я обнаружил, что при использовании структуры 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();
}
}
}