- Author: Tyler Lee
- Version: 1.0
- copy the template java file (
TestExample.java) and write Selenium tests as desired using TestNG for assertions- common functions for Selenium (web navigation)
driver.get("<URL>"); // navigates to desired url driver.findElement(By.className("button")).click(); // clicks on the warning button driver.findElement(By.id("username")).sendKeys("example-user"); // finds login text box and types "example-user" WebElement myInput = driver.findElement(By.cssSelector("input")); // finds an element based on its CSS selector and copies a reference to a local variable for future interaction with this element
- common functions for TestNG (testing assertions)
Assert.assertEquals(driver.getTitle(), "Google"); // asserts the web site title is "Google" Assert.assertEquals(myInput.getAttribute("value"), "4200"); // asserts the myInput value is "4200"
- to take screenshots of a page use the
WAFScreenShotterutility class
package util;
new WAFScreenShotter(<WEBDRIVER>, "<PICTURE NAME>");
// takes picture of current page and puts it current directory- do not add a file extension to the picture name argument, a
.jpgis automatically added - if you already have a
WAFScreenShotterobject you can simply use the.takeScreenshot()method to take another screenshot
myWAFScreenShotter.takeScreenshot(driver, "example");
// takes picture and places "example.jpg" in current directory- to download all files on a page matching a CSS selector pattern, use the
WAFFileDownloaderutility class
package util;
new WAFFileDownloader(<WEBDRIVER>, "<FOLDER NAME>", "<CSS SELECTOR>");
// downloads all files on current page based on selector into the user specified folder- be sure to include "Files" (capitalization matters) somewhere in your folder name if you want the folder deleted when
make cleanis run - almost all of your CSS selectors should end in
asince you should be clicking links to download files - if you already have a
WAFFileDownloaderobject you can simply use the.downloadFiles()method to download additional files
myWAFFileDownloader.downloadFiles(driver, "my-Files-Folder", "td > a");
// downloads all files on the page that are table element links- run the following command in the terminal
make- run the following commands in the terminal
make compile
java -cp .:res/* Main <OPTIONAL ARGUMENTS>- see Optional Arguments below for arguments
- run the following commands in the terminal
javac -cp "res/*;." util/*.java
javac -cp "res/*;." *.java
java -cp "res/*;." Main <OPTIONAL ARGUMENTS>
- see Optional Arguments below for arguments
<OPTIONAL ARGUMENTS> is replaced by your command line arguments
-bor--browserfollowed by browser name (chrome,firefox,edge,ie) for specific browser- default is
chrome
- default is
-wor--widthfollowed by port number for specific browser width- default is
1024
- default is
-hor--heightfollowed by port number for specific browser height- default is
768
- default is
-por--portfollowed by port number to run on a specific port number- parallelization on single port not possible at the moment so don't specify a port if you are running multiple tests
- default is
0(web driver will automatically choose ports)
-uor--urlfollowed by ip address for specific ip/site to be used- default is ``
- usually specify this on a test by test basis, largely meant to quickly test the same functionality on two copies of the same site from the command line
-tor--tagfollowed by a non-spaced comma-separated value of test class namesExample1, Example2to run TestExample1 and TestExample2 test classes for example- default is just
Example
- after the tests run, a folder called
test-outputwill be generated- within this folder, another folder
htmlexists and within that is theindex.htmlfile containing the reportNG report of how the tests went - the
testng-results.xmlis anxmlreport that can be used to display results within an environment like Jenkins or Zephyr
- within this folder, another folder
- if you want to start fresh and remove compiled files simply run
make clean- if you want to remove everything but the bare essentials run
make superclean- this removes the
build.xml(recreated byMain.javaeach run) and the pdf copy of this README
This framework works in the following manner:
- All java files are compiled
- Main is run
- Parses optional arguments
- Creates
build.xmlTestNG - Uses
build.xmlas a template to run tests- Initializes web driver
- Performs actions using Selenium
- TestNG test assertions are checked
- TestNG framework creates output
.htmland.xmlfiles to view test results
makeruns the following commands:
javac -cp .:res/* util/*.java
javac -cp .:res/* *.java
java -cp .:res/* Mainmake compileruns the following commands:
javac -cp .:res/* util/*.java
javac -cp .:res/* *.javamake cleanruns the following command:
rm -rf test-output *Files* *.class util/*.class *.zip *.png *.jpgmake supercleanruns the following command:
rm -rf test-output *Files* *.class util/*.class *.zip *.png *.jpg *.pdf docs/*.pdf *.xml- 1.X
- demonstration of working selenium/testng functionality
- portability assurance with chrome/linux
- local report generation
- make file for ease of compilation
- cross platform/browser compatibility with windows/linux
- user defined test parameters using advanced options parser
- browser, resolution, port, url
- parallel same browser tests
- vastly improved documentation
- abstracted screen-shotting, file downloading, and login processes
- utility packaging improvements
- web driver abstraction for better parallelization support
- 2.X (future features)
- catch test class doesn't exist exception
- improve command line tag parsing
5.1-7.1would run every test that exists in that range5.1.1would run just that specific step (wrapped in login and quit)
- add test categorization and reversals in conjunction with one another
smokewould run just tests labeled with smokenot debugwould run all tests that aren't debug- combined these two tags would run smoke tests that aren't debug
- make multiple tests with a specified port run each additional web driver in successive ports
- for example, if the user has 3 tests to run and specifies port 4000 then web drivers are spun up on 4000, 4001, and 4002
- auto fix the web drivers to whatever they need to be
- right now if the defaults don't work you have to look at the web browser version and manually download the correct one
- web requests to download new/old drivers?
- If you get an error that says "port already in use" run the following
- Windows: open task manager (right click taskbar) and find chromedriver/geckodriver/mswebdriver
- right click and kill process
- Linux:
- open a terminal and run
killall chromedriverorkillall geckodriver
- open a terminal and run
- Windows: open task manager (right click taskbar) and find chromedriver/geckodriver/mswebdriver
- Incompatible web drivers
- download the correct ones and replace in the
driversfolder- find your browser version (usually in settings > about) and google it for matching web driver version
- download the correct ones and replace in the
- If compilation throws warnings on Windows try recompiling (rerunning the same steps) to remove these warnings
- A port cannot be specified if multiple tests are run as a port collision will occur
- Windows compilation occasionally throws warnings that can be fixed by recompiling
- Internet Explorer web driver not working :)