Upload
vuongkiet
View
220
Download
4
Embed Size (px)
Citation preview
ServiceNow Quality Assurance
Instructions on Using Snow Robot Framework:Robot Framework:Robot Framework Installation Guide:
Installing Python:Installing PIP:Installing Robot Framework:Installing Selenium2LibraryDownloading ChromeDriverRunning Your First Robot-Framework Test:
Robot Framework Custom Library (RFLib)Running Tests from Command Line:
Running all tests at once:Running a single test:Getting Backup from Robot Framework Tests
Robot Framework Custom CommandsREST Framework:How to write Robot Framework Tests:Installing Sublime-Text and other useful plugins for Robot Framework
Installing Syntax Highlighter Plugin:Installing Robot Framework Asset Plugin:
Instructions on Using Snow Testing Framework:Note: All documentations in below are obsolete and we no longer use Snow Testing Framework as the main library. Please referto Robot Framework instructions in the above.
Giving the Snow Testing Framework a valid username/password to used for looging into SNOW:Running Python Scripts:Using functions inside a module in SNOW Framework:Snow Testing Framework:Running a Sample Demo for Creating Tickets:Running a Sample Demo for Updating Tickets:
Automation Tools
SNOW-Robot.zip
SNOW_testing_framework.zip
binding-selenium-with-python.pdf
driver.py
Instructions on Using Snow Robot Framework:
Robot Framework:Robot framework is a framework mainly made in Python that allows us to write test cases in business logic instead of sophisticated, and technicalprogramming languages. One of the greatest advantages of Robot Framework is that once a test case is written in the langages, everyone canread and/or potentially edit the test case documents.
Robot Framework Installation Guide:
Installing Python:
The first step to install Robot Framework is to download and install Python from here: https://www.python.org/downloads/
Note: Make sure to download version 2.7 of the software as version 3.4 is not supported by Robot Framework.
Installing PIP:
PIP is the package manager for python. To install it, go to .http://pip.readthedocs.org/en/latest/installing.html
In the Git repository, a requirements.txt file containing the needed packages has been created under SNOW_Tests. To use it, run:
python -m pip install -r requirements.txt
If you use this method, you can skip the below commands.pip install
Installing Robot Framework:
The easiest way to install Robot Framework is to do it using PIP Python package installer. First run this command in windows command prompt orMac/Linux Terminal:
pip install robotframework
If the above command does not work then what that means is that you probably do not have PIP on your system, and you should install it. Toinstall PIP look at the documentation in here: https://pip.pypa.io/en/latest/installing.html
Once you have installed PIP successfully run the above command again to install Robot Framework
Installing Selenium2Library
Selenium2Library is a library required for Robot Framework to run. You can use pip package installer for binding it to Python using this command:
pip install robotframework-selenium2library
Downloading ChromeDriver
In order to make selenium/robot-framework run Google Chrome you need to download the appropriate ChromeDriver from here: http://chromedriver.storage.googleapis.com/index.html?path=2.10/
After downloading the zip file, extract it, then put the file in the folder where Python is installed (i.e., usually something like: chromedriver.exe C:\P).ython27
Also make sure ChromeDriver is on your PATH.
Running Your First Robot-Framework Test:
Extract the file to your hard-drive. Go to the 'snow_tests' folder and run this command:SNOW-Robot.zip
pybot PriorityMatrixTest.txt
This runs the test cases stored in the 'PriorityMatrixTest.txt' text file. It is used to check whether or not the priority matrix is working when creatinga new incident.
Robot Framework Custom Library (RFLib)Robot Framework Library (RFLib) is the library that we developed and allows us to define new Robot Framework keywords and commands. Inbelow are instructions.
Running Tests from Command Line:
Running all tests at once:
open command prompt from directory and run the following command:SNOW_Tests
python testRunner.py -project: -version: -cycle: -all
Example: python testRunner.py -project: "IT Service Management" -version: "Eureka Upgrade" -cycle: "Core" -all
Running a single test:
similarly, open command prompt from directory and run the following command:SNOW_Tests
python testRunner.py -project: -version: -cycle: -test:
Example: python testRunner.py -project: "IT Service Management" -version: "Eureka Upgrade" -cycle: "Core" -test: "ITSM-103"
Getting Backup from Robot Framework Tests
Since Robot Tests stored on Jira could be modified, or removed by mistake easily we use this back up facility to get regular backups from our RFTests. similarly to the above, open command prompt from directory and run the following command:SNOW_Tests
python backup.py -project: {project name in quotations} -version: {version name in quotations} -cycle: {cycle name in quotations}
Example: python backup.py -project: "IT Service Management" -version: "Eureka Upgrade" -cycle: "Core"
The above commands store all robot tests in a zipped file named BACKUP_Robot_Tests.zip
Robot Framework Custom Commands To view and search for ServiceNow-specific Robot Framework commands please use the web application: Live Search for ServiceNow-specificSelenium Commands
REST Framework:Major parts of automation is done through sending and receving http requests to JIRA and ServiceNow. For convenience we have developed ourown Python framework to communicate with ServiceNow and JIRA (Zephyr). The following UML diagram explains the overall structure of thePython REST framework used in our test scripts.
How to write Robot Framework Tests:Step 1: Create a file to run:
The first step is to create a text file. This file will be the file you use to write your test cases and run them before publishing them on Jira. Create afile and name it "robot.txt". You can also work with the "sampleTestCase.txt file in our Git repository."
Step 2: Working with the Robot Script:
Before we start writing our script, our file needs to contain some headers that tell rebot (Python class that interprets robot scripts) where to readdata from and what libraries to use. To do this, add the following lines at the beginning of you script:
*** Settings ***
Resource resource.txt
Library Selenium2Library
Library ${CURDIR}\\RFLib\\
*** Test Cases ***
# Author:
# Date:
# Description:
#=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also in your file, you can write info about Author, Date, and Description (under "***Test Cases***", although it is not mandatory.
Step 3: Writing the Test Case:
Think of the scenario you want to write and add commands line by line. Normally, since you are testing a web application, the first line should beopening the browser, and logging into servicenow:
Open browser to snow
Log into snow
Now your script looks like this:
*** Settings ***
Resource resource.txt
Library Selenium2Library
Library ${CURDIR}\\RFLib\\
*** Test Cases ***
# Author:
# Date:
# Description:
#=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Open browser to snow
Log into snow
Step 3: Running the Test Script:
Follow these instructions in order to run your script:
- Open Command Prompt (or Terminal in Mac/GNU/Linux) to the directory where your script is located
- Run this command from the Command Prompt:
pybot <script name>
For Example:
pybot sampleTestCase.txt
- And your test case runs!
Step 4: Writing More Advanced Scripts:
It may take some time until you get used to writing Robot Framework test scripts. Probably the best way to get help is to:
- Look in Jira for other test scripts written, and learn from them: https://jira.its.sfu.ca/atl-jira/issues/?jql=labels%20%3D%20automated
- Search our database of Robot Framework commands, for the command that you need: http://cgi.sfu.ca/~snowtest/
Step 5: Putting your test on Jira:
Please note that when you put your test on Jira, you should remove the "*** settings ***" section.
So, for example, your code would look something like this:
*** Test Cases ***
# Author:
# Date:
# Description:
#=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Open browser to snow
Log into snow
Labelling:
It is recommended that Zephyr tests be labeled so that later they can be easily searched for.
automated: Tests that are fully automated
partially-automated: Tests that are partially automated.
automatic: is added to both automated and partially-automated tests so that in future we can find tests that have some automation
Workflow:
Our "testRunner.py" script runs tests based on the following workflow. In summary:
- If a test is partially automated and fails, the result if FAIL
- If a test is partially automated and passes, the result is BLOCK (Because there are still some steps to be done manually by the user)
- If a test is automated and fails, the result if FAIL
- If a test is automated and passes, the result is PASS (As expected)
One last point, defining new commands:
At some point you might feel that the existing commands are not enough, in which case you want to define new commands. To do so, go to the"RFLib" directory and open the"__init__.py" file. Every function in the file is a Robot Framework command that I defined. So for example:
This function:
Def Click_link_with_text_that_matches(self, text)
Can be used by pybot in the same format except that unserscores ("_") are turned into spaces. So the equivalent robot framework commandbecomes:
Click link with text that matches Create new
Now one last question you may have:
How to control the browser using Python?
Answer: Read the python-selenium docs in here: http://selenium-python.readthedocs.org/
Installing Sublime-Text and other useful plugins for Robot FrameworkSublime-Text is a very powerful text editor that has syntax highlighting and intellisence features for many programming languages. It can bedownloaded and installed from here:
http://www.sublimetext.com/ (Don't miss their demo on their homepage as it teaches you how to make the best of some amazing unique featuresthat this powerful editor has)
Installing Syntax Highlighter Plugin:
You can first download and install this plugin that adds syntax highlighting features for Robot Framework:
https://github.com/shellderp/sublime-robot-plugin
Steps to install the plugin:
1) Download the *.zip file from the above link
2) Navigate to the location where you Sublime-Text program is installed/extracted
3) Navigate to ( If the Packages folder does not already exist in there, then you need to create it)\Data\Packages Note:
4) Create a new folder in the Packages directory, and give it an appropriate name (e.g., )Robot Framework File
5) Paste the contents of the *.zip file into the folder you just created
6) Done. If the above steps where done correctly, once you open Sublime-Text, click on the button on the bottom-down corner next to 'Tab Size'and you can set the syntax highlighting mode to ' 'Robot Framework.txt
Installing Robot Framework Asset Plugin:
This plugin adds some features to your Sublime-Text that enable you to run test files without even opeining the cmd/terminal console, and manyother assets. You can add it to your Sublime-Text using the exact same steps as in above but this time with the package that you can downloadfrom here: https://github.com/andriyko/sublime-robot-framework-assistant
Instructions on Using Snow Testing Framework:
Note: All documentations in below are obsolete and we no longer use Snow Testing Framework as themain library. Please refer to Robot Framework instructions in the above.
Giving the Snow Testing Framework a valid username/password to used for looging into SNOW:
Before you run any of the Python scripts, the test scripts need to know a valid username/password that they can use once they login into SNOW.
Open the 'SnowInit.py' file using a text editorChange the value of the 'driverpath' variable to the path of the chrome driver that you downloaded in the previous steps (the pdf fileabove). The driver path can look something like this: " "C:\\Users\\bazizi\\Downloads\\chromedriver_win32(1)\\chromedriver.exe Find the line containing the command: ' ' and replace 'bazizi' with yourbrowser.find_element_by_id("computingId").send_keys('bazizi')own username Find the line containing the command: ' ' andbrowser.find_element_by_id("password").send_keys(snowEncryptor.decryptMessage('', ''))replace ' ' with your own password.snowEncryptor.decryptMessage('', '')Note: You can alternatively use the 'snowEcryptor' module to encrypt/decrypt your username and/or password. This way someone whosees your code will see your username/password in encrypted mode rather than plain text.|
Running Python Scripts:
To run each of the Python scripts you need to use the following command in the Windows/Linux/Mac Command Prompt (CMD):
python SCRIPT_NAME.py
where SCRIPT_NAME is the name of the script you want to run.
Using functions inside a module in SNOW Framework:
In the diagram below you can see different modules used in the SNOW framework. You can use any of the functions available in any of themodules by first importing that module into your own Python script. For example: if you want to use the 'check_exists_by_id() function inside the'snowUtilities' module you can write this line of code at the top of your python script:
import snowUtilities
The above statement imports snowUtilities into your own python script and from now on you can use all functions that exist inside this module
using the following format. For example to run the ' ' function inside that module you can do it this way:check_exits_by_id()
snowUtilities.check_exists_by_id(browser, "loginButton")
Snow Testing Framework:
For more information on functions, and methods available in the SNOW Testing Framework you can refer to the diagram below:
Running a Sample Demo for Creating Tickets:
After you do the steps in the above you can start running your first test.
First open the file ' '. Each line in the CSV file contains information for each of the tickets that you want tocreate_ticket_test_cases.csvcreate. The first line is the header and all test cases are added under the header, and there are three different test cases (one test caseper line) there already added.Now open the console/cmd and run the following command:python createTicket.pyThe above command should run the createTicket.py script. This script reads the test cases you put in 'create_ticket_test_cases.csv' filesand creates tickets on SNOW based on the test cases that you provided in the file.
Running a Sample Demo for Updating Tickets:
There are two options when updating existing tickets . You can either read data from a CSV file, or use a SNOW filter to extractSNOW-Robot.zipticket numbers for you and update them
First open the file ' '. Each line in the CSV file contains information for each of the tickets that you want toupdate_ticket_test_cases.csvcreate. The first line is the header and all test cases are added under the header, and there are three different test cases (one test caseper line) there already added. The items under the first column are ticket numbers to be updated, and should be tickets actually existingin SNOW.Now open the ' script in a text editor and look for these two line:'updateTicket.py
#linesArr = snowUtilities.CSV_in_array("update_ticket_test_cases.csv")linesArr = snowUtilities.existing_tickets_in_array(browser, "https://sfutraining.service-now.com/incident_list.do?sysparm_query=active%3
");Dtrue%5Ecaller_id!%3D76239f4b875a78006fa670406d434d39&sysparm_view= The first and the second lines are actually the two options when updating existing tickets (either reading from a csv or using a filterrespectively) As you can see, by default the first line is commented out which means that by default it is using a filter (i.e., find all ticketswhose caller is not 'behnam azizi'!)Now open the console/cmd and run the following command:python updateTicket.pyThe above command should run the script.createTicket.py
Automation Tools
Selenium using Python iMacros
Uses Python Uses its own specific programming language
Can be used for Chrome, Firefox, and IE Mainly to be used by IE. Can by used for Chrome as well, but haslimited functionality.
Can be used to read and parse HTML content of the web-page usingHTTP request
Can extract data from elements on a webpage even if the text is hidden
Can handle alerts, pop-ups, and prompts Can handle pop-up errors and pass the error information back to thecalling program
free >$495.00
Utilizes HTML DOM Utilizes HTML DOM
Good online documentations Good online documentations
Only web applications Only web applications
Only Python Compatible mainly with VBScript, JScript
Can run tests in parallel Can run tests in parallel
Sikuli iMacros
Uses Python Uses its own specific programming language
free >$495.00
Utilizes image recognition Utilizes HTML DOM
Good online documentations Good online documentations
Any type of application, Operating System, and browser (e.g., Android version ofServiceNow after Dublin release)
Only web applications
Uses only Python as its main scripting language Compatible mainly with VBScript, but also manymore languages
Runs tests sequentially Can run tests in parallel
Name Advantages Disadvantages Description Price Integration Features
iMacros - Can be used by almost any user withoutscripting background
- Excellent online documentation and resourcesavailable
- It supports multiple browsers including GoogleChrome, IE and FF
- VBScript examples and documentationavailable on their website
- We can run VBScripts that automate the testingprocess
-Supports image recognition
- iMacro files (.iim) can be intitiated to run fromVBScript, javascript or python. VBS can bescheduled through MS scheduler.
- Language used insidethe software is specific toitself
- The fact that the ID ofsome elements in thewebpage change aftereach page load makesiMacros not useful in somecases
Can be downloaded andinstalled as a separatesoftware that has a built-inbrowser (Chrome, IE,FireFox)
30-day Trial version:Free
Standard Edition: US$495.00 per license
Enterprise Edition:
US $995.00 per licence
-Visual Basic integration. We mybe able to write VBScripts thatautomate integration with Zephyr, although iMacros doesnot have these features on itself.
-Zephyr supports REST (HTTPprotocols) to insert, update,modify and delete information.
- iMacros encapsulates thebrowser to detect and capturewhat the user is doing and ascript is then generated.
Sikuli - Automates anything you see on the screen ofyour desktop computer running Windows, Macor some Linux/Unix using image recognition
- Scripting languages like Java and Python aresupported
- The fact that it uses image recognition makes itusable for almost any type of application (evennon-web application). For example: when theDublin release comes out we can use Sikuli totest Android version of ServiceNow
- It can be used by anyone without scripting andprogramming knowledge
- There is good online documentations andtutorials on how to use the software
- Uses image recognitionrather than HTML DOM forrecording tests
An automation tool thatrecords every action thatyou do on your computerscreen and uses imagerecognition to simulatethem
Free No specific integration features
Selenium Since it is mostly done through scripting itcan make use of programming featuressuch as loops, conditions etc.Test files are saved in *.xml format and areportableIt is open-source and freeMany good documentations availableonline for using Selenium with PythonCan make use of robot-framework to writein business logic rather than programminglanguages
RequiresprogrammingknowledgeSince it is mostlydone throughprogramming, it mytake more time towrite test scenarios
Mainly a plugin for firefox,can also be used for webautomation usinglanguages such as Java,Javascript.
Free N/A
Sahi - Supports almost all browsers including:FireFox, Chrome, and IE
- Ability to record user actions as Java/Rubycommands
- Has SSL issues inChrome and did not allowme to connect toservicenow through https
- Did not work properly inChrome. I could not submita ticket using automation
- User interface isconfusing
1 year license for$495.00 CAD
- Integrates with Selenium Driver(according to their website)
Helium - Similar to Selenium
- mostly done through scripting it can make useof programming features such as loops,conditions etc.
- Does not seem to haverecording feature to recordbrowser action and everyautomation has to be donethrough scripting only
Like Selenium makes useof programming languagessuch as Java, and python
1-year License: License for 1 year for oneuser Free updates andmaintenance $99 perlicense
Perpetual License: Perpetual license for oneuser Free updates andmaintenance includedonly $219 per license