A Login and Logout Scenario
Our first scenario is going to be a very simple one. We're just going to log into the application and then log out. We're going to use default values and aren't going to parameterize anything:
login-logout.py
[sourcecode language="python"]
from torqueo.test.framework.Scenario import Scenario
from torqueo.test.tasks.login.LoginTask import LoginTask
from torqueo.test.tasks.login.LogoutTask import LogoutTask
#
# Make a new scenario
#
myScenario = Scenario("My Scenario", {"url0":"https://local.sitetotest.com:8443"});
# Create a new instance of the Login Task
loginTask = LoginTask()
# Create a new instance of the Logout Task
logoutTask = LogoutTask()
#Add the tasks to our scenario
myScenario.addTask(loginTask)
myScenario.addTask(logoutTask)
class TestRunner:
def __call__(self):
myScenario.run()
[/sourcecode]
Pretty simple, right? First we create an instance of a Scenario. We give it a description and also a dictionary containing the URL we're going to be using. Then, we create an instance of a login task, a logout task, and add it to our scenario. Finally, we run our scenario in the __call__ method. Now what if we want to parameterize the logins? That's not difficult either:
login-logout-parameterized.py:
[sourcecode language="python"]
from torqueo.test.framework.Scenario import Scenario
from torqueo.test.tasks.login.LoginTask import LoginTask
from torqueo.test.tasks.login.LogoutTask import LogoutTask
#
# Make a new scenario
#
myScenario = Scenario("My Scenario", {"url0":"https://local.sitetotest.com:8443"});
# Create a new instance of the Login Task
loginTask = LoginTask()
# Define our login credentials
loginCredentials = [{"username":"vivin", "password":"abAB12!@"},
{"username":"jimbo", "password":"abAB12!@"},
{"username":"hippy", "password":"abAB12!@"},
{"username":"flippy", "password":"abAB12!@"},
{"username":"batman", "password":"abAB12!@"},
{"username":"beverly", "password":"abAB12!@"},
{"username":"worf", "password":"abAB12!@"},
{"username":"deanna", "password":"abAB12!@"},
{"username":"jean-luc", "password":"abAB12!@"},
{"username":"laren", "password":"abAB12!@"},
{"username":"will", "password":"abAB12!@"},
{"username":"tasha", "password":"abAB12!@"},
{"username":"geordi", "password":"abAB12!@"},
{"username":"data", "password":"abAB12!@"},
{"username":"wesley", "password":"abAB12!@"}]
# Set loginCredentials as a new property of loginTask since we're going to be
# using it in our parameterizing method
setattr(loginTask, "loginCredentials", loginCredentials)
# Define our parameterizing method
def parameterizeLogin(self=loginTask):
loginCredential = self.loginCredentials[grinder.threadNumber];
username = loginCredential["username"];
password = loginCredential["password"];
self.parameters["appLogin2"]["201"]["username"] = username;
self.parameters["appLogin2"]["201"]["password"] = password;
# Set parameterizeLogin the parameterizing method for "appLogin2"
loginTask.setParameterizingMethodFor("appLogin2", parameterizeLogin)
# Create a new instance of the Logout Task
logoutTask = LogoutTask()
#Add the tasks to our scenario
myScenario.addTask(loginTask)
myScenario.addTask(logoutTask)
class TestRunner:
def __call__(self):
myScenario.run()
[/sourcecode]
I configured, Grinderstone, PyDev and Jython on Eclipse Mars (version 4.5) with java 1.7, will can I be able to start recording scripts from Eclipse directly ? to do that should I include the startTCPProxy.sh from Eclipse or is there any other way ? Please adivise, which approach will be more productive , appreciate your response.
how to parameter values in quotes in jython, this is my method :
BaseSTSSchedulerTask.__init__(self, Test(testId, “Get Service Group by ID”), hostPort, ‘/SchServices/api/servicegroup/9999’, HEADERS)
I want to replace the value 9999 with a variable which is returned from a method., like id= Data.getID(). I tried doing this ‘/SchServices/api/servicegroup/’+id, it does not help . Any idea how to handle this ?