http://www.cnblogs.com/puresoul/p/3483055.html
http://www.360doc.com/content/14/0913/10/13497042_409107000.shtml
Summary
This manual will help you to set up the automation test environment for Selenium.
I will also introduce the automation test framework of Selenium used in Morningstar.
The related tools introduction
First, i'd like to show you all the tools which we'll use during the automation test work. We just need to have a brief understand about them in the beginning. No need to spend too much time on this table. After we participate in a specific project, we will get to know all the tools in detail.
Don't worry about the huge list. Leaving an impression is enough.
No
|
Software
|
Software Category
|
Description
|
Official Download Address
|
---|---|---|---|---|
1 | Selenium | Automation Test Tool | Selenium is used to do automation test for Web product,which can simulate real user to operate in browser. | http://docs.seleniumhq.org/ |
2 | Spring Tool Suite |
IDE (Integrated Development Environment) |
Spring Tool Suite is an Eclipse-based development environment,which is used for us to develop,debug and run java code. Spring Tool Suite has included maven . |
http://spring.io/tools/sts |
3 | Maven | Software Project Management Tool | Maven is used to control code dependencies. | http://maven.apache.org/download.cgi |
4 | JDK | Java Development Kit |
JDK includes all the class libraries to develop java code and run java applications. JDK has included JRE. |
http://www.oracle.com/technetwork/java/javase/downloads/index.html |
5 | JRE | Java Run-time Environment | JRE is used to run java applications | http://java.com/en/download/windows_xpi.jsp?locale=en |
6 | GitExtension | Version Control Tool |
Git Extensions is a toolkit to make us working with Git under Windows more intuitive. The shell extension will integrate in Windows Explorer and presents a nice context menu on files. Git Extensions has included Git. |
http://gitextensions.codeplex.com/ |
7 | Git | Version Control System | Git is used to manage code,we can upload,update and download code from server by Git in Command Line Mode. | http://code.google.com/p/msysgit/downloads/list |
8 | TortoiseGit | Version Control Tool | TortoiseGit can make the version control more convenience, which will mark every file by icon to tell us it's new added, modified or deleted. | |
9 | Grid | Concurrency Test Model | Grid is a system with one Hub and multiple Nodes which can help us to run multiple test cases in the meantime. | |
10 | Jenkins | CI Tool(Continuous Integration Tool) | Jenkins is used to manage the auto-run of automation test cases. | http://jenkins-ci.org/ |
11 | iReport | Test Report Designer | iReport is used to design automation test report. | http://sourceforge.jp/projects/sfnet_ireport/releases/ |
The installation package we should prepare and install
If you want to set up the Selenium automation test environment in your own computer. You can copy all the needed installation packages from my personal computer, i have shared them to everyone: \szpc2081ToolsSelenium Autotest Softwares
Below tools are enough for us to set up the local automation test environment. Please install them according to the manual below, which will guide you step by step.
1.Install JDK
Step 1: Double click , you will find the following dialogue, then click "Next" Button.
Step 2:Remain the default configuration, then click “Next”, you will see the progress bar.
Step 3:Change the install path if you like, click "Next", you will see the progress bar.
Step 4:Finish installing JDK, click "Close" button.
Step 5:Set environment variables for JDK.
All the environment variables we need to add includes:
JAVA_HOME=C:Program FilesJavajdk1.7.0_45
CLASSPATH=.;%JAVA_HOME%lib
Path=%JAVA_HOME%in
Please follow the below steps to set environment variables :
Step 5-1:Right Click "Computer" icon, select "Properties".
Step 5-2:Click "Advanced system settings"
It will pop up a window named "System Properties".
Step 5-3:Click "Environment Variables"
It will pop up a window named "Environment Variables".
Step 5-4:If you want to add a variable, click "New..." button.
It will pop up a window named "New System Variable".
In " New System Variable " popup window , input " Variable name " and " Variable value " as follows, and then click "OK" button.
JAVA_HOME=C:Program FilesJavajdk1.7.0_45 (Change the path to the actual path in your own computer)
CLASSPATH=.;%JAVA_HOME%lib
Path=%JAVA_HOME%in
Step 5-5: If the variable you want to add had already existed , just select the Variable and click "Edit..." button.
It will pop up a window named "Edit System Variable".
In "Edit System Variable" popup window, input " Variable name " and " Variable value " as follows, and then click "OK" button.
Path=%JAVA_HOME%in;
(Because every computer already had an environment variable named Path, just Edit it, add %JAVA_HOME%in; in the beginning of Variable value, ; is necessary, it's a delimiter between two paths.)
Step 6(Optional): Check if JDK installed sucessfully.
Step 6-1:In the start menu, type "cmd" and press Enter on keyboard.
The cmd window will appear.
Step 6-2:Type "java -version" in the cmd windows and press Enter, if JDK has been installed successfully on your computer, you can see the JAVA version information, here is "1.7.0_45".
2.Install GitExtensions(GitExtensions include Git)
Step 1:Double click ,You will find the following dialogue,then click "Run" Button.
Step 2: Then click “Next”.
Step 3: Choose “Install for all users of this machine”, then click “Next”.
Step 4: Choose “Install MsysGit” and “Install KDiff”, then click “Next”.
Step 5: You can choose the path to install GitExtensions,and then click "Next" button.
Step 6: Remain the default configuration. Then click “Next”.
Step 7: Choose “OpenSSH”, then click “Next”.
Step 8: Now we begin to install GitExtensions,click "Install” button,you will see the progress bar.
Step 9: Then install KDiff3.
Step 10: Remain the default configuration. Then click “Next”.
Step 11: You can choose the path to install KDiff3.
Step 12: Choose “Install for all users”, then click “Next”.
Step 13: Change a folder to create shortcuts if you like,then click "Install" button.
Step 14:Finish install GitExtension,click "Finish" button.
Step 15:Start to install Git.Click "Next" button.
Step 16:Then click “Next”.
Step 17:Remain the default configuration. Then click “Next”.
Step 18:Choose “Use Git Bash only”, then click “Next”.
Step 19:Remain the default configuration,then click “Next”.
Step 20:Click "Next" button,it will pop up a warning window,Click "OK" button.
Step 21:Open "Start Task Manager",Select "explorer.exe",click "End Process" by right menu to kill explorer.exe.You will can not see the icon on desktop.
Step 22:Click "Refresh" button,and then click "Next" button again,installation will continiue,you will see the progress bar.
Step 23:Finish install Git,click Finish button.
Step 24:Restart explorer.exe,you will see the icons on your desktop.
- Press CTRL+ALT+DEL,and then select "Windows Task Manager", window named "Windows Task Manager" will be opened.
- In "Windows Task Manager",select File->New task(Run...),window named "Create New Task" will be opened.
- Input explorer.exe,and click "OK" button,you will find the icons come back on your desktop.
Step 25(Optional): Check if GitExtension and Git installed sucessfully.
- Right click in a blank place,you will see the menu like this:
3.Install Spring Tool Suite
Step 1:double click to start installation.
if you haven't installed JDK firstly,it will infrom you that "This application requires a Java Runtime Environment 1.6.0", JDK involve JRE. Pleaseinstall JDK instead.
If you had already installed JDK in the first,it will pop up this window,click "Next" button.
Step 2:Select "I accept the terms of this license agreement.",and then click "Next" button.
Step 3:Select the installation path if you like,and then click "Next" button.
Step 4:It will mention you that "The target directory will be created",Click "OK" Button.
Step 5:Remain the default configuration and then click "Next" button.
Step 6:Select the JDK path,and then click "Next" button,you will see the progress bar.
Step 7:When installtion progress "Finished",click "Next" button.
Step 8:Remain the default configuration,click "Next" button.
Step 9:Finish installtion of Spring Tool Suite,click "Finish" button.
4.Create a workspace in Spring Tool Suite
Step 1:Double click to run Spring Tool Suite.
Step 2:Create a folder on you computer (Here,i created a folder named "spring_workspace"),and select it as workspace,and then click "OK" button.You will see the progress of "Loading Workbench".
Step 3:Finish creating workspace.Close the Welcome page,you will see the work page,and also you can check the files under the folder you created.
Preconditon:
1.The code you want to download has already been uploaded to Stash by somebody , and you know the web address of code.
Web address for PA test code: https://msstash.morningstar.com/projects/AUTO/repos/automation_test_do_pa/browse
Web address for RP test code: https://msstash.morningstar.com/projects/AUTO/repos/automation_test_do_rp/browse
2.You need request rights to login Stash.This need yourself to submit a ticket in mshelpdesk
mshelpdesk address: http://mshelpdesk.morningstar.com/hsPages/CRMHome.aspx?InitLaunch=0
When you request rights to Stash in the Helpdesk, comment to add you in these three groups:
Step 1:In the workspace folder,right click in a blank space,select "GitEx Clone".
Step 2:Input clone address in "Repository to clone":
Clone address for PA automation test: https://UserName@msstash.morningstar.com/scm/auto/automation_test_do_pa.git
Clone address for RP automation test: https://UserName@msstash.morningstar.com/scm/auto/automation_test_do_rp.git
Comment: UserName should be replaced with your own user name, it's the same with your computer's login account. For example, mine isjzhang6.
You can also obtain the clone address following the screenshot if you know the web address of code.
Click "Clone" button,you will see the download progress.
Step 3:Finish download code,wait until the progress 100%,the window will close by itself.You can check the workspace folder,a new folder named "automation_test_pa" is created.
6.Install TestNG in Spring Tool Suite
Step 1:Open Help->Eclipse Marketplace... in Spring-Tool-Suite.It will pop up a window named "Eclipse Marketplace".
Step 2:Input "testng" in Find TextBox to search TestNG,you will see "TestNG for Eclipse".Click "Install" button.
Step 3:Click "Next" button.
Step 4:Select "I accept the terms of the license agreement", Click "Finish" button.
Step 5:Wait For a long time.
Step 6:Click Yes,Spring Tool Suite will restart.
7.Deploy maven in Spring Tool Suite
Step 1:Open Window->Preferences in Spring-Tool-Suite.
Step 2:Click the "Browse..." button to select the setting.xml in maven.
Step 3:Maven is in the folder where you install Spring-Tool-Suite.Click "Open" button.
Step 4:Then you will find the url has changed and then click "OK" button.
8.Import a maven project in Spring Tool Suite
Step 1:Open File->Import...
Step 2:Select "Existing Maven Projects",and then click "Next >" button.
Step 3:Click "Browse..." button to select the maven project you want to import.You will see the "Select Root Folder".
Step 4:Select "automaton_test_do_pa" under your spring workspace,and then click "OK" button.You will see the progress bar.
Step 5:Remain the configuration,click "Finish" button.
If it's the first time you import a selenium project, after you click "Finish" button, the maven project will automatically download dependent JARs to your local computer.
The download process will take a long time. Please be patient to wait.
The JARs will be downloaded to this directory automatically : C:Usersjzhang6.m2 epository
You can also see the JARs in the Project's Maven Dependencies in Spring Tool Suite.
Someone may wonder where is Selenium. Actually Selenium just provides some JARs to us, you can find them in the Maven Dependencies.
Step 6:(Opetional)If import project failed,try to do the following operation.
After the download process finished , if error with red cross appears in the code, it means some JARs may download failed.
We need to delete the project in Spring Tool Suite and delete all the files in this folder : C:Usersjzhang6.m2 epository
And then import the project to Spring Tool Suite again.
Or, you can also operate as below:
1.Click Window->Show View->Other...
2.Select Maven Repositories and click "OK" button.
3.Select "Golbal Repositories->central(http://repo.maven.apache.org/maven2)[updating]" and then click "Rebuild Index"
9.Maven install project
Before maven install the project, firstly change environment.xml as below:
Change mode="debug" , useGrid="false"
Why do this, i will explain it in another section.
Now, let's start to maven install the project to perform the test.
Step 1:Find out pom.xml in the project,select it and right click the mouse,and then click Run as->Maven install, testing will start.
The testing will take a long time, because all the test cases will be tested. If you want to suspend it , close Spring Tool Suite and kill all the browser processes and java process in Windows Task Manager : java.exe, firefox.exe, ie.exe, chrome.exe and etc.
Step 2:(Opetional)If maven install project failed,try to do the following operation.
1.Click Window->Show View->Other...
2.Select Maven Repositories and click "OK" button.
3.Select "Golbal Repositories->central(http://repo.maven.apache.org/maven2)[updating]" and then click "Rebuild Index"
10.Run mode introduction
There are several modes to run test cases.
You can let test case run on your local computer or remote computer.
And also you can let multiple test cases run on multiple remote computers at the same time, we call it concurrency test. And we also call it run inGrid mode.
Mode 1 : Run test case on local computer.
When we are developing a new test case, we always need to run the code on local computer.
Mode 2 : Run test suite on remote computers
Test suite may includes one or multiple test cases.
Hub can be put on Local Computer or Remote Computer, or other computers, no matter where is it.
Nodes on Remote Computers will point which computer is Hub by IP address.
Selenium will configure which computer is Hub in environment.xml
How to control the Run mode?
We can control the Run mode by environment.xml
(File Path: Automation_Test_PA_Smokesrc est esourcesconfigenvironment.xml)
mode="" useGrid="true" : Run on remote computers , Hub is CIHub configured in environment.xml
mode="debug" useGrid="false" : Run on local computers
mode="debug" useGrid="true" : Run on remote computers , Hub is debugHub configured in environment.xml
11.Debug test case on local computer in non-Grid mode
Step 1: Config environment.xml to let test case run on local computer with no concurrency
File Path: Automation_Test_PA_Smokesrc est esourcesconfigenvironment.xml
Change mode="debug" useGrid="false"
Step 2: Debug one test case
If you want to debug one test case, you can find it out in the "Outline" view, and right click it and debug it by TestNG.
Or just move the mouse to the test case's class name in code , right click it and debug by TestNG.
12.Run test suite on remote computer in Grid mode
If you want to run a test suite with multiple test cases, you can run it on remote computer in Grid mode.
Test cases in the test suite will run concurrently on multiple computers which are being used as nodes.
Step 1:Change environment configuration "environment.xml". Let it run in grid mode.
Change mode="" useGrid="true"
Step 2: Select smokeTest.xml, right click it and select Run As->TestNG Suite
The test cases configured in smokeTest.xml will run on remote computers in concurrency mode.
13.About Grid,Hub,Node,BrowserDriver
Why we need Grid?
When we want to improve the speed of automation test, we hope the test cases can run on multiple computers at the same time, we call it "concurrent execution", so we need Grid.
What is Grid?
In Grid mode, there is one Hub and multiple Nodes.
Hub run on a single computer, each Node run on a single computer.
Each Node points to the Hub by the hostname and port of the Hub.
How to set up the Grid environment?
To set up the Grid environment, we only need to copy several files to the computers which are used as Hub and Node.
Config the hub infomation and file path in Allnodes.bat, and then run Hub.bat on Hub, run Allnodes.bat on Nodes.
You can find the files in the code to set up Grid environment: /src/test/resources/driver
About Hub.bat and Allnodes.bat
Copy the folder driver to C:/ , change the folder name to WebDriver
About Hub.bat , no need to change anything
About AllNodes.bat
If you want to build the Hub and Node environment on you local computer or other computers, you must modify the configuration in Allnodes.bat.
Both the HUD_NAME and DRIVER_PATH in Allnodes.bat need to be modified according to the actual condition.
What is Browserdriver?
Webdriver is provided by browser company, if we want to operate Browser by software program, we need Browser Webdriver to driver it.
The Webdriver for Firefox has been integrated to Browser , so we can not see Firefox Webdriver in the folder.
Only Webdriver for Chrome and IE have been included in.
Grid we are using
Let's see the Grid Console which we are using. Copy "http://szmercurytest1:4444/grid/console#" to Browser and open it.
There are 7 Nodes under the Hub "SZMERCURYTEST1".
Each Node has 4 kinds of WebDrivers, includes :Safari, Chrome, Firefox, IE
When the browser has been used to run test case, the icon of it will become gray.
More information about Grid we are using , please refer to : Automation Test Operation Memo
14.Introduction of automation test projects
1: Introduce project "Automation_Test_PA".
com.morningstar.mercury.ct.base.cons: Manage the constant in our project, such as the scene's name, email addresses where the reports are sent to.
com.morningstar.mercury.ct.base.listener: Manage some kinds of listener. For example, the project will wait for the automation testing until it has finished then send a report to us.
com.morningstar.mercury.ct.flows: Implementation for each check point. Don't put any asserts here.
com.morningstar.mercury.ct.pages: Manage the elements of pages.
com.morningstar.mercury.ct.tests: Manage all test cases. You can put all asserts here.
CISuite: Allocate test cases of the same category in a suite. Now it includes regression testing, core regression testing and smoke testing. It's used in Jenkins. It runs multithreading.
config: Manage the configuration, such as the accounts when we log in and url where we run the script.
driver: Manage the driver for browser and the script for hub.
reports: It's the demo of the reports.
suiteXmlFile: The same with the CISuite, but it's used in local machine. It runs single thread.
testData: Manage some test data for input in the test cases.
2:Introduce project "AutomationBase"
com.morningstar.mercury.automation.base.cons: Manage the constant for all projects, such as the hub's url, browser's type and browser driver's path.
com.morningstar.mercury.automation.base.core: Manage the common abstract classes for all projects to extend.
com.morningstar.mercury.automation.base.core.beans: Manage all the core classes for the automation, such as generating reports, sending reports, managing users and so on.
com.morningstar.mercury.automation.base.core.configurations: Manage the core configuration and get the data.
com.morningstar.mercury.automation.base.core.filedownload: Manage the test strategy about file download,only check the reponse message of HTTP request,not really download.
com.morningstar.mercury.automation.base.core.listener: Manage all kinds of listener for all projects. For example, listen to the action of test's skipping, success and failure..
com.morningstar.mercury.automation.base.core.report: Manage all kinds of functions for report, such as back up the reports, generating the report as PDF type.
com.morningstar.mercury.automation.base.core.testdata: Manage all kinds of functions for using test data.
com.morningstar.mercury.automation.base.core.users: Manage all kinds of functions for users.
com.morningstar.mercury.automation.base.core.utils: Manage all kinds of useful tools for all projects, such as SeleniumUtil, HttpUtil, FtpUtil, etc.
15.Configure Jenkins
Request Jenkins right
Direct/Office automation test run environment :https://jenkins.morningstar.com/job/DO/
If you have no Jenkins right of DO Automation, please contact Sandy Liu or Jenny Zhang to give you the right
If you already have the Jenkins right
Open "Automation_Selenium_PA_Smoke" in DO Automation, then click "Configure".
Or directly open https://jenkins.morningstar.com/job/DO/job/Automation_Selenium_PA_Smoke/configure
1. Change the Days to keep builds and Max # of builds to keep
2.Configure the run Environment (eg: QA, TP, Live) and Browser (eg : Firefox, Chrome, IE)
The choices should be consistent with environment.xml in the code.
3.Configure JDK version and Restrict where this project can be run
4.Configure Repository URL in Git and Branches to build
The Repositories should be filled out with the code's Clone Address in Stash.
5.Set the time to run test
If you don't know how to fill out the schedule, you can put the mouse on the ? icon.
6.Set the environment before and after build
7.Configure Maven Version, Root POM, Goals and options for build
It's important to choose the pom.xml in your project.
In Goals and options, it is the command to run the testing.
${Browser} and ${Environment} means they are variables and will get value from Browser and Environment's choice.
The script means Jenkins task will run test suite configured in smokeTest.xml
And it will first execute maven clean, and then execute maven install
8.Configure Post steps and E-mail notification
16.New task in Jenkins
Click the "New Job", then enter Job name as "RP_Automation",select "Copy existing Job" ,enter copy from "PA_Automation".
Modify Root POM as "Automation_Test_RP/pom.xml",and configure Goals and options.Change E-mail Recipients and click "Save".
You can see the Project "RP_Automation" is created successfully.
17.Run test suite by Jenkins
URL of Direct/Office automation test run environment : https://dojenkins81/view/DO%20Automation/
The test suite will run automatically by Jenkins as the time you set in Jenkins.
If you want to run the task manually right now,just click "Build Now" on the left.
And you can also click the icon "Schedule a Build" on the right to run it manually.The round icon on the left will twinkle.
Or you can place mouse on Project Name "RP_Automation" and click "Build Now" in the menu.The round icon on the left will twinkle.
Here,you can see the running progress.
18.The process of generate report
19.Update code by Git
tep 1:Update code if your code is not the newest.Right click in a blank space and select Git Extensions->Pull
Step 2:Click "Pull" button.
Step 3:Update code successfully.Click "OK" button.
Q & A
Q1: Where is Selenium?
Selenium is several .jar packets used as functional APIs in our projects. Your can see them in the Project's folder : "Maven Dependencies".
All of them will be downloaded to : C:Usersjzhang6.m2 epository when you import a maven project.
Q4: When running test case in Firefox, Firefox can be opened but displays white board, error message is "driver is null"
Current Selenium version may not support the Firefox version in your computer, if your Firefox always update automatically, the version may be too new to Selenium.
Please uninstall the New Firefox Version and install the old Firefox 31.0 version.
Your can get the installation package from Jenny Zhang's computer: \szpc2081ToolsFirefox Setup 31.0.exe
After you install it and open it the first time, it's very important to prevent the automatic update before you check the Firefox Version
(If you check the Firefox version firstly, it will update soon, so don't check the version before you prevent the automatic update.)
To prevent automatic update, Click in the top right, select "Options"->"Advanced"->"Update", setup is shown below.