我想在 Jenkins 中运行我的测试 Selenium 。我使用 Maven 和 Testng 在 jenkins 中运行我的测试。我有一个简单的配置来做到这一点:
package Testselenium;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.Assert;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.AfterTest;
public class NewTest {
private WebDriver driver;
@Test
public void testEasy() {
driver.get("http://localhost");
String title = driver.getTitle();
Assert.assertTrue(title.contains("TimDevOps"));
}
@BeforeTest
public void beforeTest( ) {
driver = new FirefoxDriver();
}
@AfterTest
public void afterTest() {
driver.close();
}
}
我想配置与 Selenium IDE 中所做的相同的测试,但是当我提取 java 文件并替换上面的配置时,它不起作用:
package com.example.tests;
import com.thoughtworks.selenium.*;
import java.util.regex.Pattern;
public class test extends SeleneseTestCase {
public void setUp() throws Exception {
setUp("http://localhost/", "*chrome");
}
public void testTest() throws Exception {
selenium.open("/");
selenium.click("css=input[type=\"button\"]");
selenium.click("css=input[type=\"button\"]");
selenium.click("css=input[type=\"button\"]");
selenium.click("css=input[type=\"button\"]");
}
}
Eclipse 不知道 selenium 对象。
有人知道如何混合这两个文件吗?预先感谢您
最佳答案
我不确定我是否理解您的问题。但我猜这就是你想要的。
package Testselemium;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.Assert;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import com.thoughtworks.selenium.*;
public class NewTest extends SeleneseTestCase {
private WebDriver driver;
@Test
public void testEasy() {
driver.get("http://localhost");
String title = driver.getTitle();
Assert.assertTrue(title.contains("TimDevOps"));
}
@Test
public void testTest() throws Exception {
selenium.open("/");
selenium.click("css=input[type=\"button\"]");
selenium.click("css=input[type=\"button\"]");
selenium.click("css=input[type=\"button\"]");
selenium.click("css=input[type=\"button\"]");
}
@BeforeTest
public void beforeTest() {
driver = new FirefoxDriver();
}
@AfterTest
public void afterTest () {
driver.close();
}
}
关于java - 测试 Selenium Jenkins ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37294950/