繁体   English   中英

使用Selenium WebAPI进行Jira测试自动化

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM