QA/Mozmill Test Automation/Test Modules Refactor: Difference between revisions

Jump to navigation Jump to search
 
(42 intermediate revisions by 3 users not shown)
Line 14: Line 14:
  |- valign="top"
  |- valign="top"
  | '''Status:'''
  | '''Status:'''
  | In process of determining style guidelines
  | '''on hold'''
  |- valign="top"
  |- valign="top"
  | '''Repository Location:'''
  | '''Repository Location:'''
Line 23: Line 23:
  |- valign="top"
  |- valign="top"
  | '''Documentation:'''
  | '''Documentation:'''
  | [https://docs.google.com/document/d/13OhM4T2nxYqrvCAtVicjB-PCrDeLiSOnc6N-pXw939A/edit?hl=en&authkey=CPmR7d4J Draft Proposal]
  |
* [https://docs.google.com/document/d/13OhM4T2nxYqrvCAtVicjB-PCrDeLiSOnc6N-pXw939A/edit?hl=en&authkey=CPmR7d4J Draft Proposal]
* [http://neil.rashbrook.org/JS.htm Neil Rashbrook's style guide]
* [http://javascript.crockford.com/code.html Douglas Crockford's style guide]
  |}
  |}


Line 30: Line 33:
The purpose of this project is to ensure all tests are implemented using an agreed style guideline.  The workflow of this project will mostly be parallel with the Shared Modules Refactor project.  This project will be rolled out in multiple phases.
The purpose of this project is to ensure all tests are implemented using an agreed style guideline.  The workflow of this project will mostly be parallel with the Shared Modules Refactor project.  This project will be rolled out in multiple phases.


== Phase I ==
== Style Guidelines ==
Goal: Refactor "lowest-hanging-fruit" changes<br>
The [https://developer.mozilla.org/en/Mozmill_Tests/Mozmill_Style_Guide Mozmill Style Guide] v1.0 has been created. The following refactoring work is an effort to implement those guidelines throughout the mozmill-tests repository. This refactoring will be implemented in multiple phases, outlined below.
Dependencies: Agreed upon style guidelines


== Refactoring  ==
== Refactoring  ==
; Timeouts & Delays
=== Phase I ===
* gDelay: replace with a discrete int value
{| class="fullwidth-table"
* gTimeout: replace with TIMEOUT
| Goal
 
| Implement lowest hanging fruit, make all tests reflect the styleguide
; Constants
|-
* const SOME_CONST = value;
| {{bug|}}
 
| Replace all constants with CONSTANTS
; setupModule & teardownModule
* gDelay, 100 => DELAY
* Remove ''module'' parameter
* gTimeout, 5000 => TIMEOUT
 
* sleep() parameter => SLEEP_TIMEOUT
; Mozilla Components
* unique timeouts => CONSTANT (ie. SEARCH_TIMEOUT)
* Ensure proper alignment of getService() on Cc[]
|-
 
| {{bug|}}
; Local Test Pages
| Replace discrete, unchanging values with CONSTANTS
* Replace any LOCAL_PAGE or LOCAL_TEST_PAGE with a LOCAL_TEST_PAGES array
|-
* Each array element should have at least a URL and ID member
| {{bug|}}
 
| Migrate tests away from testGeneral
; Arrays
|-
* Ensure proper alignment from style guidelines
| {{bug|}}
 
| All test pages in LOCAL_TEST_PAGES array
; Assertions
|-
* waitForEval: replace with waitFor()
| {{bug|}}
 
| Replace waitForEval() with waitFor() where possible
== Style Guidelines ==
|-
; Timeouts & Delays
| {{bug|}}
* Proposed Guidelines:
| Replace DELAY/TIMEOUT with waitFor() where possible
** Delay: Use discrete value
|-
** Timeout: Use global TIMEOUT
| {{bug|}}
* Henrik: Timeouts should be encapsulated within a global shared module
| License block formatting
* Geo: Use default params where appropriate, wrapper functions where not
* "the Mozilla Foundation"
 
* contributor list alignment
; Constants
|-
* Proposed Guidelines:
| {{bug|}}
** Exist between ''requires'' and ''setupModule()''
| All error messages use format:
** const SOME_CONSTANT = value;
* message + " - got " + condition1 + ", expected " + condition2
* Geo: All ''unchanging'' variables as constants
* ''message'' uses positive wording
 
|-
; Function Signatures
| {{bug|}}
* Proposed Guidelines:
| Whitespace formatting
** var nameOfFunction = function() {
* No trailing whitespace
* Geo: Agree on open-brace on same line but common in JS to have an next-line exception for named functions; could go either way.
* 1 newline at end of file
* 2-space indentation where appropriate
* Wrap on 80-characters where appropriate
|-
| {{bug|}}
| Replace sleep() with waitFor() where possible
|-
| {{bug|}}
| Extract any ''new elementslib...'' from function parameter list
|-
| {{bug|}}
| Replace all array iteration with Array.forEach()
|-
| {{bug|}}
| Replace anonymous functions with named functions
|-
| {{bug|}}
| Adopt consistent commenting style
|-
| {{bug|}}
| All iterators as ''i'', not ''ii''
|-
| {{bug|}}
| Adopt consistent conditional cuddling
|-
| {{bug|}}
| All included modules should use variable names starting with capital
|-
| {{bug|}}
| All conditionals use !== or ===
|}


; ''module'' as a param for setupModule & teardownModule
''Note: The above comes from the agreed to refactoring [http://etherpad.mozilla.com:9000/mozmill-test-refactor guidelines]''
* Proposed Guidelines:
** ???
* Geo: Strange to have a function not declare a parameter that’s actually being supplied, but maybe that’s more normal in JS.
* Henrik: Removing module was probably a mistake; used for injecting global functions into the module scope.


; Mozilla Components
=== Phase II ===
* Proposed Guidelines:
Goal: Bring tests in-line with Shared Module Refactor
** var obj = Cc[“@mozilla.org/component;1”].getService(Ci.interface);
** Declare in setupModule()
** For word-wrapping, split after the ., getService() aligned with Cc[]


; LOCAL_TEST_PAGES
== Outstanding Items ==
* Proposed Guidelines:
Discussion [http://mozqa.ietherpad.com/refactor-discussion here]
** Encapsulate all local test pages within a const LOCAL_TEST_PAGES array
** Each element (test page) consists of a URL and an ID
* Henrik: We should use Name, Link, and XPath as well
* Aaron: Establish a module/API to handle loading of any needed test files


; Array Formatting
; Generally Agreed
* Proposed Guidelines:
* We should always use the triple operator to not experience strange behavior
** Each array element on its own line
** ===/!== instead of ==/!=
** Each element member on its own line
* Variables for imported modules have to start with a capital letter
<pre>
** i.e. var Tabs = require(".../tabs")
const LOCAL_TEST_PAGES = [
* Class names have to start with a capital letter
{ id: “Some_ID”,
* setupModule(module) and teardownModule(module) have to specify the module parameter
  url: LOCAL_TEST_FOLDER + ‘someFolder/someFile.html’ },
* If variable name contains an acronym, capitalize the acronym
{ id: “Some_ID”,
* Error messages should use the following format:
  url: LOCAL_TEST_FOLDER + ‘someFolder/someFile.html’ },
** Boolean: "<element> is <state>."
{ id: “Some_ID”,
** Value: "<element> is <state>: got 'value', expected 'value'"
  url: LOCAL_TEST_FOLDER + ‘someFolder/someFile.html’ }
** Example: "Password notification is visible"
];
** Example: "mozilla.org is loaded: got '<loaded_domain>', expected 'mozilla.org'"
</pre>
* sleep() should be avoided and only used when...
** element is not immediately available
** state is not immediately available
** waitFor() fails to capture event


; Assertions
; Needs Discussion
* Use waitFor() for all timeout assertions
* TestFilesAPI for loading of test files
<pre>
** We should have a module specific to loading of test files
controller.waitFor(function() {
** We should also check how we can make sure those locations are easily replacable with other servers (apache, ...)
  return someObject.value == expectedValue;
* Parameters should be named using aParam format
}, TIMEOUT, 100, “My failure message”);
** shows that a variable inside a long function is a parameter and hasn't been declared locally
</pre>
* Constant scope - should they be global and local?
* Use assertDOMProperty() for all DOM property assertions
<pre>controller.assertDOMProperty(someObject.someProperty, expectedValue);</pre>
* Use assertJSProperty() for all JS property assertions
<pre>controller.assertJSProperty(someObject.someProperty, expectedValue);</pre>
Confirmed users
14,525

edits

Navigation menu