= 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
Test Suite
}}}
loginLogout.html
{{{#!highlight html
Login and Logout
Login and Logout
storeEval prompt("User"); userx
storeEval prompt("Password"); passwordx
open http://localhostyii/demos/blog/
clickAndWait link=Login
type id=LoginForm_username ${userx}
type id=LoginForm_password ${passwordx}
clickAndWait //input[@value='Login']
clickAndWait link=Logout (demo)
}}}
addPost.html
{{{#!highlight html
Add post
Add post
open http://localhostyii/demos/blog/
clickAndWait link=Login
type id=LoginForm_username demo
type id=LoginForm_password demo
clickAndWait name=yt0
clickAndWait link=Create New Post
type id=Post_title Selenium Title
store javascript{ new Date().toString() } datex
type id=Post_content ${datex}
clickAndWait name=yt0
waitForText link=Selenium Title AABBCC Selenium Title AABBCC
click link=Logout (demo)
}}}
deletePost.html
{{{#!highlight html
deletePost
deletePost
open http://localhostyii/demos/blog/
clickAndWait link=Login
type id=LoginForm_username demo
type id=LoginForm_password demo
clickAndWait name=yt0
clickAndWait link=Manage Posts
clickAndWait css=img[alt="Delete"]
assertConfirmation Are you sure you want to delete this item?
clickAndWait link=Logout
}}}
== 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 ==
{{{
storeEval selenium.browserbot.getUserWindow().jQuery('#selectx_id option:contains("Option Value")').css('display'); optionValueVisible
echo ${optionValueVisible}
storeEval "none" noneValue
assertEval storedVars['optionValueVisible']==storedVars['noneValue'] true
}}}
== 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()
}}}