CLOUDSTACK-1180: UI test automation using selenium

Description:
	Adding selenium test scripts.
This commit is contained in:
Parth Jagirdar 2013-02-19 14:40:13 -08:00 committed by David Nalley
parent 368a5d5a9a
commit 8134885e2d
8 changed files with 1870 additions and 0 deletions

52
test/selenium/ReadMe.txt Normal file
View File

@ -0,0 +1,52 @@
##############################################
This files contains following:
1) Installation requirements
2) Test Pre requisites
3) Running the Test and Generating the report
##############################################
##########################################################################################################################################
1) Installtion Requirements
1)Firefox depending on your OS (Good to have Firebug and Selenium IDE for troubleshooting and dev work)
2)Install Python 2.7. Recommend to use Active State Python
3) Now Open CMD/Terminal and type all of following
- pypm install pycrypto (Installs Pycrypto)
- pypm install paramiko (Install paramiko)
- pip install unittest-xml-reporting (Install XML Test Runner)
- pip install -U selenium (Installs Selenium)
5) Now get the HTMLTestRunner for nice looking report generation.
- http://tungwaiyip.info/software/HTMLTestRunner.html
- Download and put this file into Lib of your python installation.
##########################################################################################################################################
2) Test Prerequisites
- Download and install CS
- Log into the management server nad Add a Zone. (Must be Advance Zone and Hypervisor type must be Xen)
##########################################################################################################################################
3) Running the Test and Generating the report
- Folder smoke contains main.py
- main.py is the file where all the tests are serialized.
- main.py supports HTML and XML reporting. Please refer to end of file to choose either.
- Typical usage is: python main.py for XML Reporting
- And python main.py >> results.html for HTML Reporting.
##########################################################################################################################################

View File

@ -0,0 +1,207 @@
'''
Variable Names are as follows
Logical Page Descriptor_____What Element Represents and/or where it is_____LocatorType
For Example ::
instances_xpath = "//div[@id='navigation']/ul/li[2]/span[2]"
Means this is:: xpath link for Instances which is present on Dashboard.
Any test cases that requires to go into Instances from Dashboard can use this variable now.
This may not be intuitive as you go deep into the tree.
for example
stopinstanceforce_id
The best way to know what this represents is to track by variable name
Under Instances / any instance is click on any instance (applies to any instance) / stop instance has a force stop check box when you click.
This link represents that.
Steps below do not have global locators.
PF rule steps including and after filling port numbers. (Refer to vmLifeAndNetwork.py / def test_PF)
FW rule steps including and after filling port numbers. (Refer to vmLifeAndNetwork.py / def test_PF)
ADD Disk Offering page has Names, description, storage type etc etc
ADD Compute Offering page has Names, description, CPU Cores, CPU clocks type etc etc
Create Acc, Delete Acc, Login and Logout are for test flow and are not test cases. They do not have global Locators.
Such and many more data entry points that appear only once and hence we do not need glonal names for them. They are hard coded as and when needed in the scripts.
'''
################################################################################################################################################################################################
## Links on the Main UI page (Dash board). Listed in the order they appear on screen
dashboard_xpath = "//div[@id='navigation']/ul/li"
instances_xpath = "//div[@id='navigation']/ul/li[2]/span[2]" # Link for Instance and following as self explanatory
storage_xpath = "//div[@id='navigation']/ul/li[3]/span[2]"
network_xpath = "//div[@id='navigation']/ul/li[4]/span[2]"
templates_xpath = "//div[@id='navigation']/ul/li[5]/span[2]"
events_xpath = "//div[@id='navigation']/ul/li[6]/span[2]"
projects_xpath = "//div[@id='navigation']/ul/li[7]/span[2]"
accounts_xpath = "//div[@id='navigation']/ul/li[8]/span[2]"
domains_xpath = "//div[@id='navigation']/ul/li[9]/span[2]"
infrastructure_xpath = "//div[@id='navigation']/ul/li[10]/span[2]"
globalSettings_xpath = "//div[@id='navigation']/ul/li[11]/span[2]"
serviceOfferings_xpath = "//div[@id='navigation']/ul/li[12]/span[2]"
################################################################################################################################################################################################
## Instances Page
## Instances Main page
# Add Instance Button on top right corner of Instances page
add_instance_xpath = "//div[2]/div/div[2]/div/div[2]/span"
# Add Instance Wizard next button
add_instance_next_xpath = "//div[4]/div[2]/div[3]/div[3]/span"
# Table that lists all VM's under Instances page; General usage is to traverse through this table and search for the VM we are interested in.
instances_table_xpath = "/html/body/div/div/div[2]/div[2]/div[2]/div/div[2]/div[2]/table/tbody/tr/td/span"
# Click any instance and following are available
# Click ok on confirmation pop-up box for most actions listed below
actionconfirm_xpath = ("//button[@type='button']")
# status of VM running. Click on VM > 3rd row in table
state_xpath = "/html/body/div/div/div[2]/div[2]/div[2]/div[2]/div[2]/div/div/div[2]/div/table/tbody/tr[3]/td[2]/span"
# Stop instance icon
stopinstance_css = "a[alt=\"Stop Instance\"] > span.icon"
# stop instance forcefully check box available after stop instance is executed in separate pop up
stopinstanceforce_id = ("force_stop")
# start instance icon
startinstance_css = "a[alt=\"Start Instance\"] > span.icon"
yesconfirmation_xapth = "(//button[@type='button'])[2]"
# Destroy instance icon
destroyinstance_css = "a[alt=\"Destroy Instance\"] > span.icon"
#Restore Instance icon
restoreinstance_css = "a[alt=\"Restore Instance\"] > span.icon"
# Reboot instance
rebootinstance_css = "a[alt=\"Reboot Instance\"] > span.icon"
################################################################################################################################################################################################
## Network Page
# Table that lists all Networks under Network page; General usage is to traverse through this table and search for the network we are interested in.
network_networktable_xpath = "/html/body/div/div/div[2]/div[2]/div[2]/div[3]/div[2]/div/div[2]/table/tbody/tr/td/span"
# View IP addresses button on each network page
viewIp_css="div.view-all > a > span"
# Acquire a new ip
acquireIP_xpath="//div[2]/div/div/div[2]/span"
# List of IP's within a netork table
network_iptables_xpath = "/html/body/div/div/div[2]/div[2]/div[2]/div[3]/div[2]/div/div[2]/table/tbody/tr/td/span"
# Configuration tab for each IP
ipConfiguration_text="Configuration"
# PF under configuration for each IP
ip_PF = "li.portForwarding > div.view-details"
################################################################################################################################################################################################
## Servivce Offering Page
# Selects Compute offering from drop down menu
Offering_compute_xpath = "/html/body/div/div/div[2]/div[2]/div[2]/div/div[2]/div/div/div/select/option[1]"
# Selects System offering from drop down menu
Offering_system_xpath = "/html/body/div/div/div[2]/div[2]/div[2]/div/div[2]/div/div/div/select/option[2]"
# Selects Disk offering from drop down menu
Offering_disk_xpath = "/html/body/div/div/div[2]/div[2]/div[2]/div/div[2]/div/div/div/select/option[3]"
# Selects Network offering from drop down menu
Offering_network_xpath = "/html/body/div/div/div[2]/div[2]/div[2]/div/div[2]/div/div/div/select/option[4]"
# Add Offering
Offering_add_xpath ="//div[3]/span"
# Points to tbale that lists Offerings
Offering_table_xpath = "/html/body/div/div/div[2]/div[2]/div[2]/div/div[2]/div[2]/table/tbody/tr/td/span"
# Edit Button
Offering_edit_css = "a[alt=\"Edit\"] > span.icon"
# Edit name box
Offering_editname_name = "name"
# Edit description box
Offering_editdescription_name = "displaytext"
# Edit finished click ok
Offering_editdone_css="div.button.done"
# delete offering button for Disk only
Offering_delete_css = "a[alt=\"Delete Disk Offering\"] > span.icon"
# delete offering button for Compute only
Offering_deletecompute_css = "a[alt=\"Delete Service Offering\"] > span.icon"
################################################################################################################################################################################################
#### Templates Page
# Selects Templates from drop down
template_xpath = "/html/body/div/div/div[2]/div[2]/div[2]/div/div[2]/div/div/div/select/option[1]"
# Selects ISO from drop down
iso_xpath = "/html/body/div/div/div[2]/div[2]/div[2]/div/div[2]/div/div/div/select/option[2]"
# Add Template
AddTemplate_xpath = "//div[3]/span"
# Points to table where all templates are
template_table_xpath ="/html/body/div/div/div[2]/div[2]/div[2]/div/div[2]/div[2]/table/tbody/tr/td/span"
# Edit Template Button
template_edit_css = "a[alt=\"Edit\"] > span.icon"
# Edit finished click OK
template_editdone_css = "div.button.done"
# Delete Template button
template_delete_css = "a[alt=\"Delete Template\"] > span.icon"
################################################################################################################################################################################################
## Login Page
# Username box
login_username_css = "body.login > div.login > form > div.fields > div.field.username > input[name=\"username\"]" # Login>Username TextBox
# Password Box
login_password_css = "body.login > div.login > form > div.fields > div.field.password > input[name=\"password\"]" # LoginPassword TextBox
# Click ok to login
login_submit_css = "body.login > div.login > form > div.fields > input[type=\"submit\"]" # Login>Login Button (Submit button)

