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

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

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

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

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Monday in Jira Software

How large do you think Jira Software can grow?

Hi Atlassian Community! My name is Shana, and I’m on the Jira Software team. One of the many reasons this Community exists is to connect you to others on similar product journeys or with comparabl...

588 views 6 12
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you