Univention Bugzilla – Attachment 5209 Details for
Bug 21728
UDM Web Test per Selenium
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
WIP: Noch eine Variante des UMC-Logins
selenium-webdriver.py (text/plain), 5.32 KB, created by
Philipp Hahn
on 2013-04-30 15:09 CEST
(
hide
)
Description:
WIP: Noch eine Variante des UMC-Logins
Filename:
MIME Type:
Creator:
Philipp Hahn
Created:
2013-04-30 15:09 CEST
Size:
5.32 KB
patch
obsolete
>#!/usr/bin/python >"""Run simple UMC login Selenium test.""" ># ># python-selenium is too old in Debian sid and does not work with Iceweasel 10. ># Install via pip: ># aptitude install python-pip ># pip install selenium ># ># <http://seleniumhq.org/docs/03_webdriver.jsp> ># >import sys >import time >from optparse import OptionParser > >from selenium import webdriver >from selenium.webdriver.common.desired_capabilities import DesiredCapabilities >#from selenium.common.exceptions import TimeoutException >from selenium.webdriver.support.ui import WebDriverWait # >= 2.4.0 >#from selenium.webdriver.support import expected_conditions as EC # >= 2.26.0 > > >class German(object): > """German.""" > languages = "de-DE,de" > logout_button = "//span[string()='Abmelden']" > > >class English(object): > """English.""" > languages = "en" > logout_button = "//span[string()='Logout']" > > >class Test(object): > """UMC Login.""" > > def firefox(self): > """Setup firefox.""" > # Create a new profile > profile = webdriver.FirefoxProfile() > profile.set_preference("intl.accept_languages", self.lang.languages) > > # Create a new instance of the Firefox driver > driver = webdriver.Firefox(firefox_profile=profile) > > return driver > > > def chrome(self): > """Setup chome or chromium.""" > # <http://code.google.com/p/selenium/downloads/list> > # Create settings > settings = { > "intl.accept_languages": self.lang.languages, > } > # Create options > options = webdriver.ChromeOptions() > options.add_argument("start-maximized") > options.add_experimental_option("prefs", settings) > > # Create a new instance of the Chrome driver > driver = webdriver.Chrome(chrome_options=options) > > return driver > > > def iexporer(self): > """Setup Internet Explorer.""" > driver = webdriver.Ie() > return driver > > > def opera(self): > """Setup Opera Explorer.""" > driver = webdriver.Opera() > return driver > > > def remote(self): > """Setup Remote driver.""" > # <http://code.google.com/p/selenium/wiki/Grid2> > cap = webdriver.DesiredCapabilities() > cap = cap.FIREFOX | cap.CHROME | cap.ANDROID | cap.HTMLUNIT | cap.HTMLUNITWITHJS | cap.INTERNETEXPLORER | cap.IPAD | cap.IPHONE | cap.OPERA | cap.PHANTOMJS | cap.SAFARI > #cap["jenkins.label"] = "redhat5 && amd64" > #cap["jenkins.nodeName"] = "(master)" > driver = webdriver.Remote(cap) > return driver > > > def __init__(self, options): > """Initialize browser.""" > if options.lang == "de": > self.lang = German > elif options.lang == "en": > self.lang = English > else: > raise ValueError(options.lang) > > if options.browser == "firefox": > self.driver = self.firefox() > elif options.browser == "chrome": > self.driver = self.chrome() > elif options.browser == "ie": > self.driver = self.iexporer() > elif options.browser == "opera": > self.driver = self.opera() > elif options.browser == "remote": > self.driver = self.remote() > else: > raise ValueError(options.browser) > > self.delay = options.delay > self.timeout = options.timeout > > #driver.implicitly_wait(10) # seconds > > > def run(self, url): > """Run test.""" > driver = self.driver > try: > # go to UMC > driver.get(url) > time.sleep(1) # FIXME Chromium > > # The login in loaded in an <iframe> > driver.switch_to_frame("umc_LoginDialog_Iframe") > > # Setup user name > username = driver.find_element_by_id("umc_UsernameInput") > username.send_keys("Administrator") > > # Enter password > password = driver.find_element_by_id("umc_PasswordInput") > password.send_keys("univention") > > # Submit > login = driver.find_element_by_id("umc_SubmitButton") > login.click() > > # Leave <iframe> > driver.switch_to_default_content() > driver.get_screenshot_as_file("result1.png") > > # Logout again > logout = driver.find_element_by_css_selector(".umcLogoutButton") > logout.click() > driver.get_screenshot_as_file("result2.png") > > # Confirm logout > logout = self.wait(lambda driver: > driver.find_element_by_xpath(self.lang.logout_button)) > logout.click() > driver.get_screenshot_as_file("result3.png") > except Exception: > driver.get_screenshot_as_file("resultF.png") > time.sleep(self.delay) > raise > finally: > driver.quit() > > > def wait(self, function): > """Wait for element.""" > return WebDriverWait(self.driver, self.timeout).until(function) > > >def main(): > """Run simple Selenium Web Test on UMC. > > Login to UMC. > Log out of UMC. > > """ > parser = OptionParser() > parser.add_option("-b", "--browser", > dest="browser", action="store", type="choice", > choices=("firefox", "chrome", "ie", "opera", "remote"), default="firefox", > help="Select browser") > parser.add_option("-l", "--language", > dest="lang", action="store", type="choice", > choices=("de", "en"), default="en", > help="Select language") > parser.add_option("-d", "--delay", > dest="delay", action="store", type="int", default=0, > help="Delay quit") > parser.add_option("-t", "--timeout", > dest="timeout", action="store", type="int", default=10, > help="Timeout for rendering") > > options, args = parser.parse_args() > try: > url = args.pop(0) > except IndexError: > url = "http://xen12.knut.univention.de/univention-management-console/?lang=%s" % options.lang > # ?lang=en-US&username=Administrator&password=univention&module=udm&flavor=groups/group > Test(options).run(url) > > >if __name__ == '__main__': > main() > ># <http://www.seleniumwebdriver.com/google-selenium-webdriver/best-practices-with-framework-like-dojo/> ># element = driver.execute_script("return $('.cheese')[0]")
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
Actions:
View
Attachments on
bug 21728
:
3087
|
5208
| 5209