View File

@ -0,0 +1,15 @@
'''
This will help pass webdriver (Browser instance) across our test cases.
'''
from selenium import webdriver
DRIVER = None
def getOrCreateWebdriver():
global DRIVER
DRIVER = DRIVER or webdriver.Firefox()
return DRIVER

View File

@ -0,0 +1,236 @@
import sys, os
sys.path.append(os.path.abspath(os.path.dirname(__file__) + '/'+'../lib'))
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
import Global_Locators
import initialize
class login(unittest.TestCase):
def setUp(self):
self.driver = initialize.getOrCreateWebdriver()
self.base_url = "http://10.223.49.206:8080/" # Your management Server IP goes here
self.verificationErrors = []
def test_login(self):
# Here we will clear the test box for Username and Password and fill them with actual login data.
# After that we will click Login (Submit button)
driver = self.driver
driver.maximize_window()
driver.get(self.base_url + "client/")
driver.find_element_by_css_selector(Global_Locators.login_username_css).clear()
driver.find_element_by_css_selector(Global_Locators.login_username_css).send_keys("admin")
driver.find_element_by_css_selector(Global_Locators.login_password_css).clear()
driver.find_element_by_css_selector(Global_Locators.login_password_css).send_keys("password")
driver.find_element_by_css_selector(Global_Locators.login_submit_css).click()
time.sleep(5)
def is_element_present(self, how, what):
try: self.driver.find_element(by=how, value=what)
except NoSuchElementException, e: return False
return True
def tearDown(self):
self.assertEqual([], self.verificationErrors)
################################################################################################################################################
class logout(unittest.TestCase):
def setUp(self):
self.driver = initialize.getOrCreateWebdriver()
self.driver.implicitly_wait(100)
self.verificationErrors = []
def test_logout(self):
# Here we will clear the test box for Username and Password and fill them with actual login data.
# After that we will click Login (Submit button)
driver = self.driver
driver.find_element_by_xpath("//div[@id='navigation']/ul/li").click()
driver.find_element_by_css_selector("div.icon.options").click()
driver.find_element_by_link_text("Logout").click()
def is_element_present(self, how, what):
try: self.driver.find_element(by=how, value=what)
except NoSuchElementException, e: return False
return True
def tearDown(self):
self.assertEqual([], self.verificationErrors)
################################################################################################################################################
class login_test(unittest.TestCase):
def setUp(self):
self.driver = initialize.getOrCreateWebdriver()
self.verificationErrors = []
def test_logintest(self):
# Here we will clear the test box for Username and Password and fill them with actual login data.
# After that we will click Login (Submit button)
driver = self.driver
driver.find_element_by_css_selector(Global_Locators.login_username_css).clear()
driver.find_element_by_css_selector(Global_Locators.login_username_css).send_keys("test")
driver.find_element_by_css_selector(Global_Locators.login_password_css).clear()
driver.find_element_by_css_selector(Global_Locators.login_password_css).send_keys("password")
driver.find_element_by_css_selector(Global_Locators.login_submit_css).click()
time.sleep(5)
def is_element_present(self, how, what):
try: self.driver.find_element(by=how, value=what)
except NoSuchElementException, e: return False
return True
def tearDown(self):
self.assertEqual([], self.verificationErrors)
################################################################################################################################################
class createAcc(unittest.TestCase):
def setUp(self):
self.driver = initialize.getOrCreateWebdriver()
self.verificationErrors = []
def test_createacc(self):
driver = self.driver
self.driver.implicitly_wait(100)
driver.find_element_by_xpath("//div[@id='navigation']/ul/li[8]/span[2]").click()
driver.find_element_by_xpath("//div[3]/span").click()
driver.find_element_by_id("label_username").clear()
driver.find_element_by_id("label_username").send_keys("test")
driver.find_element_by_id("password").clear()
driver.find_element_by_id("password").send_keys("password")
driver.find_element_by_id("label_confirm_password").clear()
driver.find_element_by_id("label_confirm_password").send_keys("password")
driver.find_element_by_id("label_email").clear()
driver.find_element_by_id("label_email").send_keys("test@citrix.com")
driver.find_element_by_id("label_first_name").clear()
driver.find_element_by_id("label_first_name").send_keys("test")
driver.find_element_by_id("label_last_name").clear()
driver.find_element_by_id("label_last_name").send_keys("test")
driver.find_element_by_id("label_domain").click()
Select(driver.find_element_by_id("label_type")).select_by_visible_text("Admin")
Select(driver.find_element_by_id("label_timezone")).select_by_visible_text("[UTC-08:00] Pacific Standard Time")
driver.find_element_by_xpath("//button[@type='button']").click()
# Go to Dashboard
driver.find_element_by_xpath(Global_Locators.dashboard_xpath).click()
time.sleep(30)
def is_element_present(self, how, what):
try: self.driver.find_element(by=how, value=what)
except NoSuchElementException, e: return False
return True
def tearDown(self):
self.assertEqual([], self.verificationErrors)
################################################################################################################################################
class tearAcc(unittest.TestCase):
def setUp(self):
self.driver = initialize.getOrCreateWebdriver()
self.verificationErrors = []
def test_tearacc(self):
driver = self.driver
driver.find_element_by_css_selector("li.navigation-item.accounts").click()
driver.find_element_by_css_selector("tr.odd > td.name.first").click()
driver.find_element_by_css_selector("a[alt=\"Delete account\"] > span.icon").click()
driver.find_element_by_xpath("(//button[@type='button'])[2]").click()
# Go to Dashboard
driver.find_element_by_xpath(Global_Locators.dashboard_xpath).click()
time.sleep(30)
def is_element_present(self, how, what):
try: self.driver.find_element(by=how, value=what)
except NoSuchElementException, e: return False
return True
def tearDown(self):
self.driver.quit()
self.assertEqual([], self.verificationErrors)
################################################################################################################################################

