Updated documentation to mention an issue with IDE export.
[mediagoblin-automation:mediagoblin-selenium.git] / docs / ContributingTests.txt
1 ------------------------
2 How to Contribute Tests
3 ------------------------
4 Tests can be recorded using Selenium IDE within Firefox or by generating the 
5 HTML either programmatically or by hand. Theses tests are then to be added
6 to the TestSuite.html under tests/src. 
7
8 The current workflow then requires that you export your test case as a 
9 "Python 2 webdriver" script and save it in the tests/ folder. In the future
10 this conversion will be done by the automation framework itself so only the
11 HTML source file will need to be committed.
12
13 ------------------------
14 Things to Note
15 ------------------------
16 Don't set your base url to have a forward slash at the end. Selenium adds the forward
17 slash for you by default.
18
19 The Selenium IDE doesn't currently export the selection of dropdown items, instead
20 it throws the following error:
21     # ERROR: Caught exception [ReferenceError: selectLocator is not defined]
22
23 Here is an example of one wayto add a dropdown selection to a script:
24         select = Select(driver.find_element_by_id("license"))
25         select.select_by_visible_text("CC0 1.0")
26
27 ------------------------
28 Writing Upload Tests
29 ------------------------
30 If a test makes use of local files, such as those found under the resources 
31 directory, you need to edit the Selenium HTML file and replace the your specific
32 base directory path with the parameter WORKING_DIRECTORY.
33
34 Example:
35 /home/lotusecho/gmg/mediagoblin-selenium/resources/gavroche.png
36
37 Becomes
38
39 WORKING_DIRECTORY/resources/gavroche.png
40
41 When runtests.sh is run it will process that paramter and replace it with your 
42 current working directory.
43
44 ------------------------
45 When Recording / Code Reuse
46 ------------------------
47 At /tests/util we have provided a small set of often-used functions that can be
48 added to your test cases to reduce the amount of repeated work.
49
50 When you record your tests you don't need to record the login/logout steps as 
51 a part of test. Instead, add them to the exported python file. 
52
53 ------------------------
54 util.login EXAMPLE
55 ------------------------
56 Add this ->         from util import login, logout
57 Right before ->     from selenium import webdriver
58
59 ...
60
61 Next, find your test function, like the following:
62
63     def test_upload_j_p_e_g(self):
64         driver = self.driver
65         #Insert your objects here for login
66         data = {"username" : "testuser", "password" : "TestPassworD!"}
67         tLogin = login.LogIn()
68         tLogin.log_in(self, data)
69         #End of new code
70
71
72 Each reusable object takes data from your current test to proceed.