我对Selenium和Automation很新。使用Selenium IDE和我对Java的一般知识,我能够在Eclipse中制作一系列在JUnit上运行的测试用例。现在我的测试在eclipse中运行,然后按[run]。我想将这些测试用例导入Jenkins/Hudson。有两种方法我更喜欢做CI。如何获得在Jenkins上运行的Selenium/WebDriver测试?
安排时间(每周一次)运行测试并发送结果电子邮件。
将我的测试用例上传到GitHub上的存储库,当存储库发生更改时,运行测试和/或按计划(每周一次)。
我诚实地试图查找教程(视频/文档),但他们都似乎很不清楚。举个例子,我不知道build.xml或POM是什么。
使用Jenkins插件或使用ANT或Maven做这件事更好吗?如果是这样,我需要在代码中添加/更改以允许发生这种情况,并在Jenkins中进行配置。
我的示例代码如下:
package Profile;
import java.util.concurrent.TimeUnit;
import java.util.regex.Pattern;
import java.util.concurrent.TimeUnit;
import org.junit.*;
import static org.junit.Assert.*;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.Select;
import com.opera.core.systems.scope.protos.ExecProtos.ActionList.Action;
public class P_ProfileChangeTestCase {
private WebDriver driver;
private String baseUrl;
private StringBuffer verificationErrors = new StringBuffer();
//Before the test begins, creates a new webdriver and sets the base url
@Before
public void setUp() throws Exception {
driver = new FirefoxDriver();
baseUrl = "http://www.test.com/";
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
}
@Test
public void testOpen() throws Exception {
System.out.println("**Starting Profile**");
driver.get(baseUrl);
//Click LogIn
System.out.println("Clicking Log In");
driver.findElement(By.cssSelector("div.button.login > a.link")).click();
//Enter User name
System.out.println("Entering Username");
driver.findElement(By.xpath("//input[@id='login']")).sendKeys("TEST");
//Enter Password
System.out.println("Entering Password");
driver.findElement(By.xpath("//input[@id='login_password']")).sendKeys("PW");
//Click LogIn Button
System.out.println("Submit Log In");
driver.findElement(By.className("login-button")).click();
//Verify user name login by echo name to console
System.out.println("Verify User Log In");
String text = driver.findElement(By.cssSelector("span.username")).getText();
System.out.println("Username is :" + text);
////////////////////////
//Click on Edit Profile
System.out.println("Clicking on Edit Profile Button");
driver.findElement(By.cssSelector("div.button.login")).click();
driver.findElement(By.xpath("//div[@id='mlg-header']/div/div[3]/div/div[7]/div/div[2]/a")).click();
//Change description in profile
System.out.println("Editing the Interests section of profile");
driver.findElement(By.name("interests")).clear();
driver.findElement(By.name("interests")).sendKeys("Edit Profile in Selenium Eclipse");
//Update Profile
System.out.println("Click on submit to change profile");
driver.findElement(By.cssSelector("input[type=\"submit\"]")).click();
//Verify that update has been applied to profile
System.out.println("Verifing that change has been made");
assertEquals("Profile has been updated.", driver.findElement(By.cssSelector("b > b")).getText());
//Console Output of Assert Statement Above
System.out.println("Profile has been updated!");
System.out.println("**Profile Complete!**");
}
@After
public void tearDown() throws Exception {
driver.quit();
String verificationErrorString = verificationErrors.toString();
if (!"".equals(verificationErrorString)) {
fail(verificationErrorString);
}
}
private boolean isAlertPresent() {
try {
driver.switchTo().alert();
return true;
} catch (NoAlertPresentException e) {
return false;
}
}
}
指正!我已经创建了一个maven项目,并且作为java文件,我有上面的以下代码。在我的POM XML我有硒依赖和junit依赖 – user2683183