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

Line 202: Line 202:


== Style Guidelines ==
== Style Guidelines ==
=== Naming ===
1. Local variables should be named using camel-case
1. Local variables should be named using camel-case
<pre> var exampleVariableName = value;</pre>
<pre> var exampleVariableName = value;</pre>
2. Constants should be named using all-caps
2. Constants should be named using all-caps
<pre>const EXAMPLE_CONSTANT = value;</pre>
<pre>const EXAMPLE_CONSTANT = value;</pre>


=== Commenting ===
3. Blocks of code should be commented in-line:
1. Blocks of code should be commented in-line:
<pre>
<pre>
   // What the code does
   // What the code does
Line 215: Line 214:
</pre>
</pre>


2. Functions should use JSDoc block-style comments:
4. Functions should use JSDoc block-style comments:
<pre>
<pre>
   /**
   /**
Line 226: Line 225:
</pre>
</pre>


=== Block-style ===
5. Arrays block-style
1. Arrays
<pre>
<pre>
   var obj = [
   var obj = [
Line 237: Line 235:
</pre>
</pre>


2. Named Functions
6. Named Functions
<pre>
<pre>
   function someFunction() {
   function someFunction() {
Line 244: Line 242:
</pre>
</pre>


3. Anonymous Functions
7. Anonymous Functions
<pre>
<pre>
   var someFunction() = function() {
   var someFunction() = function() {
Line 251: Line 249:
</pre>
</pre>


4. Function Usage
8. Function Usage
<pre>
<pre>
   var someVariable = someFunction(
   var someVariable = someFunction(
Line 260: Line 258:
</pre>
</pre>


5. Function Parameter Concatenation
9. Function Parameter Concatenation
<pre>
<pre>
   var someVariabe = someFunction(param1,
   var someVariabe = someFunction(param1,
Line 269: Line 267:
</pre>
</pre>


6. waitFor()
10. waitFor() block-style
<pre>
<pre>
   controller.waitFor(function() {
   controller.waitFor(function() {
Line 276: Line 274:
</pre>
</pre>


7. XPath: split on '/'
11. XPath: split on '/'
<pre>
<pre>
  var path = "/something" +
  var path = "/something" +
Line 283: Line 281:
</pre>
</pre>


=== Indentation ===
12. Lines of code should be indented 2-spaces to the right of their parent
1. Lines of code should be indented 2-spaces to the right of their parent
<pre>
<pre>
var cancelButton = new elementslib.Lookup(controller.window.document,
var cancelButton = new elementslib.Lookup(controller.window.document,
Line 291: Line 288:
</pre>
</pre>


2. Component declarations should be indented in line with the parent
13. Component declarations should be indented in line with the parent
<pre>
<pre>
var svc = Cc["string/for/service/component"].
var svc = Cc["string/for/service/component"].
Line 297: Line 294:
</pre>
</pre>


=== Line Length ===
14. Lines of code should not exceed 80 characters
1. Lines of code should not exceed 80 characters


=== Idioms ===
15. Use waitFor() as much as possible.  Only use sleep() when a waitFor() fails.
1. Use waitFor() as much as possible.  Only use sleep() when a waitFor() fails.


2. Always use a discrete int value for any DELAYs
16. Always use a discrete int value for any DELAYs


3. Always use a global constant for any TIMEOUTs
17. Always use a global constant for any TIMEOUTs
<pre>
<pre>
const TIMEOUT = 5000;
const TIMEOUT = 5000;
Line 314: Line 309:
</pre>
</pre>


4. Use assertDOMProperty(object, property) when evaluating DOM Object Properties
18. Use assertDOMProperty(object, property) when evaluating DOM Object Properties


5. Use assertJSProperty(object, property) when evaluating JS Object Properties
19. Use assertJSProperty(object, property) when evaluating JS Object Properties


6. Use array.forEach() for iterating array elements
20. Use array.forEach() for iterating array elements
<pre>
<pre>
array.forEach(function(elem, [index, [array]]) {
array.forEach(function(elem, [index, [array]]) {
Line 325: Line 320:
</pre>
</pre>


7. Don't put tests in testGeneral
21. Don't put tests in testGeneral


8. Only one test per file
22. Only one test per file


9. Element before action
23. Element before action
<pre>
<pre>
var obj = new elementGetter(params);
var obj = new elementGetter(params);
Line 335: Line 330:
</pre>
</pre>


10. Local test pages encapsulated in Array
24. Local test pages encapsulated in Array
<pre>
<pre>
const LOCAL_TEST_PAGES = [
const LOCAL_TEST_PAGES = [
Line 347: Line 342:
</pre>
</pre>


11. Constants between requires and setupModule()
25. Constants between requires and setupModule()
<pre>
<pre>
// Include required modules
// Include required modules
Line 360: Line 355:
</pre>
</pre>


12. Do not pass a ''module'' parameter in setupModule() and teardownModule()
26. Do not pass a ''module'' parameter in setupModule() and teardownModule()


== Refactoring  ==
== Refactoring  ==
Confirmed users
14,525

edits