Service Virtualization

Expand all | Collapse all

How to resolve this exception in Selenium Script in DevTest 9.5.1?

  • 1.  How to resolve this exception in Selenium Script in DevTest 9.5.1?

    Posted Apr 11, 2017 11:09 AM
      |   view attached

    Hi,

    I am trying to run a selenium script using DevTest 9.5.1. As mentioned in one of the previous discussions, i created a selenium test step first and then added the Execute Script step with the selenium code in it. This way of doing it used to work sometime before. But I dont know what changed now that I am getting the following exception - 

     

    Target exception: java.lang.ClassCastException: Cannot cast com.itko.lisa.glass.SeleniumTestNode$SeleniumState to com.sebuilder.interpreter.TestRun

     

    Has anyone faced similar issue. Any help on this please?

     

    I have attached a sample test of mine here. 

    Attachment(s)

    zip
    Sample_Test.tst.zip   1 KB 1 version


  • 2.  Re: How to resolve this exception in Selenium Script in DevTest 9.5.1?

    Broadcom Employee
    Posted Apr 12, 2017 08:27 AM
    Daniel Mazzei - thoughts?




  • 3.  Re: How to resolve this exception in Selenium Script in DevTest 9.5.1?

    Posted Apr 12, 2017 09:26 AM

    Hi, JackSteve,

    Can you share the entire Project directory? I am getting a different error:Test run failed: unable to create driver.

    Thanks,

    Dan



  • 4.  Re: How to resolve this exception in Selenium Script in DevTest 9.5.1?

    Broadcom Employee
    Posted Apr 14, 2017 10:59 AM

    I can get the same error, so let me do some research and see what I can find.

     

    Something about the JavaScript step is failing this:

     

    import org.openqa.selenium.interactions.Actions;
    import org.openqa.selenium.*;
    import org.openqa.selenium.OutputType.*;
    import org.openqa.selenium.remote.*;
    import com.sebuilder.interpreter.TestRun;

    TestRun tr = testExec.getStateObject("selenium.testrun");
    RemoteWebDriver rwd = tr.driver();

    rwd.navigate().to("www.google.com");



  • 5.  Re: How to resolve this exception in Selenium Script in DevTest 9.5.1?

    Broadcom Employee
    Posted Apr 19, 2017 10:13 AM

    The error is from this statement in your Javascript:

     

    TestRun tr = testExec.getStateObject("selenium.testrun");



  • 6.  Re: How to resolve this exception in Selenium Script in DevTest 9.5.1?
    Best Answer

    Broadcom Employee
    Posted Apr 19, 2017 01:58 PM

    Ahh, in v9.5 (and in v10.0 - I haven't tried v10.1 yet), that line should read:

    RemoteWebDriver rwd = testExec.getStateObject("selenium.testrun").testRun.getDriver();

     



  • 7.  Re: How to resolve this exception in Selenium Script in DevTest 9.5.1?

    Posted Apr 19, 2017 02:52 PM

    Wow... Thank you so much.. That statement worked.

    But why/how is it different from mentioning it in 2 lines like this -

      TestRun tr = testExec.getStateObject("selenium.testrun");
      RemoteWebDriver rwd = tr.driver();

     

    Is it to do with the TestRun Class?



  • 8.  Re: How to resolve this exception in Selenium Script in DevTest 9.5.1?

    Broadcom Employee
    Posted Apr 19, 2017 02:59 PM

    The object returned by testExec.getStateObject("selenium.testrun") is of type com.itko.lisa.glass.SeleniumTestNode$SeleniumState & not com.sebuilder.interpreter.TestRun

     

    Not verified but the line  

    TestRun tr = testExec.getStateObject("selenium.testrun");

    needs to be

     TestRun tr = testExec.getStateObject("selenium.testrun").testRun;

     

    I would add null check & check if testExec.getStateObject("selenium.testrun") is of appropriate type before invoking subsequent calls.



  • 9.  Re: How to resolve this exception in Selenium Script in DevTest 9.5.1?

    Posted Apr 19, 2017 03:27 PM

    Thanks Prem. Statements I provided before used to work in 8.4 and I am not sure if something changed after that. I actually got that statement from another discussion topic. Here is another one where the same statement is used. I believe this change will impact everyone who have been using the TestRun like this - 

     

    TestRun tr = testExec.getStateObject("selenium.testrun");
      RemoteWebDriver rwd = tr.driver();

     

    https://communities.ca.com/message/241853444?commentID=241853444#comment-241853444  



  • 10.  Re: How to resolve this exception in Selenium Script in DevTest 9.5.1?

    Broadcom Employee
    Posted Apr 19, 2017 04:49 PM

    DevTest v9.5+ uses a newer version of Selenium drivers (2.53 - the final version of Selenium before migrating to their Gecko driver. In DevTest v8.4, we included v2.46 of Selenium drivers, as those were current at the time), and we present a slightly different API entry point, which is why we do testRun.getDriver() instead of testRun() and driver().

     

    What are all the pieces of Selenium API functionality you want to use by implementing them in a script? I can add them to my list of requirements.



  • 11.  Re: How to resolve this exception in Selenium Script in DevTest 9.5.1?

    Posted Apr 20, 2017 02:13 PM

    Thank you Rick. Once I create the Remote WebDriver, I think I will be able to use all the methods associated to it (haven't tried yet). Apart from this I don't have a need for other APIs right now.



  • 12.  Re: How to resolve this exception in Selenium Script in DevTest 9.5.1?

    Posted Nov 06, 2017 03:49 AM

    Hi Rick,

     

    I had created a Test case with 2 test step first test step just has json to open up google URL and in next step I doing

    TestRun tr = testExec.getStateObject("selenium.testrun");
    RemoteWebDriver rwd = tr.driver();

    rwd.get("MY URL"); and so on code.

     

    My code is running perfect, only issue I have is I want to run this test case on server as headless. My second step is headless.. As I don't want every time users run this test case a browser window is opened...

    Please help and Thanks in advance!!

    Note: Iam using devtest 9.1