View File

@ -0,0 +1,409 @@
import sys, os
sys.path.append(os.path.abspath(os.path.dirname(__file__) + '/'+'../lib'))
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
import initialize
import Global_Locators
class Disk_offering_Add(unittest.TestCase):
def setUp(self):
self.driver = initialize.getOrCreateWebdriver()
self.verificationErrors = []
def test_diskadd(self):
driver = self.driver
self.driver.implicitly_wait(200)
#Make sure you are on Dashboard
driver.find_element_by_xpath(Global_Locators.dashboard_xpath).click()
time.sleep(2)
# Go to Service Offerings
driver.find_element_by_xpath(Global_Locators.serviceOfferings_xpath).click()
#Select Disk offering
driver.find_element_by_xpath(Global_Locators.Offering_disk_xpath).click()
# Add offering
driver.find_element_by_xpath(Global_Locators.Offering_add_xpath).click()
# Following have names.. so they do not have their global entries.
driver.find_element_by_name("name").clear()
driver.find_element_by_name("name").send_keys("Test Disk Name")
driver.find_element_by_name("description").clear()
driver.find_element_by_name("description").send_keys("Test Disk Description")
driver.find_element_by_name("disksize").clear()
driver.find_element_by_name("disksize").send_keys("1")
driver.find_element_by_xpath("//button[@type='button']").click()
time.sleep(20)
##Verification will be if this offering shows up into table and we can actually edit it.
def is_element_present(self, how, what):
try: self.driver.find_element(by=how, value=what)
except NoSuchElementException, e: return False
return True
def tearDown(self):
self.assertEqual([], self.verificationErrors)
class Disk_offering_Edit(unittest.TestCase):
def setUp(self):
self.driver = initialize.getOrCreateWebdriver()
self.verificationErrors = []
def test_diskedit(self):
driver = self.driver
self.driver.implicitly_wait(200)
#Make sure you are on Dashboard
driver.find_element_by_xpath(Global_Locators.dashboard_xpath).click()
time.sleep(2)
# Go to Service Offerings
driver.find_element_by_xpath(Global_Locators.serviceOfferings_xpath).click()
#Select Disk offering
driver.find_element_by_xpath(Global_Locators.Offering_disk_xpath).click()
# We will be searching for our disk offering into the table
linkclass = None
linkclass = driver.find_elements_by_xpath(Global_Locators.Offering_table_xpath) # This returns a list of all Offerings in table
for link in linkclass:
if link.text == "Test Disk Name":
link.click()
time.sleep(2)
# Click Edit
driver.find_element_by_css_selector(Global_Locators.Offering_edit_css).click()
#Change name
driver.find_element_by_name(Global_Locators.Offering_editname_name).clear()
driver.find_element_by_name(Global_Locators.Offering_editname_name).send_keys("Test Name")
# Change Description
driver.find_element_by_name(Global_Locators.Offering_editdescription_name).clear()
driver.find_element_by_name(Global_Locators.Offering_editdescription_name).send_keys("Test Description")
#Click Done
driver.find_element_by_css_selector(Global_Locators.Offering_editdone_css).click()
time.sleep(10)
def is_element_present(self, how, what):
try: self.driver.find_element(by=how, value=what)
except NoSuchElementException, e: return False
return True
def tearDown(self):
self.assertEqual([], self.verificationErrors)
# Now we will find this offering and delete it!!
class Disk_offering_Delete(unittest.TestCase):
def setUp(self):
self.driver = initialize.getOrCreateWebdriver()
self.verificationErrors = []
def test_diskdelete(self):
driver = self.driver
self.driver.implicitly_wait(200)
#Make sure you are on Dashboard
driver.find_element_by_xpath(Global_Locators.dashboard_xpath).click()
time.sleep(2)
# Go to Service Offerings
driver.find_element_by_xpath(Global_Locators.serviceOfferings_xpath).click()
#Select Disk offering
driver.find_element_by_xpath(Global_Locators.Offering_disk_xpath).click()
## Action part
# We will be searching for our disk offering into the table
linkclass = None
linkclass = driver.find_elements_by_xpath(Global_Locators.Offering_table_xpath) # This returns a list of all Offerings in table
for link in linkclass:
if link.text == "Test Name":
link.click()
time.sleep(2)
# Click Delete
driver.find_element_by_css_selector(Global_Locators.Offering_delete_css).click()
time.sleep(2)
driver.find_element_by_xpath(Global_Locators.yesconfirmation_xapth).click()
time.sleep(20)
def is_element_present(self, how, what):
try: self.driver.find_element(by=how, value=what)
except NoSuchElementException, e: return False
return True
def tearDown(self):
self.assertEqual([], self.verificationErrors)
class Compute_offering_Add(unittest.TestCase):
def setUp(self):
self.driver = initialize.getOrCreateWebdriver()
self.verificationErrors = []
def test_computeadd(self):
driver = self.driver
self.driver.implicitly_wait(200)
#Make sure you are on Dashboard
driver.find_element_by_xpath(Global_Locators.dashboard_xpath).click()
time.sleep(2)
# Go to Service Offerings
driver.find_element_by_xpath(Global_Locators.serviceOfferings_xpath).click()
#Select Compute offering
driver.find_element_by_xpath(Global_Locators.Offering_compute_xpath).click()
## Action part
# Add offering
driver.find_element_by_xpath(Global_Locators.Offering_add_xpath).click()
# Following do not have Global locators
driver.find_element_by_id("label_name").clear()
driver.find_element_by_id("label_name").send_keys("Test Compute Name")
driver.find_element_by_id("label_description").clear()
driver.find_element_by_id("label_description").send_keys("Test Compute Description")
driver.find_element_by_id("label_num_cpu_cores").clear()
driver.find_element_by_id("label_num_cpu_cores").send_keys("2")
driver.find_element_by_id("label_cpu_mhz").clear()
driver.find_element_by_id("label_cpu_mhz").send_keys("2000")
driver.find_element_by_id("label_memory_mb").clear()
driver.find_element_by_id("label_memory_mb").send_keys("2048")
driver.find_element_by_id("label_network_rate").clear()
driver.find_element_by_id("label_network_rate").send_keys("10")
driver.find_element_by_id("label_offer_ha").click()
driver.find_element_by_xpath("//button[@type='button']").click()
time.sleep(2)
#Make sure you are on Dashboard
driver.find_element_by_xpath(Global_Locators.dashboard_xpath).click()
time.sleep(30)
def is_element_present(self, how, what):
try: self.driver.find_element(by=how, value=what)
except NoSuchElementException, e: return False
return True
def tearDown(self):
self.assertEqual([], self.verificationErrors)
class Compute_offering_Edit(unittest.TestCase):
def setUp(self):
self.driver = initialize.getOrCreateWebdriver()
self.verificationErrors = []
def test_computeedit(self):
driver = self.driver
self.driver.implicitly_wait(200)
#Make sure you are on Dashboard
driver.find_element_by_xpath(Global_Locators.dashboard_xpath).click()
time.sleep(2)
## Action part
# Go to Service Offerings
driver.find_element_by_xpath(Global_Locators.serviceOfferings_xpath).click()
#Select Compute offering
driver.find_element_by_xpath(Global_Locators.Offering_compute_xpath).click()
# We will be searching for our disk offering into the table
linkclass = None
linkclass = driver.find_elements_by_xpath(Global_Locators.Offering_table_xpath) # This returns a list of all Offerings in table
for link in linkclass:
if link.text == "Test Compute Name":
link.click()
time.sleep(2)
# Click Edit
driver.find_element_by_css_selector(Global_Locators.Offering_edit_css).click()
#Change name
driver.find_element_by_name(Global_Locators.Offering_editname_name).clear()
driver.find_element_by_name(Global_Locators.Offering_editname_name).send_keys("Test Name")
# Change Description
driver.find_element_by_name(Global_Locators.Offering_editdescription_name).clear()
driver.find_element_by_name(Global_Locators.Offering_editdescription_name).send_keys("Test Description")
#Click Done
driver.find_element_by_css_selector(Global_Locators.Offering_editdone_css).click()
time.sleep(10)
def is_element_present(self, how, what):
try: self.driver.find_element(by=how, value=what)
except NoSuchElementException, e: return False
return True
def tearDown(self):
self.assertEqual([], self.verificationErrors)
class Compute_offering_Delete(unittest.TestCase):
def setUp(self):
self.driver = initialize.getOrCreateWebdriver()
self.verificationErrors = []
def test_computedelete(self):
driver = self.driver
self.driver.implicitly_wait(200)
#Make sure you are on Dashboard
driver.find_element_by_xpath(Global_Locators.dashboard_xpath).click()
time.sleep(2)
# Go to Service Offerings
driver.find_element_by_xpath(Global_Locators.serviceOfferings_xpath).click()
#Select Compute offering
driver.find_element_by_xpath(Global_Locators.Offering_compute_xpath).click()
## Action part
# We will be searching for our disk offering into the table
linkclass = None
linkclass = driver.find_elements_by_xpath(Global_Locators.Offering_table_xpath) # This returns a list of all Offerings in table
for link in linkclass:
if link.text == "Test Name":
link.click()
time.sleep(2)
# Click Delete
driver.find_element_by_css_selector(Global_Locators.Offering_deletecompute_css).click()
driver.find_element_by_xpath(Global_Locators.yesconfirmation_xapth).click()
time.sleep(20)
def is_element_present(self, how, what):
try: self.driver.find_element(by=how, value=what)
except NoSuchElementException, e: return False
return True
def tearDown(self):
self.assertEqual([], self.verificationErrors)

