Fixed WebUI tests. Added new tests.

This commit is contained in:
Timur Nurlygayanov 2013-03-26 13:24:37 +04:00
parent 29da07cda8
commit e4abc9b157
4 changed files with 214 additions and 47 deletions

View File

@ -4,9 +4,9 @@ import page
class DataCentersPage(page.Page): class DataCentersPage(page.Page):
page = None
def create_data_center(self, name): def create_data_center(self, name):
self.Refresh()
self.Button('Create Windows Data Center').Click() self.Button('Create Windows Data Center').Click()
@ -14,14 +14,12 @@ class DataCentersPage(page.Page):
xpath = "//input[@value='Create']" xpath = "//input[@value='Create']"
self.Button(xpath).Click() self.Button(xpath).Click()
return self
def delete_data_center(self, name): def delete_data_center(self, name):
self.Refresh()
link = self.Link(name).Address() link = self.Link(name).Address()
datacenter_id = re.search('windc/(\S+)', link).group(0)[6:-1] datacenter_id = re.search('windc/(\S+)', link).group(0)[6:-1]
print 'Data Center ID: ' + datacenter_id
xpath = ".//*[@id='windc__row__%s']/td[4]/div/a[2]" % datacenter_id xpath = ".//*[@id='windc__row__%s']/td[4]/div/a[2]" % datacenter_id
self.Button(xpath).Click() self.Button(xpath).Click()
@ -30,9 +28,27 @@ class DataCentersPage(page.Page):
self.Button("Delete Data Center").Click() self.Button("Delete Data Center").Click()
return self
def select_data_center(self, name): def select_data_center(self, name):
self.Link(name).Click() self.Link(name).Click()
page = ServicesPage(self.driver) page = ServicesPage(self.driver)
return page return page
def deploy_data_center(self, name):
self.Refresh()
link = self.Link(name).Address()
datacenter_id = re.search('windc/(\S+)', link).group(0)[6:-1]
xpath = ".//*[@id='windc__row__%s']/td[4]/div/a[2]" % datacenter_id
self.Button(xpath).Click()
button_id = "windc__row_%s__action_deploy" % datacenter_id
self.Button(button_id).Click()
def get_datacenter_status(self, name):
self.Navigate('Windows Data Centers')
link = self.Link(name).Address()
datacenter_id = re.search('windc/(\S+)', link).group(0)[6:-1]
xpath = ".//*[@id='windc__row__%s']/td[3]" % datacenter_id
return self.TableCell(xpath).Text()

View File

@ -1,16 +1,38 @@
import logging
from selenium.webdriver.support.ui import Select
logging.basicConfig()
LOG = logging.getLogger(' Page object: ')
class TableCellClass:
table = None
def __init__(self, obj):
if not obj:
LOG.error('TableCell does not found')
self.table = obj
def Text(self):
if self.table:
return self.table.text()
else:
return ''
class ButtonClass: class ButtonClass:
button = None button = None
def __init__(self, obj): def __init__(self, obj):
if not obj:
LOG.error('Button does not found')
self.button = obj self.button = obj
def Click(self): def Click(self):
self.button.click() if self.button:
self.button.click()
def isPresented(self): def isPresented(self):
if self.button != None: if self.button:
return True return True
return False return False
@ -19,60 +41,84 @@ class LinkClass:
link = None link = None
def __init__(self, obj): def __init__(self, obj):
if not obj:
LOG.error('Link does not found')
self.link = obj self.link = obj
def Click(self): def Click(self):
self.link.click() if self.link:
self.link.click()
def isPresented(self): def isPresented(self):
if self.link != None: if self.link:
return True return True
return False return False
def Address(self): def Address(self):
return self.link.get_attribute('href') if self.link:
return self.link.get_attribute('href')
else:
return ''
class EditBoxClass: class EditBoxClass:
def __init__(self, obj): def __init__(self, obj):
if not obj:
LOG.error('EditBox does not found')
self.edit = obj self.edit = obj
def isPresented(self): def isPresented(self):
if self.edit != None: if self.edit:
return True return True
return False return False
def Set(self, value): def Set(self, value):
self.edit.clear() if self.edit:
self.edit.send_keys(value) self.edit.clear()
self.edit.send_keys(value)
def Text(self): def Text(self):
return self.edit.get_text() if self.edit:
return self.edit.get_text()
else:
return ''
class DropDownListClass: class DropDownListClass:
select = None select = None
def __init__(self, obj): def __init__(self, obj):
if not obj:
LOG.error('DropDownList does not found')
self.select = obj self.select = obj
def isPresented(self): def isPresented(self):
if self.select != None: if self.select is not None:
return True return True
return False return False
def Set(self, value): def Set(self, value):
self.select.select_by_visible_text(value) if self.select:
Select(self.select).select_by_visible_text(value)
def Text(self): def Text(self):
return self.select.get_text() if self.select:
return self.select.get_text()
else:
return ''
error_msg = """
Object with parameter: %s
does not found on page.
"""
class Page: class Page:
driver = None driver = None
timeout = 300 timeout = 30
def __init__(self, driver): def __init__(self, driver):
driver.set_page_load_timeout(30) driver.set_page_load_timeout(30)
@ -82,7 +128,7 @@ class Page:
def _find_element(self, parameter): def _find_element(self, parameter):
obj = None obj = None
k = 0 k = 0
while (obj == None and k < self.timeout): while (obj is None and k < self.timeout):
k += 1 k += 1
try: try:
obj = self.driver.find_element_by_name(parameter) obj = self.driver.find_element_by_name(parameter)
@ -105,11 +151,20 @@ class Page:
except: except:
pass pass
return obj LOG.error(error_msg % parameter)
return None
def Open(self, url): def Open(self, url):
self.driver.get(url) self.driver.get(url)
def Refresh(self):
self.driver.refresh()
def TableCell(self, name):
obj = self._find_element(name)
table = TableCellClass(obj)
return table
def Button(self, name): def Button(self, name):
obj = self._find_element(name) obj = self._find_element(name)
button = ButtonClass(obj) button = ButtonClass(obj)

