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

vince spicer vinces1979 at gmail.com
Tue Jul 14 19:36:06 CEST 2009


First off, selenium is a great tool and the python driver is very powerful

there are numerous ways to access cli variables,

the quickest

import sys
print sys.srgv

sys.argv will it output a array of all command line args

./selenium-google-test.py yankees
will out put:

['selenium-google-test.py', 'yankees']

so

args = sys.argv

args[0] == 'yankees'
True

for a more functional way, check out
http://docs.python.org/library/getopt.html



On Tue, Jul 14, 2009 at 11:11 AM, J Cook <jcook713 at gmail.com> wrote:

> 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
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090714/07bf7ea0/attachment.htm>


More information about the Tutor mailing list