Checkout our demo site to practice selenium https://magento.softwaretestingboard.com/

0 like 0 dislike
5.8k views
by The go-to Tester (218 points)
edited by
I am executing script using Selenium Webdriver to download a file. My code is-:

package AllScripts;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.firefox.*;
import org.testng.annotations.*;

public class FileDownload_AutoIT {
    WebDriver driver;
    @BeforeMethod
    public void init()
    {
        System.setProperty("webdriver.gecko.driver", "C://Selenium driver/geckodriver.exe");
        DesiredCapabilities capabilities = DesiredCapabilities.firefox();
        capabilities.setCapability("marionette", true);
        driver = new FirefoxDriver();
        driver.manage().window().maximize();
        driver.manage().timeouts().implicitlyWait(3,TimeUnit.MINUTES);
    }
    @AfterMethod
    public void stop()
    {
        driver.quit();
    }
    @Test
    public void testDownload() throws InterruptedException, IOException
    {
        
        driver.get("http://seleniumhq.org/download/");
        driver.findElement(By.linkText("3.3.1")).click();
        Thread.sleep(1000);
        
        new ProcessBuilder("E:\\FDownload.exe").start();
        Thread.sleep(8000);

        
    }

}

 

The error that I get is

SEVERE: Unable to kill process with PID 3100
[Utils] Attempting to create E:\Sandeep\EclipseWorkspace\ExampleProject\test-output\Default suite\Default test.html
[Utils]   Directory E:\Sandeep\EclipseWorkspace\ExampleProject\test-output\Default suite exists: true
[Utils] Attempting to create E:\Sandeep\EclipseWorkspace\ExampleProject\test-output\Default suite\Default test.xml
[Utils]   Directory E:\Sandeep\EclipseWorkspace\ExampleProject\test-output\Default suite exists: true
FAILED: testDownload
java.io.IOException: Cannot run program "E:\FDownload.exe": CreateProcess error=2, The system cannot find the file specified
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
    at AllScripts.FileDownload_AutoIT.testDownload(FileDownload_AutoIT.java:36)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:86)
    at org.testng.internal.Invoker.invokeMethod(Invoker.java:646)
    at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:823)
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1131)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:129)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:112)
    at org.testng.TestRunner.privateRun(TestRunner.java:778)
    at org.testng.TestRunner.run(TestRunner.java:632)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:366)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:361)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:319)
    at org.testng.SuiteRunner.run(SuiteRunner.java:268)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1225)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1150)
    at org.testng.TestNG.runSuites(TestNG.java:1075)
    at org.testng.TestNG.run(TestNG.java:1047)
    at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:126)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:137)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:58)
Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified
    at java.lang.ProcessImpl.create(Native Method)
    at java.lang.ProcessImpl.<init>(ProcessImpl.java:386)
    at java.lang.ProcessImpl.start(ProcessImpl.java:137)
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)
    ... 26 more

2 Answers

0 like 0 dislike
by The go-to Tester (181 points)
As specified in the exception stack trace, your file E:\FDownload.exe is not found at the locaiton. Looks like its an AutoIT file and you have placed it somewhere else.

Kindly check exact spelling, as Java is a case sensitive language.

Also, try using forward slash E:/FDownload.exe if you think your location is correct.
0 like 0 dislike
by The go-to Tester (115 points)
Why are you trying to run exe file? Is it a AutoIT script? If it is I recommend you to convert it to batch file and run the batch file. E:\\FDownload.exe". And also going by your error trace, it looks the error is because of not able to find the location. Please make sure to provide the exact address path and hopefull it should works.


This site is for software testing professionals, where you can ask all your questions and get answers from 1300+ masters of the profession. Click here to submit yours now!

1.4k questions

1.6k answers

866 comments

1.9k users

...