View File

@ -0,0 +1,227 @@
'''
ISO PART YET TO BE ADDED:: remove this after adding it.
'''
import sys, os
sys.path.append(os.path.abspath(os.path.dirname(__file__) + '/'+'../lib'))
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
import initialize
import Global_Locators
class Template_Add(unittest.TestCase):
def setUp(self):
self.driver = initialize.getOrCreateWebdriver()
self.verificationErrors = []
def test_templateadd(self):
driver = self.driver
## Action part
#Make sure you are on Dashboard
driver.find_element_by_xpath(Global_Locators.dashboard_xpath).click()
time.sleep(2)
# Go to Templates
driver.find_element_by_xpath(Global_Locators.templates_xpath).click()
#Select Template from drop down list
driver.find_element_by_xpath(Global_Locators.template_xpath).click()
# Add Template
driver.find_element_by_xpath(Global_Locators.AddTemplate_xpath).click()
# Following have names.. so they do not have their global entries.
driver.find_element_by_id("label_name").clear()
driver.find_element_by_id("label_name").send_keys("Test Template Ubuntu")
driver.find_element_by_id("label_description").clear()
driver.find_element_by_id("label_description").send_keys("Ubuntu 10.04")
driver.find_element_by_id("URL").clear()
driver.find_element_by_id("URL").send_keys("http://nfs1.lab.vmops.com/templates/Ubuntu/Ubuntuu-10-04-64bit-server.vhd")
Select(driver.find_element_by_id("label_os_type")).select_by_visible_text("Ubuntu 10.04 (64-bit)")
driver.find_element_by_id("label_public").click()
driver.find_element_by_id("label_featured").click()
driver.find_element_by_xpath("//button[@type='button']").click()
time.sleep(2)
# Go to Dash Board
driver.find_element_by_xpath(Global_Locators.dashboard_xpath).click()
time.sleep(600)
##Verification will be if this offering shows up into table and we can actually edit it.
def is_element_present(self, how, what):
try: self.driver.find_element(by=how, value=what)
except NoSuchElementException, e: return False
return True
def tearDown(self):
self.assertEqual([], self.verificationErrors)
class Template_Edit(unittest.TestCase):
def setUp(self):
self.driver = initialize.getOrCreateWebdriver()
self.verificationErrors = []
def test_templateedit(self):
driver = self.driver
## Action part
#Make sure you are on Dashboard
driver.find_element_by_xpath(Global_Locators.dashboard_xpath).click()
time.sleep(2)
# Go to Templates
driver.find_element_by_xpath(Global_Locators.templates_xpath).click()
#Select Template from drop down list
driver.find_element_by_xpath(Global_Locators.template_xpath).click()
linkclass = None
linkclass = driver.find_elements_by_xpath(Global_Locators.template_table_xpath) # This returns a list
for link in linkclass:
if link.text == "Test Template Ubuntu": # We will search for our VM in this table
link.click()
time.sleep(2)
# Change name
driver.find_element_by_name("name").clear()
driver.find_element_by_name("name").send_keys("Test template")
# Change Description
driver.find_element_by_name("displaytext").clear()
driver.find_element_by_name("displaytext").send_keys("ubuntu")
driver.find_element_by_css_selector(Global_Locators.template_editdone_css).click()
time.sleep(2)
#Dashboard
driver.find_element_by_xpath(Global_Locators.dashboard_xpath).click()
time.sleep(10)
def is_element_present(self, how, what):
try: self.driver.find_element(by=how, value=what)
except NoSuchElementException, e: return False
return True
def tearDown(self):
self.assertEqual([], self.verificationErrors)
# Now we will find this offering and delete it!!
class Template_Delete(unittest.TestCase):
def setUp(self):
self.driver = initialize.getOrCreateWebdriver()
self.verificationErrors = []
def test_templatedelete(self):
driver = self.driver
## Action part
#Make sure you are on Dashboard
driver.find_element_by_xpath(Global_Locators.dashboard_xpath).click()
time.sleep(2)
# Go to Templates
driver.find_element_by_xpath(Global_Locators.templates_xpath).click()
#Select Template from drop down list
driver.find_element_by_xpath(Global_Locators.template_xpath).click()
linkclass = None
linkclass = driver.find_elements_by_xpath(Global_Locators.template_table_xpath) # This returns a list
for link in linkclass:
if link.text == "Test Template": # We will search for our VM in this table
link.click()
time.sleep(2)
driver.find_element_by_css_selector(Gloabl_Locators.template_delete_css).click()
driver.find_element_by_xpath(Global_Locators.yesconfirmation_xapth).click()
time.sleep(2)
#Dashboard
driver.find_element_by_xpath(Global_Locators.dashboard_xpath).click()
time.sleep(20)
def is_element_present(self, how, what):
try: self.driver.find_element(by=how, value=what)
except NoSuchElementException, e: return False
return True
def tearDown(self):
self.assertEqual([], self.verificationErrors)

