Service Virtualization

Expand all | Collapse all

Selenium code exported to Jar File , Jar is used in Execute Script # Facing issues while accessing the method

  • 1.  Selenium code exported to Jar File , Jar is used in Execute Script # Facing issues while accessing the method

    Posted Mar 13, 2017 02:28 AM
      |   view attached

    Hi All,

     

    To reduce the redesign of Selenium test cases (we know, we can redesign by Selenium Integration Step using JSON Script), we tried an alternative way of having all our Selenium test cases to a Jar file. We thought of accessing methods which are present in JAR  in our Execute Script Step by creating an object for the main class in Selenium Code like this.

     

        public void initiateSeleniumCode()
        {

          // some code here

       }

     

    we placed all the support jar files for Selenium in hotdeploy folder. But we are facing below error.

     

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

     

    Can someone help in this regard please why we are getting this error.

    Any approach to resolve this issue.

     

     

    ************************************************************************************************************************************

     

    ============================================================================
    | Error in Script
    ============================================================================
    | Step:        Execute script (JSR-223)
    ----------------------------------------------------------------------------
    | Message:     bsh.TargetError: Sourced file: inline evaluation of: ``import com.sankar.test.test;    test t=new test();  
    t.initiateSeleniumCode();    return  . . . '' : Method Invocation t.initiateSeleniumCode:
    at Line: 4 : in file: inline evaluation of: ``import com.sankar.test.test;    test t=new test();  t.initiateSeleniumCode();  
      return  . . . '' : t .initiateSeleniumCode( )

     

    Target exception: java.lang.SecurityException: Scripts cannot call Runtime.exec()
     in inline evaluation of: ``import com.sankar.test.test;    test t=new test();  t.initiateSeleniumCode();    return  . . . '' at line number 4
    ----------------------------------------------------------------------------
    | Trapped Exception: bsh.TargetError: Sourced file: inline evaluation of: ``import com.sankar.test.test;    test t=new test();  t.initiateSeleniumCode();    return  . . . '' : Method Invocation t.initiateSeleniumCode: at Line: 4 : in file: inline evaluation of: ``import com.sankar.test.test;    test t=new test();  t.initiateSeleniumCode();    return  . . . '' : t .initiateSeleniumCode( )

     

    Target exception: java.lang.SecurityException: Scripts cannot call Runtime.exec()
     in inline evaluation of: ``import com.sankar.test.test;    test t=new test();  t.initiateSeleniumCode();    return  . . . '' at line number 4
    | Trapped Message:   javax.script.ScriptException: bsh.TargetError: Sourced file: inline evaluation of: ``import com.sankar.test.test;    test t=new test();  t.initiateSeleniumCode();    return  . . . '' : Method Invocation t.initiateSeleniumCode: at Line: 4 : in file: inline evaluation of: ``import com.sankar.test.test;    test t=new test();  t.initiateSeleniumCode();    return  . . . '' : t .initiateSeleniumCode( )

     

    Target exception: java.lang.SecurityException: Scripts cannot call Runtime.exec()
     in inline evaluation of: ``import com.sankar.test.test;    test t=new test();  t.initiateSeleniumCode();    return  . . . '' at line number 4
    ----------------------------------------------------------------------------

    ************************************************************************************************************************************

     

    Here is the code written,

     

    Attachment(s)

    zip
    NewSeleniumError.zip   1 KB 1 version


  • 2.  Re: Selenium code exported to Jar File , Jar is used in Execute Script # Facing issues while accessing the method

    Posted Mar 14, 2017 10:53 AM

    Hi,

        Are the jar's running properly when you try to run them from your local desktop command prompt.Check for the compatibility of jars that you are using for Selenium scripts.