Selenium
Web apps testing platform
Selenium IDE
Plugin for Firefox
http://release.seleniumhq.org/selenium-ide/2.5.0/selenium-ide-2.5.0.xpi
http://docs.seleniumhq.org/docs/01_introducing_selenium.jsp
http://docs.seleniumhq.org/docs/02_selenium_ide.jsp
Selenium IDE (Integrated Development Environment) is a prototyping tool for building test scripts. It is a Firefox plugin and provides an easy-to-use interface for developing automated tests. Selenium IDE has a recording feature, which records user actions as they are performed and then exports them as a reusable script in one of many programming languages that can be later executed.
Sample test suite for Yii blog demo
ts.html
1 <?xml version="1.0" encoding="UTF-8"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4 <head>
5 <meta content="text/html; charset=UTF-8" http-equiv="content-type" />
6 <title>Test Suite</title>
7 </head>
8 <body>
9 <table id="suiteTable" cellpadding="1" cellspacing="1" border="1" class="selenium"><tbody>
10 <tr><td><b>Test Suite</b></td></tr>
11 <tr><td><a href="loginLogout.html">Login and Logout</a></td></tr>
12 <tr><td><a href="addPost.html">Add post</a></td></tr>
13 <tr><td><a href="deletePost.html">deletePost</a></td></tr>
14 </tbody></table>
15 </body>
16 </html>
loginLogout.html
1 <?xml version="1.0" encoding="UTF-8"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4 <head profile="http://selenium-ide.openqa.org/profiles/test-case">
5 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
6 <link rel="selenium.base" href="http://localhostyii/" />
7 <title>Login and Logout</title>
8 </head>
9 <body>
10 <table cellpadding="1" cellspacing="1" border="1">
11 <thead>
12 <tr><td rowspan="1" colspan="3">Login and Logout</td></tr>
13 </thead><tbody>
14 <tr> <td>storeEval</td> <td>prompt("User");</td> <td>userx</td> </tr>
15 <tr> <td>storeEval</td> <td>prompt("Password");</td> <td>passwordx</td></tr>
16 <tr> <td>open</td> <td>http://localhostyii/demos/blog/</td> <td></td></tr>
17 <tr> <td>clickAndWait</td> <td>link=Login</td> <td></td></tr>
18 <tr> <td>type</td> <td>id=LoginForm_username</td> <td>${userx}</td></tr>
19 <tr> <td>type</td> <td>id=LoginForm_password</td> <td>${passwordx}</td></tr>
20 <tr> <td>clickAndWait</td> <td>//input[@value='Login']</td> <td></td> </tr>
21 <tr> <td>clickAndWait</td> <td>link=Logout (demo)</td> <td></td></tr>
22 </tbody></table>
23 </body>
24 </html>
addPost.html
1 <?xml version="1.0" encoding="UTF-8"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4 <head profile="http://selenium-ide.openqa.org/profiles/test-case">
5 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
6 <link rel="selenium.base" href="http://localhostyii/" />
7 <title>Add post</title>
8 </head>
9 <body>
10 <table cellpadding="1" cellspacing="1" border="1">
11 <thead>
12 <tr><td rowspan="1" colspan="3">Add post</td></tr>
13 </thead><tbody>
14 <tr> <td>open</td> <td>http://localhostyii/demos/blog/</td> <td></td></tr>
15 <tr> <td>clickAndWait</td> <td>link=Login</td> <td></td></tr>
16 <tr> <td>type</td> <td>id=LoginForm_username</td> <td>demo</td></tr>
17 <tr> <td>type</td> <td>id=LoginForm_password</td> <td>demo</td></tr>
18 <tr> <td>clickAndWait</td> <td>name=yt0</td> <td></td></tr>
19 <tr> <td>clickAndWait</td> <td>link=Create New Post</td> <td></td></tr>
20 <tr> <td>type</td> <td>id=Post_title</td> <td>Selenium Title</td></tr>
21 <tr> <td>store</td> <td>javascript{ new Date().toString() }</td> <td>datex</td></tr>
22 <tr> <td>type</td> <td>id=Post_content</td> <td>${datex}</td></tr>
23 <tr> <td>clickAndWait</td> <td>name=yt0</td> <td></td></tr>
24 <tr> <td>waitForText</td> <td>link=Selenium Title AABBCC</td> <td>Selenium Title AABBCC</td></tr>
25 <tr> <td>click</td> <td>link=Logout (demo)</td> <td></td></tr>
26 </tbody></table>
27 </body>
28 </html>
deletePost.html
1 <?xml version="1.0" encoding="UTF-8"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4 <head profile="http://selenium-ide.openqa.org/profiles/test-case">
5 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
6 <link rel="selenium.base" href="http://localhostyii/" />
7 <title>deletePost</title>
8 </head>
9 <body>
10 <table cellpadding="1" cellspacing="1" border="1">
11 <thead>
12 <tr><td rowspan="1" colspan="3">deletePost</td></tr>
13 </thead><tbody>
14 <tr> <td>open</td> <td>http://localhostyii/demos/blog/</td> <td></td></tr>
15 <tr> <td>clickAndWait</td> <td>link=Login</td> <td></td></tr>
16 <tr> <td>type</td> <td>id=LoginForm_username</td> <td>demo</td></tr>
17 <tr> <td>type</td> <td>id=LoginForm_password</td> <td>demo</td></tr>
18 <tr> <td>clickAndWait</td> <td>name=yt0</td> <td></td></tr>
19 <tr> <td>clickAndWait</td> <td>link=Manage Posts</td> <td></td></tr>
20 <tr> <td>clickAndWait</td> <td>css=img[alt="Delete"]</td> <td></td></tr>
21 <tr> <td>assertConfirmation</td> <td>Are you sure you want to delete this item?</td> <td></td></tr>
22 <tr> <td>clickAndWait</td> <td>link=Logout</td> <td></td></tr>
23 </tbody></table>
24 </body>
25 </html>
Selenium Remote Control/RC
http://docs.seleniumhq.org/docs/05_selenium_rc.jsp
https://www.selenium.dev/documentation/en/remote_webdriver/remote_webdriver_server/
wget http://selenium-release.storage.googleapis.com/2.42/selenium-server-standalone-2.42.2.jar
- java -jar selenium-server-standalone-2.42.2.jar
- pip install selenium
- easy_install-2.7 selenium
Sample python code, testyii1.py:
1 from selenium import selenium
2 import unittest, time, re
3
4 class testyii1(unittest.TestCase):
5 def setUp(self):
6 self.verificationErrors = []
7 self.selenium = selenium("localhost", 4444, "*chrome", "http://localhostyii/")
8 self.selenium.start()
9
10 def test_testyii1(self):
11 timeoutx='30000'
12 sel = self.selenium
13 sel.window_maximize();
14 sel.open("http://localhostyii/demos/blog/")
15 sel.click("link=Login")
16 sel.wait_for_page_to_load(timeoutx)
17 sel.type("id=LoginForm_username", "demo")
18 sel.type("id=LoginForm_password", "demo")
19 sel.click("name=yt0")
20 sel.wait_for_page_to_load(timeoutx)
21 sel.click("link=Manage Posts")
22 sel.wait_for_page_to_load(timeoutx)
23 sel.click("link=Welcome!")
24 sel.click("link=Logout")
25 sel.wait_for_page_to_load(timeoutx)
26
27 def tearDown(self):
28 self.selenium.stop()
29 self.assertEqual([], self.verificationErrors)
30
31 if __name__ == "__main__":
32 unittest.main()
Run with python2.7 testyii1.py
Test values obtained with jQuery in Selenium IDE
<tr><td>storeEval</td><td>selenium.browserbot.getUserWindow().jQuery('#selectx_id option:contains("Option Value")').css('display');</td><td>optionValueVisible</td></tr> <tr><td>echo</td> <td>${optionValueVisible}</td><td></td></tr> <tr><td>storeEval</td> <td>"none"</td> <td>noneValue</td> </tr> <tr><td>assertEval</td> <td>storedVars['optionValueVisible']==storedVars['noneValue']</td><td>true</td></tr>
WebDriver python screenshot - Firefox - Geckodriver
- pip install selenium
- cd ~
wget https://github.com/mozilla/geckodriver/releases/download/v0.28.0/geckodriver-v0.28.0-linux64.tar.gz
- tar xvzf geckodriver-v0.28.0-linux64.tar.gz
- cp geckodriver scripts/ # /home/vitor/scripts in PATH
- cd 2021-02-04T18:55:16 [vitor@debian:0 /tmp]
- python test_gecko_selenium.py