View File

@ -5,19 +5,20 @@ import re
class ServicesPage(page.Page): class ServicesPage(page.Page):
def create_service(self, service_type, parameters): def create_service(self, service_type, parameters):
self.Refresh()
self.Button('services__action_CreateService').Click() self.Button('services__action_CreateService').Click()
self.DropDownList('0-service').Set(service_type) self.DropDownList('0-service').Set(service_type)
self.Button('wizard_goto_step').Click() self.Button('wizard_goto_step').Click()
for parameter in parameters: for key in parameters:
self.EditBox(parameter.key).Set(parameter.value) self.EditBox(key).Set(parameters[key])
self.Button("//input[@value='Create']").Click() self.Button("//input[@value='Create']").Click()
return self
def delete_service(self, name): def delete_service(self, name):
self.Refresh()
link = self.Link(name).Address() link = self.Link(name).Address()
service_id = re.search('windc/(\S+)', link).group(0)[6:-1] service_id = re.search('windc/(\S+)', link).group(0)[6:-1]
@ -29,5 +30,3 @@ class ServicesPage(page.Page):
self.Button(button_id).Click() self.Button(button_id).Click()
self.Button("Delete Service").Click() self.Button("Delete Service").Click()
return self

View File

@ -5,19 +5,7 @@ from login_page import LoginPage
from datacenters_page import DataCentersPage from datacenters_page import DataCentersPage
from selenium import webdriver from selenium import webdriver
"""
class SanityTests(unittest2.TestCase):
def setUp(self):
driver = webdriver.Firefox()
self.page = LoginPage(driver)
self.page.login()
self.page.Navigate('Project:Windows Data Centers')
self.page = DataCentersPage(driver)
def tearDown(self):
self.page.driver.close()
def test_01_create_data_center(self): def test_01_create_data_center(self):
self.page.create_data_center('dc1') self.page.create_data_center('dc1')
assert self.page.Link('dc1').isPresented() assert self.page.Link('dc1').isPresented()
@ -27,25 +15,42 @@ class SanityTests(unittest2.TestCase):
assert not self.page.Link('dc1').isPresented() assert not self.page.Link('dc1').isPresented()
def test_03_create_data_centers(self): def test_03_create_data_centers(self):
for i in range(1, 20): for i in range(1, 10):
name = 'datacenter' + str(i) name = 'datacenter' + str(i)
self.page.create_data_center(name) self.page.create_data_center(name)
assert self.page.Link(name).isPresented() assert self.page.Link(name).isPresented()
def test_04_delete_data_centers(self): def test_04_delete_data_centers(self):
self.page.delete_data_center('datacenter1') self.page.delete_data_center('datacenter1')
self.page.delete_data_center('datacenter20') self.page.delete_data_center('datacenter9')
assert not self.page.Link('datacenter1').isPresented() assert not self.page.Link('datacenter1').isPresented()
assert not self.page.Link('datacenter20').isPresented() assert not self.page.Link('datacenter9').isPresented()
for i in range(2, 19): for i in range(2, 9):
name = 'datacenter' + str(i) name = 'datacenter' + str(i)
assert self.page.Link(name).isPresented() assert self.page.Link(name).isPresented()
"""
class SanityTests(unittest2.TestCase):
@classmethod
def setUpClass(self):
driver = webdriver.Firefox()
self.page = LoginPage(driver)
self.page.login()
self.page.Navigate('Project:Windows Data Centers')
self.page = DataCentersPage(driver)
@classmethod
def tearDownClass(self):
self.page.driver.close()
def test_05_create_service_ad(self): def test_05_create_service_ad(self):
name = 'dc001.local' name = 'dc001.local'
self.page.create_data_center('test') self.page.Navigate('Windows Data Centers')
self.page.select_data_center('test') self.page.create_data_center('test05')
self.page = self.page.select_data_center('test05')
ad_parameters = {'1-dc_name': name, ad_parameters = {'1-dc_name': name,
'1-dc_count': 1, '1-dc_count': 1,
@ -54,7 +59,99 @@ class SanityTests(unittest2.TestCase):
self.page.create_service('Active Directory', ad_parameters) self.page.create_service('Active Directory', ad_parameters)
assert self.page.Link(name).isPresented() assert self.page.Link(name).isPresented()
"""
def test_06_create_service_ad_two_instances(self):
name = 'dc002.local'
self.page.Navigate('Windows Data Centers')
self.page.create_data_center('test06')
self.page = self.page.select_data_center('test06')
ad_parameters = {'1-dc_name': name,
'1-dc_count': 2,
'1-adm_password': 'P@ssw0rd2',
'1-recovery_password': 'P@ssw0rd'}
self.page.create_service('Active Directory', ad_parameters)
assert self.page.Link(name).isPresented()
def test_07_create_service_ad_with_iis(self):
ad_name = 'dc003.local'
self.page.Navigate('Windows Data Centers')
self.page.create_data_center('test07')
self.page = self.page.select_data_center('test07')
ad_parameters = {'1-dc_name': ad_name,
'1-dc_count': 3,
'1-adm_password': 'P@ssw0rd',
'1-recovery_password': 'P@ssw0rd2'}
self.page.create_service('Active Directory', ad_parameters)
assert self.page.Link(ad_name).isPresented()
iis_name = 'iis_server1'
iis_parameters = {'1-iis_name': iis_name,
'1-adm_password': 'P@ssw0rd',
'1-iis_domain': 'dc003.local',
'1-domain_user_name': 'Administrator',
'1-domain_user_password': 'P@ssw0rd'}
self.page.create_service('Internet Information Services',
iis_parameters)
assert self.page.Link(iis_name).isPresented()
iis_name = 'iis_server2'
iis_parameters = {'1-iis_name': iis_name,
'1-adm_password': 'P@ssw0rd',
'1-iis_domain': 'dc003.local',
'1-domain_user_name': 'Administrator',
'1-domain_user_password': 'P@ssw0rd'}
self.page.create_service('Internet Information Services',
iis_parameters)
assert self.page.Link(iis_name).isPresented()
iis_name = 'iis_server3'
iis_parameters = {'1-iis_name': iis_name,
'1-adm_password': 'P@ssw0rd',
'1-iis_domain': 'dc003.local',
'1-domain_user_name': 'Administrator',
'1-domain_user_password': 'P@ssw0rd'}
self.page.create_service('Internet Information Services',
iis_parameters)
assert self.page.Link(iis_name).isPresented()
def test_08_deploy_data_center(self):
ad_name = 'AD.net'
self.page.Navigate('Windows Data Centers')
self.page.create_data_center('test08')
self.page = self.page.select_data_center('test08')
ad_parameters = {'1-dc_name': ad_name,
'1-dc_count': 2,
'1-adm_password': 'P@ssw0rd',
'1-recovery_password': 'P@ssw0rd2'}
self.page.create_service('Active Directory', ad_parameters)
assert self.page.Link(ad_name).isPresented()
iis_parameters = {'1-iis_name': 'iis_server',
'1-adm_password': 'P@ssw0rd',
'1-iis_domain': 'AD.net',
'1-domain_user_name': 'Administrator',
'1-domain_user_password': 'P@ssw0rd'}
self.page.create_service('Internet Information Services',
iis_parameters)
assert self.page.Link('iis_server').isPresented()
self.page.Navigate('Windows Data Centers')
self.page = DataCentersPage(self.page.driver)
self.page.deploy_data_center('test08')
status = self.page.get_datacenter_status('test08')
assert 'Deploy in progress' in status
"""
if __name__ == '__main__': if __name__ == '__main__':
unittest2.main() unittest2.main()