Skip to content
This repository has been archived by the owner on Apr 4, 2023. It is now read-only.

Commit

Permalink
Merge pull request #1 from sujeetsr/master
Browse files Browse the repository at this point in the history
Updated tests and README
  • Loading branch information
sujeetsr committed May 23, 2013
2 parents 857193d + 311d24d commit d55f260
Show file tree
Hide file tree
Showing 16 changed files with 261 additions and 84 deletions.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

**Check out the code**

[email protected]:rockstor/rockstor-tests.git

**Install required modules**

pip install -r requirements.txt

**Configure**

Set the rockstor base_url in webdriver/development.yaml

**Run tests**

cd to the webdriver directory

You can run an individual test like this

python login.py


2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
selenium==2.32.0
PyYAML==3.10
2 changes: 2 additions & 0 deletions webdriver/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.py[cod]

25 changes: 25 additions & 0 deletions webdriver/all_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Select
from selenium.webdriver.support.ui import WebDriverWait
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.support import expected_conditions as EC
import unittest, time, re
import yaml
import sys, getopt
from rockstor_testcase import RockStorTestCase
from inspect import stack
from util import read_conf
from login import Login
from pools_create_raid0_2disks import PoolsCreateRaid02Disks

if __name__ == '__main__':
conf = read_conf()
# TODO generate screenshot dir name from timestamp and create dir
conf['screenshot_dir'] = 'output2'
suite = unittest.TestSuite()
suite.addTest(RockStorTestCase.parametrize(Login, conf=conf))
suite.addTest(RockStorTestCase.parametrize(PoolsCreateRaid02Disks, conf=conf))
unittest.TextTestRunner(verbosity=2).run(suite)


1 change: 0 additions & 1 deletion webdriver/config.yaml

This file was deleted.

2 changes: 2 additions & 0 deletions webdriver/development.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
base_url: https://rs14dev
screenshot_dir: output
65 changes: 35 additions & 30 deletions webdriver/login.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,40 @@
from selenium import webdriver
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Select
from selenium.webdriver.support.ui import WebDriverWait
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By

driver = webdriver.Firefox()

# read configuration
import unittest, time, re
import yaml
f = open('config.yaml')
# use safe_load instead load
config = yaml.safe_load(f)
login_url = config['login_url']

f.close()

# Go to the Login page
driver.get(login_url)

# Fill in username / password
loginField = driver.find_element_by_name("login")
loginField.send_keys("admin")

passwordField = driver.find_element_by_name("password")
passwordField.send_keys("admin")

# submit the form
driver.find_element_by_id("sign_in").click()

current_step = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.CLASS_NAME, "current-step")))
print current_step.text

driver.quit()
import sys, getopt
from rockstor_testcase import RockStorTestCase
from inspect import stack
import sys, traceback

class Login(RockStorTestCase):
def test_login(self):
try:
# Login
driver = self.driver
driver.get(self.base_url + "/login_page")
driver.find_element_by_id("inputUsername").clear()
driver.find_element_by_id("inputUsername").send_keys("admin")
driver.find_element_by_id("inputPassword").clear()
driver.find_element_by_id("inputPassword").send_keys("admin")
driver.find_element_by_id("sign_in").click()

# Check that the dashboard title is displayed
WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.CLASS_NAME, "widgets-container")))
dashboard_title = driver.find_element_by_id("title")
self.assertRegexpMatches(dashboard_title.text, r"^[\s\S]*Dashboard[\s\S]*$")
# logout
driver.find_element_by_id("logout_user").click()
except Exception, e:
exc_type, exc_value, exc_traceback = sys.exc_info()
traceback.print_exception(exc_type, exc_value, exc_traceback,
limit=2, file=sys.stdout)
self.save_screenshot(stack()[0][3])

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

44 changes: 44 additions & 0 deletions webdriver/login_and_setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Select
from selenium.webdriver.support.ui import WebDriverWait
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.support import expected_conditions as EC
import unittest, time, re
import yaml
import sys, getopt
import time
from rockstor_testcase import RockStorTestCase

class LoginAndSetup(RockStorTestCase):
def test_login_and_setup(self):
driver = self.driver
driver.get(self.base_url + "/login_page?next=/")
driver.find_element_by_id("inputUsername").clear()
driver.find_element_by_id("inputUsername").send_keys("admin")
driver.find_element_by_id("inputPassword").clear()
driver.find_element_by_id("inputPassword").send_keys("admin")
driver.find_element_by_id("sign_in").click()
btn_next = driver.find_element_by_id('next-page')
next_step_text = btn_next.text
# Go through the setup wizard till the last page is displayed.
while next_step_text != 'Finish':
btn_next.click()
# wait till current step element is rendered
current_step = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.CLASS_NAME, "current-step")))
btn_next = driver.find_element_by_id('next-page')
next_step_text = btn_next.text

# Finish
btn_next.click()

# Check that the dashboard title is displayed
WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, "widgets-container")))
dashboard_title = driver.find_element_by_id("title")
self.assertRegexpMatches(dashboard_title.text, r"^[\s\S]*System Dashboard[\s\S]*$")
# logout
driver.find_element_by_id("logout_user").click()

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

24 changes: 0 additions & 24 deletions webdriver/login_happypath.py

This file was deleted.

23 changes: 23 additions & 0 deletions webdriver/login_invalid_password.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
import unittest, time, re
from rockstor_testcase import RockStorTestCase

class LoginInvalidPassword(RockStorTestCase):

