Webdriver脚本,用于发送电子邮件通知并合并excel中的数据

时间:2017-01-19 14:46:44

标签: selenium webdriver reporting

我正在编写一个webdriver自动化程序,以查找JIRA中的错误的最后评论是否有我的团队名称或ID,如果是,我将不得不向他们发送个人电子邮件以查看该评论,并且还必须发送综合列表资源名称,错误ID以及在Excel文件中自动向我的经理发表评论

到目前为止,我有一个工作簿,其中包含我的所有团队成员ID和名称,并且该工作簿中还包含JIRA URL,用户名和密码 下面是脚本的进度,我在控制台输出中打印所有必需的脚本。在电子邮件发送部分和在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();
        }
    }
}
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

发送电子邮件需要与邮件服务器进行交互。有关如何将其整合到gmail的精彩描述,请点击此处。