Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions selenium_tests/selenium_test_base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# -*- coding: utf-8 -*-
import time
from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import NoAlertPresentException
import unittest


class SeleniumTestBase(unittest.TestCase):
def setUp(self):
ff_binary = webdriver.firefox.firefox_binary.FirefoxBinary()
ff_profile = webdriver.firefox.firefox_profile.FirefoxProfile()
ff_profile.assume_untrusted_cert_issuer = True
ff_profile.accept_untrusted_certs = True
capabilities = webdriver.DesiredCapabilities().FIREFOX
capabilities['acceptSslCerts'] = True
self.driver = webdriver.Firefox(firefox_binary=ff_binary,
firefox_profile=ff_profile,
capabilities=capabilities,
timeout=60)
self.driver.implicitly_wait(30)
self.base_url = "https://127.0.0.1:8000/"
self.verificationErrors = []
self.accept_next_alert = True

def is_element_present(self, how, what):
try:
self.driver.find_element(by=how, value=what)
except NoSuchElementException as e:
return False
return True

def is_alert_present(self):
try:
self.driver.switch_to_alert()
except NoAlertPresentException as e:
return False
return True

def close_alert_and_get_its_text(self):
try:
alert = self.driver.switch_to_alert()
alert_text = alert.text
if self.accept_next_alert:
alert.accept()
else:
alert.dismiss()
return alert_text
finally:
self.accept_next_alert = True

def wait_for(self, check_func, timeout=30):
for i in range(timeout):
try:
if check_func():
break
except:
pass
time.sleep(1)
else:
self.fail("time out")

def tearDown(self):
self.driver.quit()
self.assertEqual([], self.verificationErrors)

if __name__ == "__main__":
unittest.main()
81 changes: 8 additions & 73 deletions selenium_tests/test_login_logout.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,8 @@
# -*- coding: utf-8 -*-
from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import NoAlertPresentException
import unittest
import time
from selenium_tests.selenium_test_base import SeleniumTestBase


class TestLoginLogout(unittest.TestCase):

def setUp(self):
ff_binary = webdriver.firefox.firefox_binary.FirefoxBinary()
ff_profile = webdriver.firefox.firefox_profile.FirefoxProfile()
ff_profile.assume_untrusted_cert_issuer = True
ff_profile.accept_untrusted_certs = True
capabilities = webdriver.DesiredCapabilities().FIREFOX
capabilities['acceptSslCerts'] = True
self.driver = webdriver.Firefox(firefox_binary=ff_binary,
firefox_profile=ff_profile,
capabilities=capabilities)
self.driver.implicitly_wait(30)
self.base_url = "https://127.0.0.1:8000/"
self.verificationErrors = []
self.accept_next_alert = True

class TestLoginLogout(SeleniumTestBase):
def test_login_logout(self):
driver = self.driver
driver.get(self.base_url + "/hub/login")
Expand All @@ -32,55 +12,10 @@ def test_login_logout(self):
driver.find_element_by_id("password_input").clear()
driver.find_element_by_id("password_input").send_keys("test")
driver.find_element_by_id("login_submit").click()
for i in range(60):
try:
if "Available Applications" == driver.find_element_by_css_selector("h1").text:
break
except:
pass
time.sleep(1)
else:
self.fail("time out")
self.wait_for(
lambda: "Available Applications" == driver.find_element_by_css_selector("h1").text
)
driver.find_element_by_id("logout").click()
for i in range(60):
try:
if "Sign in" == driver.find_element_by_css_selector("div.auth-form-header").text:
break
except:
pass
time.sleep(1)
else:
self.fail("time out")

def is_element_present(self, how, what):
try:
self.driver.find_element(by=how, value=what)
except NoSuchElementException as e:
return False
return True

def is_alert_present(self):
try:
self.driver.switch_to_alert()
except NoAlertPresentException as e:
return False
return True

def close_alert_and_get_its_text(self):
try:
alert = self.driver.switch_to_alert()
alert_text = alert.text
if self.accept_next_alert:
alert.accept()
else:
alert.dismiss()
return alert_text
finally:
self.accept_next_alert = True

def tearDown(self):
self.driver.quit()
self.assertEqual([], self.verificationErrors)

if __name__ == "__main__":
unittest.main()
self.wait_for(
lambda: "Sign in" == driver.find_element_by_css_selector("div.auth-form-header").text
)
79 changes: 5 additions & 74 deletions selenium_tests/test_start_stop_container.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,11 @@
# -*- coding: utf-8 -*-
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import NoAlertPresentException
import unittest
import time
import re

from selenium_tests.selenium_test_base import SeleniumTestBase

class TestStartStopContainer(unittest.TestCase):

def setUp(self):
ff_binary = webdriver.firefox.firefox_binary.FirefoxBinary()
ff_profile = webdriver.firefox.firefox_profile.FirefoxProfile()
ff_profile.assume_untrusted_cert_issuer = True
ff_profile.accept_untrusted_certs = True
capabilities = webdriver.DesiredCapabilities().FIREFOX
capabilities['acceptSslCerts'] = True
self.driver = webdriver.Firefox(firefox_binary=ff_binary,
firefox_profile=ff_profile,
capabilities=capabilities)
self.driver.implicitly_wait(30)
self.base_url = "https://127.0.0.1:8000/"
self.verificationErrors = []
self.accept_next_alert = True

class TestStartStopContainer(SeleniumTestBase):
def test_start_stop_container(self):
driver = self.driver
driver.get(self.base_url + "/hub/login")
Expand All @@ -47,57 +26,9 @@ def test_start_stop_container(self):
self.fail("time out")
driver.find_element_by_link_text("Close").click()
driver.find_element_by_name("action").click()
for i in range(60):
try:
if "noVNC" == driver.title:
break
except:
pass
time.sleep(1)
else:
self.fail("time out")
self.wait_for(lambda: "noVNC" == driver.title)
driver.find_element_by_xpath("//i").click()
driver.find_element_by_xpath("(//button[@name='action'])[2]").click()
for i in range(60):
try:
if "Start" == driver.find_element_by_name("action").text:
break
except:
pass
time.sleep(1)
else:
self.fail("time out")
self.wait_for(
lambda: "Start" == driver.find_element_by_name("action").text)
driver.find_element_by_id("logout").click()

def is_element_present(self, how, what):
try:
self.driver.find_element(by=how, value=what)
except NoSuchElementException as e:
return False
return True

def is_alert_present(self):
try:
self.driver.switch_to_alert()
except NoAlertPresentException as e:
return False
return True

def close_alert_and_get_its_text(self):
try:
alert = self.driver.switch_to_alert()
alert_text = alert.text
if self.accept_next_alert:
alert.accept()
else:
alert.dismiss()
return alert_text
finally:
self.accept_next_alert = True

def tearDown(self):
self.driver.quit()
self.assertEqual([], self.verificationErrors)

if __name__ == "__main__":
unittest.main()