View File

@ -0,0 +1,596 @@
import sys, os
sys.path.append(os.path.abspath(os.path.dirname(__file__) + '/'+'../lib'))
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
import initialize
import Global_Locators
class deployVM(unittest.TestCase):
def setUp(self):
self.driver = initialize.getOrCreateWebdriver()
self.verificationErrors = []
def test_deployvm(self):
## Action Part
# VM will be named Auto-VM and this VM will be used in all subsequent tests.
# Deploy an Instance named Auto-VM Default CentOS no GUI Template
driver = self.driver
self.driver.implicitly_wait(30)
driver.refresh() ## Most Important step. Failure to do this will change XPATH location and Scripts will fail.
# Click on Instances link
driver.find_element_by_xpath(Global_Locators.instances_xpath).click()
# Click on add Instance on Instances page
driver.find_element_by_xpath(Global_Locators.add_instance_xpath).click()
# Following select template action will fire automatically... ignore it. And leave following commented.
# driver.find_element_by_xpath("(//input[@name='select-template'])[3]").click()
#Click on Next button on Instances Wizard.
driver.find_element_by_xpath(Global_Locators.add_instance_next_xpath).click()
# Nothing to do here as we will be using all default settings. (Default CentOS no GUI template should be highlighted here. Click Next
driver.find_element_by_xpath(Global_Locators.add_instance_next_xpath).click()
# Nothing to do here. Medium Instance compute offering should be selected here. Click Next
driver.find_element_by_xpath(Global_Locators.add_instance_next_xpath).click()
# Nothing to do here. Data Disk Offering : No Thanks!!. Click Next
driver.find_element_by_xpath(Global_Locators.add_instance_next_xpath).click()
# Since this is our first instance; we must provide a network name. We will use Test-Network as out network name.
driver.find_element_by_xpath("(//input[@name='new-network-name'])[2]").click()
driver.find_element_by_xpath("(//input[@name='new-network-name'])[2]").clear()
driver.find_element_by_xpath("(//input[@name='new-network-name'])[2]").send_keys("Test-Network")
#Click next
driver.find_element_by_xpath(Global_Locators.add_instance_next_xpath).click()
# Give our VM a name here. Use Auto-VM as name
driver.find_element_by_xpath("(//input[@name='displayname'])[2]").click()
driver.find_element_by_xpath("(//input[@name='displayname'])[2]").clear()
driver.find_element_by_xpath("(//input[@name='displayname'])[2]").send_keys("Auto-VM")
# All data filled. Click Launch VM. (It has the same xpath as Next button. So we will use Next Variable here.
driver.find_element_by_xpath(Global_Locators.add_instance_next_xpath).click()
print '\n' + '\n' + "VM Deployment is complete... wait for 5 mins to check deployment status" + '\n' + '\n'
## Verification Part
## Now we must wait for some random time (Educated guess based on experience) and check if VM has been deployed and if it is in running state.
## Should take about 4 min to deploy VM.. but we will wait 5 mins and check the status , we will do this twice. So total 2 check within 10 mins with first check occuring at 5th min.
driver.refresh() # Refresh UI Page; This polls latest status.
# Click on Instances link
driver.find_element_by_xpath(Global_Locators.instances_xpath).click()
linkclass = None
linkclass = driver.find_elements_by_xpath(Global_Locators.instances_table_xpath) # This returns a list of all VM names in tables
count = 1
while (count > 0):
time.sleep(300)
for link in linkclass:
if link.text == "Auto-VM": # We will search for our VM in this table
print "found VM in table .. checking status..." + '\n' + '\n'
link.click()
status = driver.find_element_by_xpath(Global_Locators.state_xpath).text ## get the status of our VM
if status == "Running" :
print "VM is in running state... continuing with other tests."+ '\n' + '\n'
break
else:
print "Need to check one more time after 5 mins"
continue
count = count - 1
def is_element_present(self, how, what):
try: self.driver.find_element(by=how, value=what)
except NoSuchElementException, e: return False
return True
def tearDown(self):
self.assertEqual([], self.verificationErrors)
################################################################################################################################################################################################
class destroyVM(unittest.TestCase):
def setUp(self):
self.driver = initialize.getOrCreateWebdriver()
self.verificationErrors = []
def test_destroyvm(self):
driver = self.driver
self.driver.implicitly_wait(100)
## Action part
# Click on Instances link and find our instance
driver.find_element_by_xpath(Global_Locators.instances_xpath).click()
time.sleep(2)
linkclass = None
linkclass = driver.find_elements_by_xpath(Global_Locators.instances_table_xpath) # This returns a list of all VM names in tables
for link in linkclass:
if link.text == "Auto-VM": # We will search for our VM in this table
link.click()
# Click on Destroy Instance button and confirm
time.sleep(2)
driver.find_element_by_css_selector(Global_Locators.destroyinstance_css).click()
time.sleep(2)
# Click ok on confirmation
driver.find_element_by_xpath(Global_Locators.yesconfirmation_xapth).click()
time.sleep(2)
# Go to Dashboard
# driver.find_element_by_xpath(Global_Locators.dashboard_xpath).click()
driver.refresh()
## Verification part
time.sleep(60)
# Click on Instances link and find our instance
driver.find_element_by_xpath(Global_Locators.instances_xpath).click()
time.sleep(2)
linkclass = None
linkclass = driver.find_elements_by_xpath(Global_Locators.instances_table_xpath) # This returns a list of all VM names in tables
for link in linkclass:
if link.text == "Auto-VM": # We will search for our VM in this table
link.click()
status = driver.find_element_by_xpath(Global_Locators.state_xpath).text ## get the status of our VM
if status == "Destroyed" :
print "VM is Destroyed...."+ '\n' + '\n'
else:
print "Something went wrong"
def is_element_present(self, how, what):
try: self.driver.find_element(by=how, value=what)
except NoSuchElementException, e: return False
return True
def tearDown(self):
self.assertEqual([], self.verificationErrors)
################################################################################################################################################################################################
class rebootVM(unittest.TestCase):
def setUp(self):
self.driver = initialize.getOrCreateWebdriver()
self.verificationErrors = []
def test_rebootvm(self):
driver = self.driver
self.driver.implicitly_wait(30)
print "Verify this test manually for now"
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(vmLifeAndNetwork.Server_Ip, username='root', password='password')
print '\n' + '\n' + "Before Reboot ...Executing command date ... " + '\n' + '\n'
stdin, stdout, stderr = ssh.exec_command('date')
print stdout.readlines()
print '\n' + '\n' + "Before Reboot ...Executing command last reboot | head -1 ..." + '\n' + '\n'
stdin, stdout, stderr = ssh.exec_command('last reboot | head -1')
print '\n' + '\n' + "Before Reboot ...Executing command uptime..." + '\n' + '\n'
stdin, stdout, stderr = ssh.exec_command('uptime')
print stdout.readlines()
ssh.close()
driver.refresh()
driver.find_element_by_xpath(Global_Locators.instances_xpath).click()
linkclass = None
linkclass = driver.find_elements_by_xpath(Global_Locators.instances_table_xpath) # This returns a list of all VM names in tables
count = 1
while (count > 0):
#time.sleep(300)
for link in linkclass:
if link.text == "Auto-VM": # We will search for our VM in this table
print "found VM in table .. Rebooting now..." + '\n' + '\n'
link.click()
driver.find_element_by_css_selector(Global_Locators.rebootinstance_css).click()
driver.find_element_by_xpath(Global_Locators.actionconfirm_xpath).click()
# Sleep for 5 mins to ensure system gets rebooted.
time.sleep(300)
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(vmLifeAndNetwork.Server_Ip, username='root', password='password')
print '\n' + '\n' + "After Reboot ...Executing command date ... " + '\n' + '\n'
stdin, stdout, stderr = ssh.exec_command('date')
print stdout.readlines()
print '\n' + '\n' + "After Reboot ...Executing command last reboot | head -1 ..." + '\n' + '\n'
stdin, stdout, stderr = ssh.exec_command('last reboot | head -1')
print '\n' + '\n' + "After Reboot ...Executing command uptime..." + '\n' + '\n'
stdin, stdout, stderr = ssh.exec_command('uptime')
print stdout.readlines()
ssh.close()
def is_element_present(self, how, what):
try: self.driver.find_element(by=how, value=what)
except NoSuchElementException, e: return False
return True
def tearDown(self):
self.assertEqual([], self.verificationErrors)
#########################################################################################################################################################
class restoreVM(unittest.TestCase):
def setUp(self):
self.driver = initialize.getOrCreateWebdriver()
self.verificationErrors = []
def test_restorevm(self):
driver = self.driver
self.driver.implicitly_wait(100)
## Action part
# Click on Instances link and find our instance
driver.find_element_by_xpath(Global_Locators.instances_xpath).click()
linkclass = None
linkclass = driver.find_elements_by_xpath(Global_Locators.instances_table_xpath) # This returns a list of all VM names in tables
for link in linkclass:
if link.text == "Auto-VM": # We will search for our VM in this table
link.click()
# Click on Destroy Instance button and confirm
driver.find_element_by_css_selector(Global_Locators.restoreinstance_css).click()
# Click ok on confirmation
driver.find_element_by_xpath(Global_Locators.yesconfirmation_xapth).click()
# Go to Dashboard
driver.find_element_by_xpath(Global_Locators.dashboard_xpath).click()
## Verification part
time.sleep(60)
# Click on Instances link and find our instance
driver.find_element_by_xpath(Global_Locators.instances_xpath).click()
linkclass = None
linkclass = driver.find_elements_by_xpath(Global_Locators.instances_table_xpath) # This returns a list of all VM names in tables
for link in linkclass:
if link.text == "Auto-VM": # We will search for our VM in this table
link.click()
status = driver.find_element_by_xpath(Global_Locators.state_xpath).text ## get the status of our VM
if status == "Stopped" :
print "VM is Restored. but in stopped state.. will start now."+ '\n' + '\n'
else:
print "Something went wrong"
#VM will be in stop state so we must start it now
# Click on Instances link and find our instance
driver.find_element_by_xpath(Global_Locators.instances_xpath).click()
linkclass = None
linkclass = driver.find_elements_by_xpath(Global_Locators.instances_table_xpath) # This returns a list of all VM names in tables
for link in linkclass:
if link.text == "Auto-VM": # We will search for our VM in this table
link.click()
# Click on Start Instance.
driver.find_element_by_css_selector(Global_Locators.startinstance_css).click()
time.sleep(2)
# Dismiss confirmation by clicking Yes
driver.find_element_by_xpath(Global_Locators.yesconfirmation_xapth).click()
time.sleep(2)
# Go to Dashboard
driver.find_element_by_xpath(Global_Locators.dashboard_xpath).click()
time.sleep(2)
print "VM is Started."+ '\n' + '\n'
# status = None
time.sleep(60)
# Dismiss the Start Instance information box.
driver.find_element_by_xpath(Global_Locators.actionconfirm_xpath).click()
time.sleep(2)
def is_element_present(self, how, what):
try: self.driver.find_element(by=how, value=what)
except NoSuchElementException, e: return False
return True
def tearDown(self):
self.assertEqual([], self.verificationErrors)
#########################################################################################################################################################
class startVM(unittest.TestCase):
def setUp(self):
self.driver = initialize.getOrCreateWebdriver()
self.verificationErrors = []
def test_startvm(self):
driver = self.driver
self.driver.implicitly_wait(100)
## Action part
#driver.refresh() ## Most Important step. Failure to do this will change XPATH location and Scripts will fail.
# Click on Instances link and find our instance
driver.find_element_by_xpath(Global_Locators.instances_xpath).click()
linkclass = None
linkclass = driver.find_elements_by_xpath(Global_Locators.instances_table_xpath) # This returns a list of all VM names in tables
for link in linkclass:
if link.text == "Auto-VM": # We will search for our VM in this table
print "found VM in table .. checking status..." + '\n' + '\n'
link.click()
# Click on Start Instance.
driver.find_element_by_css_selector(Global_Locators.startinstance_css).click()
time.sleep(2)
# Dismiss confirmation by clicking Yes
driver.find_element_by_xpath(Global_Locators.yesconfirmation_xapth).click()
time.sleep(2)
# Go to Dashboard
#driver.find_element_by_xpath(Global_Locators.dashboard_xpath).click()
driver.refresh()
## Verification part
# status = None
time.sleep(60)
# Dismiss the Start Instance information box.
driver.find_element_by_xpath(Global_Locators.actionconfirm_xpath).click()
time.sleep(2)
# Click on Instances link and find our instance
driver.find_element_by_xpath(Global_Locators.instances_xpath).click()
time.sleep(2)
linkclass = None
linkclass = driver.find_elements_by_xpath(Global_Locators.instances_table_xpath) # This returns a list of all VM names in tables
for link in linkclass:
if link.text == "Auto-VM": # We will search for our VM in this table
link.click()
status = driver.find_element_by_xpath(Global_Locators.state_xpath).text ## get the status of our VM
if status == "Running" :
print "VM is in Running state..."+ '\n' + '\n'
else:
print "Something went wrong"
# Go to Dashboard
driver.refresh()
def is_element_present(self, how, what):
try: self.driver.find_element(by=how, value=what)
except NoSuchElementException, e: return False
return True
def tearDown(self):
self.assertEqual([], self.verificationErrors)
#########################################################################################################################################################
class stopVM(unittest.TestCase):
def setUp(self):
self.driver = initialize.getOrCreateWebdriver()
self.verificationErrors = []
def test_stopvm(self):
driver = self.driver
self.driver.implicitly_wait(100)
## Action part
driver.refresh() ## Important step.
# Click on Instances link and find our instance
driver.find_element_by_xpath(Global_Locators.instances_xpath).click()
linkclass = None
linkclass = driver.find_elements_by_xpath(Global_Locators.instances_table_xpath) # This returns a list of all VM names in tables
for link in linkclass:
if link.text == "Auto-VM": # We will search for our VM in this table
print "found VM in table .. checking status..." + '\n' + '\n'
link.click()
# HWe are on our VM information page.
driver.find_element_by_css_selector(Global_Locators.stopinstance_css).click()
time.sleep(2)
# a Pop up must appear; below we will check the force stop check box and then we will click ok.
driver.find_element_by_id(Global_Locators.stopinstanceforce_id).click()
driver.find_element_by_xpath(Global_Locators.actionconfirm_xpath).click()
time.sleep(2)
# Go to Dahsboard
#driver.find_element_by_xpath(Global_Locators.dashboard_xpath).click()
driver.refresh()
# Should take less than min to stop the instance. We will check twice at interval of 45 seconds o be safe.
## Verification part
time.sleep(60)
# Click on Instances link and find our instance
driver.find_element_by_xpath(Global_Locators.instances_xpath).click()
linkclass = None
linkclass = driver.find_elements_by_xpath(Global_Locators.instances_table_xpath) # This returns a list of all VM names in tables
for link in linkclass:
if link.text == "Auto-VM": # We will search for our VM in this table
link.click()
status = driver.find_element_by_xpath(Global_Locators.state_xpath).text ## get the status of our VM
if status == "Stopped" :
print "VM is in Stopped state...."+ '\n' + '\n'
else:
print "Something went wrong"
def is_element_present(self, how, what):
try: self.driver.find_element(by=how, value=what)
except NoSuchElementException, e: return False
return True
def tearDown(self):
self.assertEqual([], self.verificationErrors)
#########################################################################################################################################################

