Forum Discussion

MartyBurns's avatar
MartyBurns
Occasional Contributor
11 years ago

[Resolved] Use selenium webdriver across steps

I am looking to see if anyone knows how to persist a webdriver session across steps. I am looking to modularize my tests. I would like to have, for example, a driver start script, a logon test script, a do some stuff set of steps, a logoff script, and a driver close script. Any ideas would be appreciated.

Thanks,
Marty

7 Replies

  • MartyBurns's avatar
    MartyBurns
    Occasional Contributor
    I am using SOAPUI for all my testing. The web services we are working on have a mix of "gui" interfaces, and, REST APIs.

    What I would like to do is organize the following test steps into a test suite:

    1) a driver start step - this would be a groovy step opening the web driver instance,
    2) a logon test step - this would be a groovy step that exercises the logon screen of a gui,
    3) a do some stuff set of steps, -- this might be a mix of steps that do groovy and REST API
    4) a logoff step, -- this would be a groovy step logging off the server
    5) and a driver close step. -- this would be a groovy step closing the web driver

    The challenge I have is how to create the driver in step 1 and allow the other groovy steps to use it.

    Currently I have this all in a single groovy script step. However, as you can imagine each of these steps could be a re-usable part that I could use with other similar tests. Now i have to duplicate all the code each time.

    Thanks for any help.

    Marty
  • nmrao's avatar
    nmrao
    Champion Level 3
    Currently I have this all in a single groovy script step. However, as you can imagine each of these steps could be a re-usable part that I could use with other similar tests.

    You mean, the single step would do all 5 steps that you had mentioned? Is there any hassle to divide it, by the way?
  • MartyBurns's avatar
    MartyBurns
    Occasional Contributor
    I believe the problem is that the selenium web driver instance lives for the life of a script/test step. So you could not implement the scenario I identified where the browser session is kept alive from step to step.

    Am I missing something?

    Marty
  • nmrao's avatar
    nmrao
    Champion Level 3
    I got what you mean to say. Hmm..it seems that need to do on trial basis progressively here
  • GiscardN's avatar
    GiscardN
    Frequent Contributor
    Hi,

    You should be able to save the driver instance in the context, in the same manner an HTTP session can be maintained across the execution of a TestCase. See this article that explains it: http://www.soapui.org/Functional-Testing/testcase-execution.html: Starting up the TestCase, point 1.

    You can try something like this:
    def yourDriverInstance = ...
    if( context["driverInstance"] == null )
    context["driverInstance"] = yourDriverInstance
    Then in later steps you can retrieve it as context["driverInstance"]

    For your step 2 (logon step), take a look at this article for a non-Groovy alternative: http://www.soapui.org/Working-with-Projects/form-based-authentication-in-soapui.html.

    Regards,

    Giscard
    SmartBear Support