[英]Jira Test Automation Using Selenium WebAPI
我們記錄了一個測試案例,以使用Selenium IDE登錄到jira。 並且它運行正常。但是,當它導出到Java Web驅動程序(jUnit4)時,它沒有工作,並給元素未找到錯誤。
代碼是:
package newjiralogin;
import java.util.concurrent.TimeUnit;
import org.junit.*;
import static org.junit.Assert.*;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
public class NewJiraLogin {
private WebDriver driver;
private String baseUrl;
private final StringBuffer verificationErrors = new StringBuffer();
@Before
public void setUp() throws Exception {
driver = new FirefoxDriver();
baseUrl = "http://jiratest/";
driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
}
@Test
public void testUntitled2() throws Exception {
driver.get("http://jiratest");
driver.findElement(By.id("login-form-username")).clear();
driver.findElement(By.id("login-form-username")).sendKeys("saumlk");
driver.findElement(By.id("login-form-password")).clear();
driver.findElement(By.id("login-form-password")).sendKeys("saumlk");
driver.findElement(By.id("login")).click();
}
@After
public void tearDown() throws Exception {
driver.quit();
String verificationErrorString = verificationErrors.toString();
if (!"".equals(verificationErrorString)) {
fail(verificationErrorString);
}
}
主要的Method類:
package newjiralogin;
import org.junit.runner.JUnitCore;
public class NewJiralogintest {
public static void main(String[] args) throws Exception {
JUnitCore.main("newjiralogin.NewJiraLogin");
}
}
登錄表單位於iframe中,即,在訪問元素之前,您必須切換驅動程序的上下文,例如
driver.switchTo().frame("gadget-0");
(假設“ gadget-0”是包含登錄框的框架的ID)。
我不是IDE-> WebDriver轉換的專家,但是上下文切換似乎丟失了。 如果要為JIRA實現UI自動化,請查看JIRA PageObjects,它確實簡化了許多常見任務。 Atlassian文檔頁面或以下位置提供了如何使用它們的示例: https : //blog.codecentric.de/en/2014/07/part-3-agile-testing-jira-plugins-system-tests/ 。 這篇博客文章是我們寫的簡短系列文章的一部分,因為類似問題,我們想分享我們學到的知識。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.