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();
} catch (IOException e) {
}
}
}


Now run this Java file as “Java application” or call execDOSCmd() method from elsewhere. Even You can run your own batch script with this method.
**************************************************************************************

QACult Best Software Testing Courses in Chandigarh tricity.- We love to enhance your knowledge.

QACult is the premier institute catering to the requirements of experienced and fresh pass-out that gives leaders like you a new way to experience Quality engineering—while you work and giving you the flexibility to both advance your career.
Our faculty have 12+ years of industrial experience and have developed many automation testing frameworks in java using TestNG or BDD (cucumber) methodology. We expertise in developing automation testing frameworks in java, python, javascript, php, ruby(WATIR-webdriver & Capybara) and Appium.
please subscribe our channel for more such updates:  
And visit our website: www.qacult.com for various blogs and Upcoming Events.

Comments

Popular posts from this blog

Robot Framework With Python: An Open Source Framework For RPA

Robot Framework in python with RIDE

How to do copy Paste in browser using selenium using Actions class