Hi Team,
This is another tutorial from jira side for the removal of jira users from specific or all groups using a simple selenium script. Selenium makes it easier for the user to perform the task which will take real good time when done manually. In the below example, I have not taken the users list from any external source, but the same is explained in my previous tutorials. Here the user list is a simple string where users are separated by comma and the same are iterated using the for loop.
The TestClass.java file is as follows:
[java]
package com.code2java.jira;
import com.thoughtworks.selenium.*;
import org.junit.After;
import org.junit.Test;
import org.junit.Before;
import java.util.regex.Pattern;
public class TestClass extends SeleneseTestCase {
@Before
public void setUp() throws Exception {
selenium = new DefaultSelenium(“localhost”, 4444, “*iexplore”, “http://localhost/”);
selenium.start();
}
@Test
public void test() throws Exception {
selenium.open(“/jira/login.jspa”);
selenium.click(“link=Log In”);
selenium.waitForPageToLoad(“30000”);
selenium.type(“id=login-form-username”, “username”);
selenium.type(“id=login-form-password”, “password”);
selenium.click(“id=login-form-submit”);
selenium.waitForPageToLoad(“30000”);
selenium.click(“id=admin_link”);
selenium.waitForPageToLoad(“30000”);
selenium.click(“id=user_browser”);
selenium.waitForPageToLoad(“30000”);
selenium.type(“id=login-form-authenticatePassword”, “password”);
selenium.click(“id=authenticateButton”);
selenium.waitForPageToLoad(“30000”);
String listOfUsers = “user1,user2,user3,user4”;
String[] list = listOfUsers.split(“,”);
String user = null;
try
{
for(int i=0;i<list.length;i++)
{
user = list[i];
selenium.click(“id=admin_link”);
selenium.waitForPageToLoad(“30000”);
selenium.click(“id=user_browser”);
selenium.waitForPageToLoad(“30000”);
selenium.type(“name=userNameFilter”, list[i]);
selenium.click(“//input[@value=’Filter’]”);
selenium.waitForPageToLoad(“30000”);
selenium.click(“css=span.username”);
selenium.waitForPageToLoad(“30000”);
selenium.click(“id=editgroups_link”);
selenium.waitForPageToLoad(“30000”);
try
{
String[] groupList = selenium.getSelectOptions(“groupsToLeave”);
for(int j=0;j<groupList.length; j++)
{
System.out.print(groupList[j] +”, “);
selenium.addSelection(“name=groupsToLeave”, groupList[j]);
}
selenium.click(“name=leave”);
selenium.waitForPageToLoad(“30000”);
}
catch(Exception e)
{
System.out.println(“User “+ list[i]+” not in any Group”);
}
}
}catch(Exception err)
{
System.out.println(“The user “+user+” not found”);
}
}
@After
public void tearDown() throws Exception {
selenium.stop();
}
}
[/java]
In the above example we have used “selenium.getSelectOptions(“groupsToLeave”)” (see line 54), this returns the list of groups in which the user is added, where groupsToLeave is the String type locationSelector. This location selector is nothing but the list box on the jira Edit user group page which display the groups (showed in below pic). Once we have the groups we can use them and remove the user for all those groups.
This is a really time saving option for such repetitive actions. Hope this will help you.
Regards,
Nikhil Naoghare.
Hello there, simply was aware of your weblog through Google, and located that it’s really informative. I am gonna be careful for Brussels. I’ll appreciate in case you continue this in future. Lots of folks shall be benefited out of your writing. Cheers!
Hi there, I enjoy reading all of your post. I wanted to write a little comment to support you.