平時コードメモ

4212 ワード

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;
				}
			}