|
public static void destoryProess() {
try {
String[] cmd ={"tasklist"};
Process proc = Runtime.getRuntime().exec(cmd);
BufferedReader in = new BufferedReader(new InputStreamReader(proc
.getInputStream()));
String string_Temp = in.readLine();
while (string_Temp != null) {
System.out.println(string_Temp);
if (string_Temp.indexOf("firefox.exe") != -1)
Runtime.getRuntime().exec("Taskkill /IM firefox.exe");
string_Temp = in.readLine();
}
} catch (Exception e) {
}
public class testlogin extends FeedTest{
private WebDriver driver;
private String LinkTest;
private String baseUrl = "http://wuhan.eduyun.cn";
public void startUrl() throws Exception {
driver = new FirefoxDriver();
driver.get(baseUrl);
driver.manage().window().maximize();
}
@Test(dataProvider = "feeder")
@Source("test.xls")
public void testLogin(String userName, String passWord,boolean flag,
String excepted) {
try{
startUrl();
driver.findElement(By.id("info_username")).clear();
driver.findElement(By.id("info_username")).sendKeys(userName);
driver.findElement(By.id("info_password")).clear();
driver.findElement(By.id("info_password")).sendKeys(passWord);
driver.findElement(By.id("info_submit")).click();
if(flag){
LinkTest = driver.findElement(By.xpath("//li[contains(concat(' ', @class, ' '), ' jykj_blue ')]//strong"))
.getText().trim();
assertEquals(excepted, LinkTest);
LinkTest = null;
Thread.sleep(2000);
}else{
LinkTest = driver.findElement(By.xpath("//p[contains(concat(' ', @class, ' '), ' warnmsg ')] "))
.getText().trim();
assertEquals(excepted, LinkTest);
LinkTest = null;
Thread.sleep(2000);
}
driver.quit();
}catch(Exception e){
e.printStackTrace();
}finally{
gongYongmethods.destoryProess();
}
}
}
当执行上千条或者更多的用例时,会出现很多不通过的用例 ,这时不通过的用例就会占用我机器的内存,在selenium中,如果出现错误,代码不会往下执行,就算你最后调用了quit或者 close方法也不会执行,如果不通过数量多,会导致我本机和JVM的内存耗完。我写一个公用的方法来杀死我的进程 ,在我执行的用例最后在finally下调用杀死firefox的进程,
这样就不会出现占大量内存的情况 |
|