= 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
{{{#!highlight html
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <meta content="text/html; charset=UTF-8" http-equiv="content-type" />
  <title>Test Suite</title>
</head>
<body>
<table id="suiteTable" cellpadding="1" cellspacing="1" border="1" class="selenium"><tbody>
<tr><td><b>Test Suite</b></td></tr>
<tr><td><a href="loginLogout.html">Login and Logout</a></td></tr>
<tr><td><a href="addPost.html">Add post</a></td></tr>
<tr><td><a href="deletePost.html">deletePost</a></td></tr>
</tbody></table>
</body>
</html>
}}}

loginLogout.html
{{{#!highlight html
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head profile="http://selenium-ide.openqa.org/profiles/test-case">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="selenium.base" href="http://localhostyii/" />
<title>Login and Logout</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">Login and Logout</td></tr>
</thead><tbody>
<tr> 	<td>storeEval</td> 	<td>prompt(&quot;User&quot;);</td> 	<td>userx</td> </tr>
<tr>	<td>storeEval</td>	<td>prompt(&quot;Password&quot;);</td>	<td>passwordx</td></tr>
<tr>	<td>open</td>	<td>http://localhostyii/demos/blog/</td>	<td></td></tr>
<tr>	<td>clickAndWait</td>	<td>link=Login</td>	<td></td></tr>
<tr>	<td>type</td>	<td>id=LoginForm_username</td>	<td>${userx}</td></tr>
<tr>	<td>type</td>	<td>id=LoginForm_password</td>	<td>${passwordx}</td></tr>
<tr>	<td>clickAndWait</td> 	<td>//input[@value='Login']</td> 	<td></td> </tr>
<tr>	<td>clickAndWait</td> 	<td>link=Logout (demo)</td> 	<td></td></tr>
</tbody></table>
</body>
</html>
}}}


addPost.html
{{{#!highlight html
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head profile="http://selenium-ide.openqa.org/profiles/test-case">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="selenium.base" href="http://localhostyii/" />
<title>Add post</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">Add post</td></tr>
</thead><tbody>
<tr>	<td>open</td>	<td>http://localhostyii/demos/blog/</td>	<td></td></tr>
<tr>	<td>clickAndWait</td>	<td>link=Login</td>	<td></td></tr>
<tr>	<td>type</td>	<td>id=LoginForm_username</td>	<td>demo</td></tr>
<tr>	<td>type</td>	<td>id=LoginForm_password</td>	<td>demo</td></tr>
<tr>	<td>clickAndWait</td>	<td>name=yt0</td>	<td></td></tr>
<tr>	<td>clickAndWait</td>	<td>link=Create New Post</td>	<td></td></tr>
<tr>	<td>type</td>	<td>id=Post_title</td>	<td>Selenium Title</td></tr>
<tr>	<td>store</td>	<td>javascript{ new Date().toString() }</td>	<td>datex</td></tr>
<tr>	<td>type</td>	<td>id=Post_content</td>	<td>${datex}</td></tr>
<tr>	<td>clickAndWait</td>	<td>name=yt0</td>	<td></td></tr>
<tr>	<td>waitForText</td>	<td>link=Selenium Title AABBCC</td>	<td>Selenium Title AABBCC</td></tr>
<tr>	<td>click</td>	<td>link=Logout (demo)</td>	<td></td></tr>
</tbody></table>
</body>
</html>
}}}

deletePost.html
{{{#!highlight html
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head profile="http://selenium-ide.openqa.org/profiles/test-case">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="selenium.base" href="http://localhostyii/" />
<title>deletePost</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">deletePost</td></tr>
</thead><tbody>
<tr>	<td>open</td>	<td>http://localhostyii/demos/blog/</td>	<td></td></tr>
<tr>	<td>clickAndWait</td>	<td>link=Login</td>	<td></td></tr>
<tr>	<td>type</td>	<td>id=LoginForm_username</td>	<td>demo</td></tr>
<tr>	<td>type</td>	<td>id=LoginForm_password</td>	<td>demo</td></tr>
<tr>	<td>clickAndWait</td>	<td>name=yt0</td>	<td></td></tr>
<tr>	<td>clickAndWait</td>	<td>link=Manage Posts</td>	<td></td></tr>
<tr>	<td>clickAndWait</td>	<td>css=img[alt=&quot;Delete&quot;]</td>	<td></td></tr>
<tr>	<td>assertConfirmation</td>	<td>Are you sure you want to delete this item?</td>	<td></td></tr>
<tr>	<td>clickAndWait</td>	<td>link=Logout</td>	<td></td></tr>
</tbody></table>
</body>
</html>

}}}

== Selenium Remote Control/RC ==
http://docs.seleniumhq.org/docs/05_selenium_rc.jsp
 * 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:
{{{#!highlight python
from selenium import selenium
import unittest, time, re

class testyii1(unittest.TestCase):
    def setUp(self):
        self.verificationErrors = []
        self.selenium = selenium("localhost", 4444, "*chrome", "http://localhostyii/")
        self.selenium.start()

    def test_testyii1(self):
        timeoutx='30000'
        sel = self.selenium
        sel.window_maximize();
        sel.open("http://localhostyii/demos/blog/")
        sel.click("link=Login")
        sel.wait_for_page_to_load(timeoutx)
        sel.type("id=LoginForm_username", "demo")
        sel.type("id=LoginForm_password", "demo")
        sel.click("name=yt0")
        sel.wait_for_page_to_load(timeoutx)
        sel.click("link=Manage Posts")
        sel.wait_for_page_to_load(timeoutx)
        sel.click("link=Welcome!")
        sel.click("link=Logout")
        sel.wait_for_page_to_load(timeoutx)

    def tearDown(self):
        self.selenium.stop()
        self.assertEqual([], self.verificationErrors)

if __name__ == "__main__":
    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  ==
{{{#!highlight python
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument('--ignore-certificate-errors')
options.add_argument("--test-type")
options.binary_location = "/usr/bin/chromium"
driver = webdriver.Chrome(chrome_options=options)
driver.get('https://python.org')
driver.save_screenshot("screenshot.png")
driver.close()
}}}