日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

selenium中应用问题解决

發布時間:2024/4/17 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 selenium中应用问题解决 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

selenium使用Runtime.getRuntime().exec()調用系統執行bat文件

Test.java文件內容: import java.util.Timer; import java.util.TimerTask; import java.util.Date;public class Test{public static void main(String[] args){System.out.println("timer canceled!");}}

Test.bat文件內容:

java Test>>output.txt

?

package cn.gloryroad;import java.io.BufferedReader; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader;public class StreamGobbler extends Thread {InputStream is;String type;public StreamGobbler(InputStream is, String type) {this.is = is;this.type = type;}public void run() {try {InputStreamReader isr = new InputStreamReader(is);BufferedReader br = new BufferedReader(isr);String line = null;while ((line = br.readLine()) != null) {if (type.equals("Error")) {System.out.println("Error :" + line);} else {System.out.println("Debug:" + line);}}} catch (IOException ioe) {ioe.printStackTrace();}}public static void main(String[] args) throws Exception{Runtime.getRuntime().exec("javac G:\\temp\\Test.java"); //不支持帶有中文的路徑Thread.sleep(3000); // Runtime.getRuntime().exec("notepad.exe"); //調用記事本//可以調用.bat(內容:java Test>>output.txt)文件執行成功且將打印日志重載到指定文件Process proc = Runtime.getRuntime().exec("cmd.exe /c start Test.bat",null,new File("G:/temp"));StreamGobbler errorGobbler = new StreamGobbler(proc.getErrorStream(), "Error");StreamGobbler outputGobbler = new StreamGobbler(proc.getInputStream(), "Output");errorGobbler.start();outputGobbler.start();proc.waitFor();} }

?

執行結果:

junit中調用exe文件:

JunitDebug.java package snippet;import java.io.File; import snippet.util.StreamGobbler;public class JunitDebug{public void execRuntime() throws Exception{ // Process proc = Runtime.getRuntime().exec("notepad.exe");Process proc =Runtime.getRuntime().exec("cmd /C update.exe", null, new File("E:/")) ;StreamGobbler errorGobbler = new StreamGobbler(proc.getErrorStream(), "Error",null);StreamGobbler inputGobbler = new StreamGobbler(proc.getInputStream(), "Input",null);StreamGobbler outputGobbler = new StreamGobbler(null, "Output", proc.getOutputStream());errorGobbler.start();inputGobbler.start();outputGobbler.start();proc.waitFor();} }

JunitDebugTest.java

package snippet;import static org.junit.Assert.*;import org.junit.After; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test;public class JunitDebugTest {private static JunitDebug add = new JunitDebug();@BeforeClasspublic static void setUpBeforeClass() throws Exception {}@AfterClasspublic static void tearDownAfterClass() throws Exception {}@Beforepublic void setUp() throws Exception {}@Afterpublic void tearDown() throws Exception {}@Testpublic void test() throws Exception {add.execRuntime();}}

調用記事本(notepad.exe)、update.exe成功

==========================================================================================================================================

testNG中調用exe文件:

JunitDebugTest.java

package snippet.snippet;import org.testng.annotations.Test;import snippet.JunitDebug;import org.testng.annotations.BeforeMethod; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeClass; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeTest; import org.testng.annotations.AfterTest;public class JunitDebugTest {private static JunitDebug add = new JunitDebug();@BeforeMethodpublic void beforeMethod() {}@AfterMethodpublic void afterMethod() {}@BeforeClasspublic void beforeClass() {}@AfterClasspublic void afterClass() {}@BeforeTestpublic void beforeTest() {}@AfterTestpublic void afterTest() {}@Testpublic void execRuntime() throws Exception {add.execRuntime();} }

調用記事本(notepad.exe)、update.exe成功

=======================================================================================================================================

同時或先后啟動兩個系統exe:

?

JunitDebug.java

?

?

package snippet;import java.io.File; import snippet.util.StreamGobbler;public class JunitDebug{public void execRuntime() throws Exception{Process proc = Runtime.getRuntime().exec("notepad.exe"); //success Thread.sleep(3000);Process proc1 = Runtime.getRuntime().exec("calc.exe"); //successStreamGobbler errorGobbler1 = new StreamGobbler(proc1.getErrorStream(), "Error",null);StreamGobbler inputGobbler1 = new StreamGobbler(proc1.getInputStream(), "Input",null);StreamGobbler outputGobbler1 = new StreamGobbler(null, "Output", proc1.getOutputStream());errorGobbler1.start();inputGobbler1.start();outputGobbler1.start();proc1.waitFor();} }

?

JunitDebugTest.java

package snippet.snippet;import org.testng.annotations.Test;import snippet.JunitDebug;import org.testng.annotations.BeforeMethod; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeClass; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeTest; import org.testng.annotations.AfterTest;public class JunitDebugTest {private static JunitDebug add = new JunitDebug();@BeforeMethodpublic void beforeMethod() {}@AfterMethodpublic void afterMethod() {}@BeforeClasspublic void beforeClass() {}@AfterClasspublic void afterClass() {}@BeforeTestpublic void beforeTest() {}@AfterTestpublic void afterTest() {}@Testpublic void execRuntime() throws Exception {add.execRuntime();} }

調用記事本(notepad.exe)、計算器(calc.exe)成功

?

轉載于:https://www.cnblogs.com/celine/p/11382901.html

總結

以上是生活随笔為你收集整理的selenium中应用问题解决的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。