128
test/selenium/smoke/main.py Normal file
View File

@ -0,0 +1,128 @@
import unittest
import HTMLTestRunner
import xmlrunner
global DRIVER
# Import test cases
##################################
from Login_and_Accounts import *
from Service_Offering import *
from TemplatesAndISO import *
from VM_lifeCycle import *
###################################
# Following are BVT Tests
# serialize the test cases
suite = unittest.TestSuite() # setup new test suite
####################################################################################################
# Following logs admin user in and creates test account then logs admin user out and logs in as test to run tests.
# You should leave this as is for all the tests.
suite.addTest(unittest.makeSuite(login)) #Login Admin
time.sleep(5)
suite.addTest(unittest.makeSuite(createAcc)) # Create an Account test. We will use test account for all our tests
time.sleep(5)
suite.addTest(unittest.makeSuite(logout)) #Logout Admin
time.sleep(5)
suite.addTest(unittest.makeSuite(login_test)) # Login Test
####################################################################################################
time.sleep(5)
suite.addTest(unittest.makeSuite(Disk_offering_Add))
time.sleep(5)
suite.addTest(unittest.makeSuite(Disk_offering_Edit))
time.sleep(5)
suite.addTest(unittest.makeSuite(Disk_offering_Delete))
time.sleep(5)
suite.addTest(unittest.makeSuite(Compute_offering_Add))
time.sleep(5)
suite.addTest(unittest.makeSuite(Compute_offering_Edit))
time.sleep(5)
suite.addTest(unittest.makeSuite(Compute_offering_Delete))
# time.sleep(5)
# suite.addTest(unittest.makeSuite(deployVM))
# time.sleep(5)
# suite.addTest(unittest.makeSuite(stopVM))
# time.sleep(5)
# suite.addTest(unittest.makeSuite(startVM))
# time.sleep(5)
# suite.addTest(unittest.makeSuite(destroyVM))
# time.sleep(5)
# suite.addTest(unittest.makeSuite(restoreVM))
# time.sleep(5)
# suite.addTest(unittest.makeSuite(Template_Add))
# time.sleep(5)
# suite.addTest(unittest.makeSuite(Template_Edit))
# time.sleep(5)
# suite.addTest(unittest.makeSuite(Template_Delete))
####################################################################################################
# Following logs test user out and logs back in as Admin and tears down the test account.
# You should leave this as is for all the tests.
suite.addTest(unittest.makeSuite(logout)) #Logout test
time.sleep(5)
suite.addTest(unittest.makeSuite(login)) #Login Admin
time.sleep(5)
suite.addTest(unittest.makeSuite(tearAcc)) # Delete Account test
####################################################################################################
# If XML reports compatible with junit's XML output are desired then leave folowing code as is.
# If HTML reports are desired follow instructions
#Comment following line for HTML and uncomment for XML
runner = xmlrunner.XMLTestRunner(output='test-reports')
#Comment following line for XML and uncomment for HTML
#runner = HTMLTestRunner.HTMLTestRunner()
#header is required for displaying the website
#Comment following line for XML and uncomment for HTML
#print "Content-Type: text/html\n"
# Leave following as is for either XML or HTML
runner.run(suite)