I am writing a webdriver automation to find if last comment of a bug in JIRA has my teams name or id and if so I will have to send individual emails to them to look into that comment and also have to send consolidated list of resource name, bug id and comment to my manager automatically in an Excel file
So far I had a workbook where I have all my team members id and name and also have JIRA URL, username and password in that workbook Below is the progress of the script where I print all required in console output. Need help in email sending part and consolidating results in Excel
package myproject;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import java.io.FileInputStream;
import java.util.*;
//import java.io.IOException;
import jxl.Sheet;
import jxl.Workbook;
import java.lang.*;
public class jiracomments {
public static void main(String[] args) throws Exception
{
String url, name, password;
String[] database = new String[30];
String[] id = new String[30];
String FilePath = "mypath";
FileInputStream fs = new FileInputStream(FilePath);
Workbook wb = Workbook.getWorkbook(fs);
// TO get the access to the sheet
Sheet sh = wb.getSheet("Sheet1");
url = sh.getCell(2,0).getContents();
System.out.println("JQL applied is : "+url);
name = sh.getCell(2,1).getContents();
System.out.println("Logged in with username: "+ name);
password = sh.getCell(2,2).getContents();
try{
for (int row = 0; row < 30; row++) {
database[row]=sh.getCell(0, row).getContents();
}
}
catch(Exception i){}
try{
for (int row = 0; row < 30; row++) {
id[row]=sh.getCell(1, row).getContents();
}
}
catch(Exception i){}
int v,i, x, xp;
boolean b;
String[] bug = new String[30];
String[] jiraname = new String[30];
WebDriver driver;
// System.setProperty("webdriver.gecko.driver", "C://Users/rajamas/Desktop/Selenium Jars/geckodriver-v0.10.0-win64/");
driver =new FirefoxDriver();
driver.get(url);
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.manage().window().maximize();
driver.findElement(By.xpath("/html/body/div/section/div/div/section/form/div[1]/fieldset/div[1]/input")).sendKeys(name);
driver.findElement(By.xpath("/html/body/div/section/div/div/section/form/div[1]/fieldset/div[2]/input")).sendKeys(password);
driver.findElement(By.xpath("/html/body/div/section/div/div/section/form/div[2]/div/input")).click();
//Number of results in filter
String counter= driver.findElement(By.xpath(".//*[@id='content']/div[1]/div[4]/div/div/div/div/div/div/div[1]/div[1]/span/span[3]")).getText();
int rows_count=Integer.parseInt(counter);
Thread.sleep(30000);
//to sort comments section
driver.findElement(By.xpath(".//*[@id='issuetable']/tbody/tr[1]/td[1]/a[2]")).click();
Thread.sleep(10000);
driver.findElement(By.xpath(".//*[@id='activitymodule']/div[2]/div[1]/div/a")).click();
Thread.sleep(10000);
driver.findElement(By.xpath(".//*[@id='return-to-search']")).click();
System.out.println("Comments having DA's id is : "+rows_count);
System.out.println("");
System.out.println("Below list has DA's id in last comment: ");
System.out.println("");
//to loop through all Jira's
for (int row=1;row<=rows_count;row++){
System.out.println(row);
// to navigate to next page if more than 100 results
if (row == 101) {
row=row-100;
rows_count=rows_count-100;
driver.findElement(By.xpath(".//*[@id='content']/div[1]/div[4]/div/div/div/div/div/div/div[4]/div[2]/div/a[2]")).click();
System.out.println("Moving to next page");
Thread.sleep(10000);
}
String row1= Integer.toString(row);
//to get bug id and click and navigate to bug details page
String bugId = driver.findElement(By.xpath(".//*[@id='issuetable']/tbody/tr["+row1+"]/td[1]/a[2]")).getText();
driver.findElement(By.xpath(".//*[@id='issuetable']/tbody/tr["+row1+"]/td[1]/a[2]")).click();
Thread.sleep(30000);
// to get the last comments value
String newsting= driver.findElement(By.xpath(".//*[@id='activitymodule']/div[2]/div[2]/div[2]/div[1]/div[1]/div[2]")).getText();
//code to be added to either send an email if DA name is available or raise nc
for (int count=0;count<28;count++)
{
if(newsting.toLowerCase().indexOf(id[count].toLowerCase())!=-1){
System.out.println("YOU HAVE AN ALERT: "+id[count]+" PLEASE LOOK INTO BUG: "+bugId);
System.out.println("The comment in your name is : "+newsting);
System.out.println("");
}
}
// to go back to search results
driver.findElement(By.xpath(".//*[@id='return-to-search']")).click();
}
}
}