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

This widget could not be displayed.

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

This widget could not be displayed.

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
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted yesterday in New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

46 views 1 0
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