Service Virtualization

Expand all | Collapse all

java.lang.SecurityException: Scripts cannot call Runtime.exec()

  • 1.  java.lang.SecurityException: Scripts cannot call Runtime.exec()

    Posted Feb 18, 2016 01:47 PM

    Hi,

     

    I have a selenium script written in Eclipse. When I run it in Eclipse, it launches a new browser. Now, I want it to run in DevTest so I added a new step called 'Execute script (JSR-223)', choose Groovy and pasted the code below. I need to use IE instead of the default Firefox driver that comes with DevTest.

     

    import java.io.File;

    import java.sql.Connection;

    import java.sql.DriverManager;

    import java.sql.ResultSet;

    import java.sql.SQLException;

    import java.sql.Statement;

     

     

    import org.apache.http.auth.UsernamePasswordCredentials;

    import org.openqa.selenium.ie.InternetExplorerDriver;

    import org.openqa.selenium.interactions.Actions;

    import org.openqa.selenium.security.Credentials;

    import org.openqa.selenium.security.UserAndPassword;

    import org.openqa.selenium.support.ui.ExpectedConditions;

    import org.openqa.selenium.support.ui.Select;

    import org.openqa.selenium.support.ui.WebDriverWait;

    import org.openqa.selenium.*;

    import java.util.concurrent.TimeUnit;

     

    InternetExplorerDriver wd;

    File file = new File("C:/driver/IEDriverServer.exe");

    System.setProperty("webdriver.ie.driver", file.getAbsolutePath());

    wd = new InternetExplorerDriver();

    wd.navigate().to("http://google.com");

     

    Now, when I try to run the script, it throws the following exception. I tried to search the discussion board and found a similar situation, Unable to execute Selenium Script with Chrome/IE Driver but it doesn't mention any solution. How do we call executables / other processes via this scripting step?

     

    Error in Script

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

    | Step:        Execute script (JSR-223)

    ----------------------------------------------------------------------------

    | Message:     java.lang.SecurityException: Scripts cannot call Runtime.exec()

    ----------------------------------------------------------------------------

    | Trapped Exception: java.lang.SecurityException: Scripts cannot call Runtime.exec()

    | Trapped Message:   javax.script.ScriptException: java.lang.SecurityException: Scripts cannot call Runtime.exec()



  • 2.  Re: java.lang.SecurityException: Scripts cannot call Runtime.exec()

    Posted Jun 17, 2016 02:52 PM

    Hi All,

    I am also facing same issue with external command step. Can anyone please help -

    Here is my post - Error while executing external command from custom script

    Thanks.



  • 3.  Re: java.lang.SecurityException: Scripts cannot call Runtime.exec()

    Posted Jun 17, 2016 02:56 PM

    I had to let the external command step RUN the actual command.



  • 4.  Re: java.lang.SecurityException: Scripts cannot call Runtime.exec()

    Posted Jun 17, 2016 03:15 PM

    Even I tried this option. The issue I am getting is like whenever I execute the external command step it till go on executing the command but control is not going forward to further steps for processing.

    Issue with Execute External Command step 



  • 5.  Re: java.lang.SecurityException: Scripts cannot call Runtime.exec()

    Posted Jun 17, 2016 03:49 PM

    how is the step configured, for next step or assertions?



  • 6.  Re: java.lang.SecurityException: Scripts cannot call Runtime.exec()

    Posted Jun 17, 2016 03:53 PM

    No sdwtweil2, the step will only start the server. There is no assertion for next step.



  • 7.  Re: java.lang.SecurityException: Scripts cannot call Runtime.exec()

    Posted Jun 17, 2016 04:10 PM

    ok, you said it didn't advance.

     

    what does the command do?

     

    on windows or linux you have to use the appropriate function to start a program in the background, like a server..

     

    start for Windows

    or use & at the end for linux



  • 8.  Re: java.lang.SecurityException: Scripts cannot call Runtime.exec()

    Posted Jun 17, 2016 04:22 PM

    The command will start activemq server and VSM flow advance to listener step. I am trying to execute external command on windows. Do you want me to use START /B on windows to run in background ?



  • 9.  Re: java.lang.SecurityException: Scripts cannot call Runtime.exec()

    Posted Jun 17, 2016 04:46 PM

    yes, then you should use Start to execute the MQ server in the background.



  • 10.  Re: java.lang.SecurityException: Scripts cannot call Runtime.exec()

    Posted Jun 17, 2016 04:48 PM

    I tried to execute command with START but then next Listener step is not able to listen any incoming request. All requests are failing but transaction count remain 0.



  • 11.  Re: java.lang.SecurityException: Scripts cannot call Runtime.exec()

    Posted Jun 17, 2016 04:50 PM

    why did the listen step fail? what does the inspection view say?



  • 12.  Re: java.lang.SecurityException: Scripts cannot call Runtime.exec()

    Posted Jun 17, 2016 04:52 PM

    ActiveMQ server will be up and running but I cant see anything in inspection view. I think execute command step blocks the incoming requests.



  • 13.  Re: java.lang.SecurityException: Scripts cannot call Runtime.exec()

    Posted Jun 17, 2016 05:02 PM

    the execute command should be (from your other post on this topic

     

    start path/activemq.bat start

     

    this says

    execute asyncronously and return immediately

    the command path\activemq.bat

    and pass a parmeter to that command of 'start'

     

    if you are using the execute external command then you should set it up like this

    don't wait , exec shell (same as cmd /c), spawn new process

     



  • 14.  Re: java.lang.SecurityException: Scripts cannot call Runtime.exec()

    Posted Jun 17, 2016 05:35 PM

    My command as like this

     

    cmd /c "D:\software\apache-activemq-5.13.1\bin\activemq.bat" start

     

    But in my case whenever this step executed, new command line window will open and do nothing.



  • 15.  Re: java.lang.SecurityException: Scripts cannot call Runtime.exec()

    Posted Jun 18, 2016 08:05 AM

    correct.

     

    the activemq.bat file does not return.. it is 'running' as you indicated, 'start'..

    the cmd /c is just the shell, in single command mode.. and it is waiting for the single command to complete.

     

    so, you need to change it to

     

    cmd /c Start "D:\software\apache-activemq-5.13.1\bin\activemq.bat" start

     

    this will instantiate the activemq.bat in a separate command shell, passing it the parameter 'start' like now.

    and then the Start command will return and  the cmd /c will end as the single command it executed (Start)

    has completed.

     

    and if you sent the execute external command properties right you won't need cmd /c  (same as 'exec shell')

    or Start (same as 'Spawn process' and NOT 'Wait for Completion')

    so the command would just be

     

    "D:\software\apache-activemq-5.13.1\bin\activemq.bat" start