Multi step test case

Asked by Ayo

I am having problem writing a multi step test case i.e. perform multiple actions within a test script
 1 go to home page (go_to url)
 2 assert title
 3 go to another page (go_to url)

My aim is to be able to run all the steps within the test case even if it fails. This used to be possible with verify command Selenium RC. Below are 2 sample scripts trying to perform this

richt.py
#(the test script runs through all the steps)
from sst.actions import *

go_to('http://testutils.org/sst/index.html#')
assert_title_contains ('SST - Web Test Framework ')
go_to('http://testutils.org/sst/changelog.html#')

falsch.py
#(the test script stops as it fails at the step 2)
from sst.actions import *

go_to('http://testutils.org/sst/index.html#')
assert_title_contains ('huygiug ')
go_to('http://testutils.org/sst/changelog.html#')

The problem i am having is that if the script fails at step 2 it does not continue with step 3. I have tried using the if condition but was not able to get it to work.As there is no verify command how can i use the assert command and still be able to run the whole steps.

Thanks in advance.

Question information

Language:
English Edit question
Status:
Answered
For:
selenium-simple-test Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
pratik shah (pratik-shah) said :
#1

You can write a sst method called "get_title", then just check for the condition:

define a method for get_title:

def get_title(title):
    """Get title of browser page"""
    real_title = browser.title
    return real_title

condition to check for:

my_title = get_title('http://localhost:8000')
if not 'string im looking for' in my_title:
    print 'Sorry, title string not found..'

Revision history for this message
Ayo (k-akolay1) said :
#2

Thanks will try out the solution.

Revision history for this message
Ayo (k-akolay1) said :
#3

Hi Pratik,
Just getting of the holiday mode and getting back to the testing mode.
Took a crash python course over the holidays.

A quick question, is the 'browser' and 'title' in the "real_title = browser.title" for the browser used for the test and title the expected page title?
EXAMPLE===>
real_title = firefox.www.mysite.com

Thanks in advance.
Ayo

Revision history for this message
Leo Arias (elopio) said :
#4

Hey Ayo,

In good theory, you have two tests there and it might be better to split them. It's easier to spot the application errors when you have only one assertion at the end of the test. But, if you have a good reason for doing this, then you could use try.

import sst.actions

sst.actions.go_to('http://testutils.org/sst/index.html#')
try:
    sst.actions.assert_title_contains ('huygiug ')
except AssertionError:
    print 'Do something here'
sst.actions.go_to('http://testutils.org/sst/changelog.html#')

Revision history for this message
pratik shah (pratik-shah) said :
#5

Ayo,

Yes, you're passing the URL you want the title to, so, it might be confusing with that being the parameter name of the method.

def get_title(url):
    """Get title of browser page"""
    real_title = browser.title
    return real_title

You're passing the URL, getting the browser title from the method, then you're using basic python to check for the string you want.

I absolutely agree with Leo, I proposed a solution based on the question, but he's correct.

Can you help with this problem?

Provide an answer of your own, or ask Ayo for more information if necessary.

To post a message you must log in.