QA/Execution/Web Testing/Docs/Automation/StyleGuide: Difference between revisions

Jump to navigation Jump to search
Line 6: Line 6:
* Each file should have a completed copy of the [http://www.mozilla.org/MPL/2.0/ MPL2] license block, immediately followed by an empty line.
* Each file should have a completed copy of the [http://www.mozilla.org/MPL/2.0/ MPL2] license block, immediately followed by an empty line.
* Each file should pass [http://www.python.org/dev/peps/pep-0008/ PEP8] except for line length, see below.   
* Each file should pass [http://www.python.org/dev/peps/pep-0008/ PEP8] except for line length, see below.   
<pre class="brush:py;toolbar:false;">
<source lang="python">
    # Good
# Good
    def method(self, parameter)  
def method(self, parameter)  


    # Bad
# Bad
    def method(self,parameter)
def method(self,parameter)
</pre>
</source>
* Lines should try not to have more than 100 characters.
* Lines should try not to have more than 100 characters.
* Docstrings should conform to [http://www.python.org/dev/peps/pep-0257/ PEP0257] and should be on a single line wherever possible.
* Docstrings should conform to [http://www.python.org/dev/peps/pep-0257/ PEP0257] and should be on a single line wherever possible.
<pre class="brush:py;toolbar:false;">
<source lang="python">
    # Good
# Good
    def click_login():
def click_login():
    """Clicks the login link."""
"""Clicks the login link."""


    # Bad
# Bad
    def click_login():
def click_login():
    """
"""
    Clicks the login link.
Clicks the login link.
    """
"""
</pre>
</source>
Where not possible, the first line should be a summary.
Where not possible, the first line should be a summary.
<pre class="brush:py;toolbar:false;">
<source lang="python">
    # Good
# Good
    def login():
def login():
    """Logs in.
"""Logs in.


    Clicks the login link and then waits for the home page to load.
Clicks the login link and then waits for the home page to load.


    """
"""


    # Bad
# Bad
    def login():
def login():
    """Logs in.
"""Logs in.
    Clicks the login link and then waits for the home page to load."""
Clicks the login link and then waits for the home page to load."""
</pre>
</pre>
* Indenting should be a soft tab (4 spaces) as common with in Python. Do not mix tabs and spaces!
* Indenting should be a soft tab (4 spaces) as common with in Python. Do not mix tabs and spaces!
* There should be no whitespace at the end of the file (as per PEP8)
* There should be no whitespace at the end of the file (as per PEP8).
* Comments should be on the line above. Remember to update comments when changing code so that code matches the comments.
* Comments should be on the line above. Remember to update comments when changing code so that code matches the comments.
* Class names should be in Pascal style as this is Python idiomatic.
* Class names should be in Pascal style as this is Python idiomatic.
<pre class="brush:py;toolbar:false;">
<source lang="python">
    # Good
# Good
    class TestThisSite:
class TestThisSite:
      
      
    # Bad
# Bad
    class test_this_site:
class test_this_site:
</pre>
</source>


= Page Objects =
= Page Objects =
Confirmed users
2,197

edits

Navigation menu