[Tutor] How to pass command line variables to this python code...

J Cook jcook713 at gmail.com
Tue Jul 14 19:11:48 CEST 2009


Hello,

I have some autogenerated code from Selenium which I cannot figure out 
how to pass some command line variables to. For example I could export 
the same in Perl and it would be for example:

<code>
use strict;
use warnings;
use Time::HiRes qw(sleep);
use Test::WWW::Selenium;
use Test::More "no_plan";
use Test::Exception;

my $sel = Test::WWW::Selenium->new( host => "localhost",
                                     port => 4444,
                                     browser => "*chrome",
                                     browser_url => 	 
"http://www.google.com/" );

$sel->open_ok("/");
$sel->type_ok("q", "red sox");
</code>

I could then go in and add something like:

my ($arg1) = shift || "default";

which would pick up the first command line parameter and then I could do 
something like:

$sel->(type_ok, $arg1);

All is good here, now Selenium will export the following for Python:

<code>
from selenium import selenium
import unittest, time, re

class NewTest(unittest.TestCase):
     def setUp(self):
         self.verificationErrors = []
         self.selenium = selenium("localhost", 4444, "*chrome", 
"http://www.google.com/")
         self.selenium.start()

     def test_new(self):
         sel = self.selenium
         sel.open("/")
         sel.type("q", "red sox")

     def tearDown(self):
         self.selenium.stop()
         self.assertEqual([], self.verificationErrors)

if __name__ == "__main__":
     unittest.main()
</code>

Now I am confused on how to pass a command line parameter here. Any 
suggestions? I would like to be able to run something like:

$ python selenium-google-test.py "yankees"

Suggestions?


TIA

Justin


More information about the Tutor mailing list