From 48540dcf5621d0cd7a925e8da299a3ef2d7d0c31 Mon Sep 17 00:00:00 2001 From: Parth Jagirdar Date: Wed, 1 May 2013 10:44:26 -0700 Subject: [PATCH] CLOUDSTACK-2282: Selenium Headless configuration using PhantomJS. Description: Putting in selenium_headless support. Command Line parameter added for management server ip. --- test/selenium/ReadMe.txt | 36 ++++++++++++++++------- test/selenium/lib/initialize.py | 17 ++++++++++- test/selenium/smoke/Login_and_Accounts.py | 5 ++-- test/selenium/smoke/main.py | 2 +- 4 files changed, 45 insertions(+), 15 deletions(-) diff --git a/test/selenium/ReadMe.txt b/test/selenium/ReadMe.txt index 30b0e0df7a0..bc968f1dc93 100644 --- a/test/selenium/ReadMe.txt +++ b/test/selenium/ReadMe.txt @@ -1,31 +1,41 @@ ############################################## + +Questions? Post'em @ dev@cloudstack.apache.org + +############################################## + This files contains following: 1) Installation requirements -2) Test Pre requisites -3) Running the Test and Generating the report +2) Testing pre-requisites +3) Running the Tests and Generating the report ############################################## ########################################################################################################################################## -1) Installtion Requirements +1) Installation Requirements +--------------------------- -1)Firefox depending on your OS (Good to have Firebug and Selenium IDE for troubleshooting and dev work) +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 +2) Install Python 2.7. 3) Now Open CMD/Terminal and type all of following -- pypm install pycrypto (Installs Pycrypto) -- pypm install paramiko (Install paramiko) +- pip install pycrypto (Installs Pycrypto) +- pip install paramiko (Install paramiko) - pip install unittest-xml-reporting (Install XML Test Runner) - pip install -U selenium (Installs Selenium) +4) Get PhoantomJS for your OS from http://phantomjs.org/ + +- PhantomJS will run selenium test in headless mode. Follow the instruction on PhantomJS.org. +- Make sure the executable is in PATH. (TIP: Drop it in Python27 folder :-)) 5) Now get the HTMLTestRunner for nice looking report generation. - http://tungwaiyip.info/software/HTMLTestRunner.html @@ -35,18 +45,22 @@ This files contains following: ########################################################################################################################################## 2) Test Prerequisites +--------------------- + +- Download and install CS. /cwiki.apache.org has links to Installation Guide and API reference. +- Log into the management server and Add a Zone. (Must be Advance Zone and Hypervisor type must be Xen) -- 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. +- Typical usage is: python main.py 10.1.1.10 >> result.xml for XML Reporting +- And python main.py 10.1.1.10 >> result.html for HTML Reporting. +- 10.1.1.10 (your management server IP) is an argument required for main. ########################################################################################################################################## diff --git a/test/selenium/lib/initialize.py b/test/selenium/lib/initialize.py index e8cc49adff4..55e5d9aa3b1 100644 --- a/test/selenium/lib/initialize.py +++ b/test/selenium/lib/initialize.py @@ -21,11 +21,26 @@ This will help pass webdriver (Browser instance) across our test cases. from selenium import webdriver +import sys DRIVER = None +MS_ip = None + def getOrCreateWebdriver(): global DRIVER - DRIVER = DRIVER or webdriver.Firefox() + DRIVER = DRIVER or webdriver.PhantomJS('phantomjs') # phantomjs executable must be in PATH. return DRIVER + +def getMSip(): + global MS_ip + if len(sys.argv) >= 3: + sys.exit("Only One argument is required .. Enter your Management Server IP") + + if len(sys.argv) == 1: + sys.exit("Atleast One argument is required .. Enter your Management Server IP") + + for arg in sys.argv[1:]: + MS_ip = arg + return MS_ip \ No newline at end of file diff --git a/test/selenium/smoke/Login_and_Accounts.py b/test/selenium/smoke/Login_and_Accounts.py index c5132d9754c..44b1e836b4c 100644 --- a/test/selenium/smoke/Login_and_Accounts.py +++ b/test/selenium/smoke/Login_and_Accounts.py @@ -34,11 +34,12 @@ class login(unittest.TestCase): def setUp(self): + MS_URL = initialize.getMSip() self.driver = initialize.getOrCreateWebdriver() - self.base_url = "http://10.223.49.206:8080/" # Your management Server IP goes here + self.base_url = "http://"+ MS_URL +":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. diff --git a/test/selenium/smoke/main.py b/test/selenium/smoke/main.py index 86bb9308c2f..921192dc847 100644 --- a/test/selenium/smoke/main.py +++ b/test/selenium/smoke/main.py @@ -21,7 +21,7 @@ import xmlrunner global DRIVER - +global MS_ip # Import test cases