简体   繁体   中英

Jira Test Automation Using Selenium WebAPI

We recorded a test case to log into jira using Selenium IDE. And it was running correctly.BUT when it exported to java web driver(jUnit4), it did not worked and gave element not found error.

The code is :

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);
    }
  }

The main Method class :

package newjiralogin;

import org.junit.runner.JUnitCore;


public class NewJiralogintest {

    public static void main(String[] args) throws Exception {                    
       JUnitCore.main("newjiralogin.NewJiraLogin");  
    }
}

The login form resides inside an iframe, ie before accessing the elements you have to switch the context of the driver, .eg

driver.switchTo().frame("gadget-0");

(assuming "gadget-0" is the id of the frame which contains the login box).

I'm not an expert for the IDE->WebDriver conversion, but it seems that the context switch got lost. If you want to implement UI automation for JIRA, have a look at the JIRA PageObjects which really ease many of the common tasks. A sample how they can be employed is available at the Atlassian documentation pages or here: https://blog.codecentric.de/en/2014/07/part-3-agile-testing-jira-plugins-system-tests/ . This blog entry is part of a short series we wrote b/c we had similar issues and wanted to share what we learned.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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