def test_login_invalid_username(self):
driver = self.driver
driver.get(self.base_url + "/login_page")
driver.find_element_by_id("inputUsername").clear()
driver.find_element_by_id("inputUsername").send_keys("admin")
driver.find_element_by_id("inputPassword").clear()
driver.find_element_by_id("inputPassword").send_keys("admin1")
driver.find_element_by_css_selector("button.btn.btn-primary").click()
# Warning: verifyTextPresent may require manual changes
self.assertRegexpMatches(driver.find_element(by=By.TAG_NAME, value="body").text, r"^[\s\S]*Login incorrect![\s\S]*$")

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

4 changes: 3 additions & 1 deletion webdriver/login_invalid_username.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class LoginInvalidUsername(RockStorTestCase):

def test_login_invalid_username(self):
driver = self.driver
driver.get(self.base_url + "/login_page?next=/")
driver.get(self.base_url + "/login_page")
driver.find_element_by_id("inputUsername").clear()
driver.find_element_by_id("inputUsername").send_keys("admin1")
driver.find_element_by_id("inputPassword").clear()
Expand All @@ -18,3 +18,5 @@ def test_login_invalid_username(self):
# Warning: verifyTextPresent may require manual changes
self.assertRegexpMatches(driver.find_element(by=By.TAG_NAME, value="body").text, r"^[\s\S]*Login incorrect![\s\S]*$")

if __name__ == '__main__':
unittest.main()
22 changes: 0 additions & 22 deletions webdriver/login_suite.py

This file was deleted.

57 changes: 57 additions & 0 deletions webdriver/pools_create_raid0_2disks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Select
from selenium.webdriver.support.ui import WebDriverWait
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.support import expected_conditions as EC
import unittest, time, re
import yaml
import sys, getopt
from rockstor_testcase import RockStorTestCase
from inspect import stack
from util import read_conf
from inspect import stack
import sys, traceback

class PoolsCreateRaid02Disks(RockStorTestCase):

def test_create_raid0_2disks(self):
try:
self.login()
self.create_pool()
except Exception, e:
exc_type, exc_value, exc_traceback = sys.exc_info()
traceback.print_exception(exc_type, exc_value, exc_traceback,
limit=2, file=sys.stdout)
self.save_screenshot(stack()[0][3])

def login(self):
# Login
driver = self.driver
driver.get(self.base_url + "/login_page")
driver.find_element_by_id("inputUsername").clear()
driver.find_element_by_id("inputUsername").send_keys("admin")
driver.find_element_by_id("inputPassword").clear()
driver.find_element_by_id("inputPassword").send_keys("admin")
driver.find_element_by_id("sign_in").click()

# Check that the dashboard title is displayed
WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.CLASS_NAME, "widgets-container")))
dashboard_title = driver.find_element_by_id("title")
self.assertRegexpMatches(dashboard_title.text, r"^[\s\S]*Dashboard[\s\S]*$")

def create_pool(self):
driver = self.driver
driver.find_element_by_id("pools_nav").click()
WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, "add_pool")))
driver.find_element_by_id("add_pool").click()
driver.find_element_by_id("pool_name").clear()
driver.find_element_by_id("pool_name").send_keys("pool1")
driver.find_element_by_id("sdb").click()
driver.find_element_by_id("sdc").click()
driver.find_element_by_id("create_pool").click()
WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.LINK_TEXT, "pool1")))

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

40 changes: 36 additions & 4 deletions webdriver/rockstor_testcase.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,49 @@
import unittest, time, re
import yaml
import sys, getopt
from util import read_conf
from inspect import stack

class RockStorTestCase(unittest.TestCase):
def __init__(self, methodName='runTest', conf=None):
super(RockStorTestCase, self).__init__(methodName)
if conf == None:
self.conf = read_conf()
else:
self.conf = conf

def setUp(self):
self.driver = webdriver.Firefox()
self.driver.implicitly_wait(30)
with open('config.yaml','r') as f:
conf = yaml.load(f)
self.base_url = conf['base_url']
self.driver.implicitly_wait(15)
self.base_url = self.conf['base_url']
self.verificationErrors = []
self.accept_next_alert = True

def tearDown(self):
self.driver.quit()

def save_screenshot(self, testname):
filename = "%s_%s" %(self.get_timestamp_str(), testname)
print "Saving screenshot to %s" % filename
self.driver.save_screenshot('%s/%s.png' % (self.conf['screenshot_dir'],
filename))

def save_screenshot_from_stack(self):
self.save_screenshot(stack()[1][3])

def get_timestamp_str(self):
return time.strftime("%Y%m%d%H%M%S")

@staticmethod
def parametrize(testcase_klass, conf = None):
""" Create a suite containing all tests taken from the given
subclass, passing them the parameter 'param'.
"""
testloader = unittest.TestLoader()
testnames = testloader.getTestCaseNames(testcase_klass)
suite = unittest.TestSuite()
for name in testnames:
suite.addTest(testcase_klass(name, conf=conf))
return suite


3 changes: 3 additions & 0 deletions webdriver/staging.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
base_url: https://rs14staging
screenshot_dir: output

9 changes: 7 additions & 2 deletions webdriver/util.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import yaml
import argparse

def read_conf(env_name):
def read_conf():
parser = argparse.ArgumentParser(description='Run RockStor webdriver tests.')
parser.add_argument('-e', '--env_name', default='development')
parser.add_argument('testname', nargs='?', default=None)
args = parser.parse_args()
conf = None
with open('config.yaml','r') as f:
with open('%s.yaml' % args.env_name,'r') as f:
conf = yaml.load(f)
return conf

0 comments on commit d55f260

Please sign in to comment.