Using same browser instance in different test cases

1,816 views
Skip to first unread message

matt...@gmail.com

unread,
Jun 9, 2009, 6:43:59 AM6/9/09
to robotframework-users
Hi,

I have a situation where I can only execute one keyword at a time. But
the keywords belongs to the same test case. For example:
1.Test case:
Open Browser | "URL" | "Browser
2. Test case:
Go To | "URL
3. Test case:
Close Browser

I have to know if the keyword has passed or not before getting next
keyword, so basically I have to write all the keywords in separate
html files. The problem is that after I've run "open browser" test
case and I have to run "Go To" test case, I can't link it to the same
browser instance.

I've tried with "switch browser" but it seems I can't find the right
IDs, because I always get "No browser with index or alias 'n' found.".
Is this even possible to do with Selenium library or is there a
keyword that helps with this problem?

-Matti

Martin Taylor

unread,
Jun 9, 2009, 7:43:25 AM6/9/09
to robotframework-users
Robot Framework will not go to the next keyword if a given keyword
fails. Even if you needed multiple test cases they could all go in
the same .html (or .tsv) file since RF supports multiple test cases in
a single file (test suite). I'd suggest you study the RF user guide a
little more carefully and work through the example given in the Quick
Start Guide: http://code.google.com/p/robotframework/wiki/QuickStartGuide.

Cheers,
Martin

matt...@gmail.com

unread,
Jun 9, 2009, 8:29:15 AM6/9/09
to robotframework-users
Yes I know this, but in this case I can't set all the test case in the
same .html file. I'm iplementing Robot to another testing tool and it
handles data in such way that it is impossible to use same file for
multiple test cases. Sorry if I wasn't clear about this.
I need to work around this by using the same browser as I did with
previous test case.

Teme

unread,
Jun 9, 2009, 9:45:42 AM6/9/09
to robotframework-users
Hey,

Selenium is using session id to identify the current session. So it's
not enough to just use the correct browser id, but you also have be
able to set correct session id to new Selenium class which is
initiated by the library. It is very likely that there isn't interface
for getting the Selenium's session ID so you have to start hacking it
yourself. To get "Get Selenium Session ID" you'd have to add function
for returning it to SeleniumLibrary/selenium.py and then also the
keyword to SeleniumLibrary/__init__.py . Store the session id to file
at the first session starting and then after that read it each time
you have to access to the same session from the different test-file.

Hopefully this helps to get your started. (Hmm... instead of changing
the content of SeleniumLibrary,you should create the subclasses. It
reduces your own maintenance cost, because if you want to upgrade
leater, you'd have to merge your changes.)

Teme

Pekka Klärck

unread,
Jun 9, 2009, 3:52:42 PM6/9/09
to matt...@gmail.com, robotframework-users
2009/6/9 matt...@gmail.com <matt...@gmail.com>:

>
> I have a situation where I can only execute one keyword at a time. But
> the keywords belongs to the same test case. For example:
> 1.Test case:
> Open Browser | "URL" | "Browser
> 2. Test case:
> Go To | "URL
> 3. Test case:
> Close Browser
>
> I have to know if the keyword has passed or not before getting next
> keyword, so basically I have to write all the keywords in separate
> html files. The problem is that after I've run "open browser" test
> case and I have to run "Go To" test case, I can't link it to the same
> browser instance.

This actually should work. Have you tried creating a test case in one
file? Even though that wasn't possible in your final test case, it
could help you to debug where the problem is. Personally I'd also
avoid separating a single test into multiple test cases if at all
possible.

> I've tried with "switch browser" but it seems I can't find the right
> IDs, because I always get "No browser with index or alias 'n' found.".
> Is this even possible to do with Selenium library or is there a
> keyword that helps with this problem?

Switch Browser is used to switch the active browser if you have
multiple browsers open. That's probably not needed in your situation.

Cheers,
.peke

Reply all
Reply to author
Forward
0 new messages