QA/Execution/Web Testing/Selenium Python: Difference between revisions

No edit summary
 
(6 intermediate revisions by the same user not shown)
Line 34: Line 34:
*The Selenium IDE can generate Python code for individual SIDE commands by exporting a "script" to Python that contains only one or a few commands. The exporter does not require a fully operational script. An single SIDE command may be translated to one or more Python functions. For example, the verifyXYZ IDE commands are generally translated to a get_xyz( ) passed to an assertion function.
*The Selenium IDE can generate Python code for individual SIDE commands by exporting a "script" to Python that contains only one or a few commands. The exporter does not require a fully operational script. An single SIDE command may be translated to one or more Python functions. For example, the verifyXYZ IDE commands are generally translated to a get_xyz( ) passed to an assertion function.


<br>  
==== Shared Libraries  ====
 
[[Code libraries for AMO pages]] are available to help centralize code and simplify python scripts. &nbsp;They contain functions that execute features and locators for page elements.<br>
 
<br>


=== Setting Up Selenium RC  ===
=== Setting Up Selenium RC  ===
Line 55: Line 59:
<br>  
<br>  


=== Running the Selenium script in Python on a client ===
=== Running the Selenium script in Python  ===


==== In Windows  ====
==== In Windows  ====
Line 73: Line 77:
*To start a script in the debugger enter<br>
*To start a script in the debugger enter<br>
<blockquote>python -m pdb ''myscript''<br> where ''myscript'' is the script file.&nbsp; More information about the debugger [http://docs.python.org/library/pdb.html here]. </blockquote>  
<blockquote>python -m pdb ''myscript''<br> where ''myscript'' is the script file.&nbsp; More information about the debugger [http://docs.python.org/library/pdb.html here]. </blockquote>  
<br>
=== Running the Selenium script in Python in Selenium Grid  ===
Running a Python script in Selenium Grid is controlled by the Python statement that creates the selenium instance. For a Python script generated by the IDE exporter begins with...
<blockquote><pre>from selenium import selenium
import unittest, time, re
class my_test_script(unittest.TestCase):
    def setUp(self):
        self.verificationErrors = []
        self.selenium = selenium("localhost", 4444, "*chrome", "http://base-URL-for-the-script/")
        self.selenium.start()
</pre></blockquote>
it would be modified for Selenium Grid as follows...
<blockquote><pre>from selenium import selenium
import unittest, time, re
from GridConnection import GridConnection
class my_test_script(unittest.TestCase):
    def setUp(self):
        self.verificationErrors = []
        connection = GridConnection()
        self.selenium = selenium(connection.server, connection.port, connection.macFirefox, connection.amoStaging)
        self.selenium.start()
</pre></blockquote>
Comments
* The browser parameter in the selenium instantiation (3rd value) might need to be limited to a subset of browsers or should be applied to all browsers. The best way to manage it is being determined. Stay tuned.
* The GridConnection class is not included in Python. A script intended for Selenium Grid can be run on a client by copying&nbsp;??? found at&nbsp;??? to the client into the&nbsp;??? directory. Note that the file on the server will likely experience changes for awhile which may require a refreshed copy on a client.
<br>
<br>


1,072

edits