How to create a 'log in to JIRA' test case using Selenium Java Webdriver/WebAPI?

Hasara November 16, 2014

Here is the issue. We recorded a test case to log in to JIRA using Selenium IDE and it replayed successfully. But when we converted the code in to JAVA/JUnit, it didn't execute. It gave element not found run time error.

The code:

 

package testlogin;

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 Test1 {
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(30, TimeUnit.SECONDS);
}

@Test
public void testUntitled2() throws Exception {
driver.get(baseUrl + "");
for (int second = 0;; second++) {
if (second >= 6) fail("timeout");
try { if (driver.findElement(By.id("usernamelabel")).isDisplayed()) break; } catch (Exception e) {}
Thread.sleep(10);
}

driver.findElement(By.id("login-form-username")).click();
driver.findElement(By.id("login-form-username")).clear();
driver.findElement(By.id("login-form-username")).sendKeys("hasblk");
driver.findElement(By.id("login-form-password")).click();
driver.findElement(By.id("login-form-password")).clear();
driver.findElement(By.id("login-form-password")).sendKeys("hasblk");
driver.findElement(By.id("login")).click();
}

@After
public void tearDown() throws Exception {
driver.quit();
String verificationErrorString = verificationErrors.toString();
if (!"".equals(verificationErrorString)) {
fail(verificationErrorString);
}
}

 

Main method class: 

package testlogin;

import org.junit.runner.JUnitCore;


public class TestLogin {

/**
* @param args the command line arguments
* @throws java.lang.Exception
*/
public static void main(String[] args) throws Exception {
JUnitCore.main("testlogin.Test1");

}

}

2 answers

0 votes
James Kosiba October 27, 2016

Late to the party, but if you still have a problem with this, try the following:

 

Replace: driver.findElement(By.id("login")).click();

With: driver.findElement(By.id("login-form-password")).submit();

0 votes
Carsten Hilber
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 8, 2016

I got the same error, did you get this case to work?

Suggest an answer

Log in or Sign up to answer