gpt4 book ai didi

java - 如果使用 Conductor 框架,这个测试用例(使用 Selenium WebDriver 用 Ja​​va 编写)会是什么样子?

转载 作者:行者123 更新时间:2023-11-30 02:48:29 24 4
gpt4 key购买 nike

以下 MWE(由 Packt 出版商出版的 Unmesh Gundecha 出版的《Selenium 测试工具手册,第 2 版》中描述)是使用 Selenium 测试框架进行的网站测试。

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 构建的框架,它 promise 最大限度地减少 Java 中的 Selenium 编码。

据我所知,除了 https://github.com/conductor-framework/conductor 页面之外,没有关于 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();
}
}
}

关于java - 如果使用 Conductor 框架,这个测试用例(使用 Selenium WebDriver 用 Ja​​va 编写)会是什么样子?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39425900/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com