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 Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

3,304 views 14 20
Join discussion

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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot