我想通过gradle开始一些测试用例。 通过终端启动以下命令后: 渐变干净的chromeTest -Durl =“ https://www.hh.de”
然后我立即在:compileTestJava 步骤中收到以下错误消息:
/home/jawar/git/seleniumHH/src/test/java/content/Tina_Tickets.java:9:
error: cannot find symbol
import org.testng.Assert;
^
symbol: class Assert
location: package org.testng.annotations
/home/jawar/git/seleniumHH/src/test/java/content/Tina_Tickets.java:10:
error: cannot find symbol
import org.testng.annotations.AfterTest;
^
symbol: class AfterTest
location: package org.testng.annotations
/home/jawar/git/seleniumHH/src/test/java/content/Tina_Tickets.java:11:
error: cannot find symbol
import org.testng.annotations.BeforeTest;
^
symbol: class BeforeTest
location: package org.testng.annotations
/home/jawar/git/seleniumHH/src/test/java/content/Tina_Tickets.java:12:
error: cannot find symbol
import org.testng.annotations.Parameters;
^
symbol: class Parameters
location: package org.testng.annotations
/home/jawar/git/seleniumHH/src/test/java/content/Tina_Tickets.java:13:
error: cannot find symbol
import org.testng.annotations.Test;
^
symbol: class Test
location: package org.testng.annotations
我的测试类保存在以下路径中: src / test / java
这是我的带有TestNG批注的测试类,我正在尝试用gradle执行该:
package content;
import java.net.MalformedURLException;
import java.util.ArrayList;
import org.openqa.selenium.By;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.Assert;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
import de.hamburg.HHTest;
import de.hamburg.browser.Chrome;
import de.hamburg.browser.Firefox;
public class Tina_Tickets extends HHTest {
@Parameters({ "platform", "browser", "version" })
@BeforeTest(alwaysRun = true)
public void setup(String platform, String browser, String version) throws MalformedURLException {
DesiredCapabilities caps = new DesiredCapabilities();
caps.setPlatform(org.openqa.selenium.Platform.WIN10);
System.setProperty("java.net.preferIPv4stack", "true");
caps.setCapability("SeleniumTests", "redhat5 && amd64");
String url = System.getProperty("url");
Assert.assertNotNull(url, "Url sollte nicht null sein");
System.err.println("URL =" + url);
System.out.println(System.getProperty("url"));
if (browser.equalsIgnoreCase("firefox")) {
driver = Firefox.initFirefox(url, driver);
driver.navigate().to(url + "/tina-turner-musical/");
} else if (browser.equalsIgnoreCase("chrome")) {
driver = Chrome.initChrome(url, driver);
driver.navigate().to(url + "/tina-turner-musical/");
} else {
throw new IllegalArgumentException("The Browser Type is undefined");
}
}
@AfterTest
public void afterTest() {
driver.quit();
}
/**
*
* @throws InterruptedException
*/
@Test(description = "Calculating Test")
public void checkTickets() throws InterruptedException {
if (driver.findElement(By.xpath("/html//span[@id='articleText']//button[.='Tickets buchen']")).isDisplayed()) {
RanorexWaitXpath("/html//span[@id='articleText']//button[.='Tickets & Hotel buchen']");
RanorexWaitXpath("//span[@id='articleText']//div[@class='slideshow-container']");
RanorexWaitXpath("/html//span[@id='articleText']//div[@class='links-n-buy']");
RanorexXpathClick("/html//span[@id='articleText']//button[.='Tickets buchen']");
ArrayList<String> tabs2 = new ArrayList<String>(driver.getWindowHandles());
driver.switchTo().window(tabs2.get(1));
String url1 = driver.getCurrentUrl();
System.out.println(url1);
driver.close();
driver.switchTo().window(tabs2.get(0));
RanorexWaitXpath("/html//span[@id='articleText']//button[.='Tickets & Hotel buchen']");
RanorexXpathClick("/html//span[@id='articleText']//button[.='Tickets & Hotel buchen']");
RanorexWaitXpath("//div[@id='main']/div");
String url2 = driver.getCurrentUrl();
System.out.println(url2);
}
}
}
这是我的build.gradle脚本:
apply plugin: 'java'
apply plugin: 'eclipse'
jar {
version '1.0'
baseName 'SeleniumStarter'
extension '.jar'
}
description = "Gradle Selenium WebDriver"
sourceCompatibility = 1.8
targetCompatibility = 1.8
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
repositories {
mavenCentral()
mavenLocal()
}
ext.seleniumVersion = '3.12.0'
dependencies {
compile group: 'org.seleniumhq.selenium', name: 'selenium-java', version:seleniumVersion
compile group: 'org.seleniumhq.selenium', name: 'selenium-server', version:seleniumVersion
compile group: 'org.seleniumhq.selenium', name: 'selenium-edge-driver', version:seleniumVersion
compile group: 'org.seleniumhq.selenium', name: 'selenium-firefox-driver', version:seleniumVersion
compile group: 'org.seleniumhq.selenium', name: 'selenium-chrome-driver', version:seleniumVersion
compile group: 'org.seleniumhq.selenium', name: 'selenium-api', version:seleniumVersion
compile group: 'org.seleniumhq.selenium', name: 'selenium-java', version:seleniumVersion
compile group: 'org.uncommons', name: 'reportng', version:'1.1.4'
testCompile group: 'junit', name: 'junit', version:'4.12'
testCompile group: 'org.testng', name: 'testng', version:'6.11'
}
task chromeTest (type: Test) {
useTestNG() {
suites 'src/test/resources/hhde.xml'
}
systemProperties(System.getProperties())
println System.properties['url']
testLogging.showStandardStreams = true
}
eclipse {
classpath {
containers 'org.springsource.ide.eclipse.gradle.classpathcontainer'}
}
// A custom task to show report on tests that have run
task viewResults(dependsOn: ['seleniumTest','contentTest'] , type:Exec) {
workingDir './build/reports/tests'
commandLine 'cmd', '/c', 'start index.html'
}
task wrapper(type: Wrapper) {
gradleVersion = '2.10' //we want gradle 2.10 to run this project
}
task logInfo (dependsOn: ['seleniumTest','contentTest']){
logging.captureStandardOutput LogLevel.INFO
doLast {
println 'test'
println System.properties['url']
println 'url'
}
task printProps {
doLast {
println commandLineProjectProp
println gradlePropertiesProp
println systemProjectProp
println envProjectProp
println System.properties['system']
}
}
}
我将非常高兴获得任何帮助。