平时代码小记

if (!ele_div.getAttribute("class").contains("has-labels")) {
						severity = "3 - 中";
					}
List elelist = driver.findElements(By.xpath("//div[contains(@class,'labels')]/div[3]/a"));

String title=driver.findElement(By.id("issue-title")).getText();
rank = ele.getAttribute("href").split("=")[1];
if (rank.equals("Critical+Issue")) {
    severity = "2 - 高";
	break;
	} 
else {
		severity = "3 - 中";
	}

if(driver.getCurrentUrl().contains("issues")) {...}


WebElement author = driver.findElement(By.xpath("//*[@id=\"legendLife\"]/table/tbody/tr[1]/td"));
String authorStr = author.getText();
String authorMan = authorStr.substring(0,authorStr.indexOf("于"));
String authorTime = authorStr.substring(authorStr.indexOf("于")+2);
String sql = "replace into TFS_bugs(ID,工作项类型,标题,状态,创建日期,严重级别,产品名称,创建者,功能模块,集成版本,重现步骤)"
							+ " values (?,?,?,?,?,?,?,?,?,?,?)";
					DBHelper dbhelper = new DBHelper(sql);
					try {
						dbhelper.pst.setString(1, bugID);
						dbhelper.pst.setString(2, "Bug");
						dbhelper.pst.setString(3, title);
						dbhelper.pst.setString(4, status);
						dbhelper.pst.setString(5, thetime);
						dbhelper.pst.setString(6, severity);
						dbhelper.pst.setString(7, "Board_install");
						dbhelper.pst.setString(8, author);
						dbhelper.pst.setString(9, "无");
						dbhelper.pst.setString(10, "无");
						dbhelper.pst.setString(11, "无");
						dbhelper.pst.execute();
					} catch (SQLException e) {
						e.printStackTrace();
						continue;
					}
					dbhelper.close();
package com.inspur.jctest.app;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class DBHelper {
	public static final String url = "jdbc:mysql://10.10.4.92:3306/jctest?characterEncoding=utf8&useSSL=true";
	public static final String name = "com.mysql.jdbc.Driver";
	public static final String user = "jctest";
	public static final String password = "jctest";

	public Connection conn = null;
	public PreparedStatement pst = null;

	public DBHelper(String sql) {
		try {
			Class.forName(name);//指定连接类型
			conn = DriverManager.getConnection(url, user, password);//获取连接
			pst = conn.prepareStatement(sql);//准备执行语句
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public void close() {
		try {
			this.conn.close();
			this.pst.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
}
System.setProperty("webdriver.chrome.driver",
				"C:\\Program Files(x86)\\Google\\Chrome\\Application\\chromedriver.exe");// 定义谷歌driver的地址
driver = new ChromeDriver(); // 初始化driver
driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);// 隐式等待,driver全局生效
driver.manage().window().maximize();
driver.quit();
//隐藏重现步骤,以免分辨率不够			

((JavascriptExecutor)driver).executeScript("document.getElementsByClassName('main')[0].style.display='none';");
WebElement tbody = driver.findElement(By.xpath("//*[@id=\"legendBasicInfo\"]/table/tbody"));
				List trs = tbody.findElements(By.tagName("tr"));
				int tableSize = trs.size();
				System.out.println(tableSize);
				HashMap legendBasicInfo = new HashMap();
				for(int trNum = 1;trNum
try{
    ...
   }catch (Exception e){
				Alert alert = driver.switchTo().alert();
				if(alert.getText().contains("无权访问")) {
					alert.accept();
					continue;
				}else {
					alert.accept();
					break;
				}
			}

 

你可能感兴趣的:(JavaWeb)