| 
  
   Size: 666 
  
  Comment:  
 | 
  
   Size: 8293 
  
  Comment:  
 | 
| Deletions are marked like this. | Additions are marked like this. | 
| Line 5: | Line 5: | 
| Plguin for Firefox | Plugin for Firefox | 
| Line 14: | Line 14: | 
== 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("User");</td> <td>userx</td> </tr> <tr> <td>storeEval</td> <td>prompt("Password");</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="Delete"]</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 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: {{{#!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 - 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 {{{#!highlight python # test_gecko_selenium.py from selenium import webdriver driver = webdriver.Firefox(executable_path="/home/vitor/scripts/geckodriver") driver.get('https://python.org') driver.save_screenshot("screenshot.png") driver.close() }}}  | 
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
 
