How do I launch a batch file in a Selenium WebDriver project?
Hi Friend, When you want to create utilty to run batch file for your selenium tests, its always useful. I am giving you example of creating utility in Java Language to run batch file. Create batch file on your desktop and name it as abc.bat and write inside it echo "He is learning automation" Now create Java main class import java.io.IOException; import java.io.OutputStream; public class CMDUtilityToRunBatchFile { public static void main(String args[]){ CMDUtilityToRunBatchFile testScript = new CMDUtilityToRunBatchFile(); execDOSCmd(); } public static void execDOSCmd() { try { // Execute command String command ="cmd /c start C:\Users\DreamBook\Desktop\abc.bat"; Process child = Runtime.getRuntime().exec(command); // Get output stream to write from it OutputStream out = child.getOutputStream(); out.write("cd C:/ /r/n".getBytes()); out.flush(); out.write("dir /r/n".getBytes()); out.close(); } c...
Comments
Post a Comment