我是Selenium和Automation的新手。使用Selenium IDE和我对Java的一般知识,我能够在Eclipse上进行一系列在JUnit上运行的测试用例。现在,当我在月食中运行我的测试时,然后按[运行]。我想将这些测试用例导入Jenkins / Hudson。我希望通过两种方式进行CI。
安排时间(每周一次)进行测试并发送结果电子邮件。
将我的测试用例上传到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项目库创建硒自动化。在这种情况下,如果要使用Jenkins作为CI,请按以下步骤操作:
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句