├── .gitignore ├── README.md ├── chrome_tests.xml ├── environment.properties ├── firefox_tests.xml ├── ie_tests.xml ├── pom.xml ├── selenium_starter_guide.pdf ├── src ├── main │ └── java │ │ ├── pages │ │ ├── LoadTestPage.java │ │ ├── LoadTestingToolsPage.java │ │ ├── LoginPage.java │ │ ├── PageBase.java │ │ └── PerformanceTestPage.java │ │ ├── templates │ │ └── TestTemplate.java │ │ └── utils │ │ ├── ScreenshotOnFailure.java │ │ └── Utils.java └── test │ └── java │ └── tests │ ├── FilesDownloadVerification.java │ ├── LoginTest.java │ └── VerifyPagesLoadFine.java └── user.properties /.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | .project/ 3 | .classpath/ 4 | .settings/ 5 | .git/ 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | automation-starter-kit 2 | ====================== 3 | 4 | Selenium Grid automation framework written in Java that utilizes Maven, TestNG, Selenium Webdriver and is ready to be setup on Jenkins 5 | -------------------------------------------------------------------------------- /chrome_tests.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /environment.properties: -------------------------------------------------------------------------------- 1 | stage=https://dl.dropboxusercontent.com/u/247363443/Site/loginPage.html 2 | -------------------------------------------------------------------------------- /firefox_tests.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /ie_tests.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 4 | 4.0.0 5 | biz.neustar.tests 6 | automation-starter-kit 7 | 0.0.1-SNAPSHOT 8 | http://maven.apache.org 9 | automation-starter-kit 10 | 11 | UTF-8 12 | 13 | 14 | 15 | 16 | org.apache.maven.plugins 17 | maven-surefire-plugin 18 | 2.15 19 | 20 | true 21 | 22 | ${tests} 23 | 24 | 25 | 26 | 27 | ch.fortysix 28 | maven-postman-plugin 29 | 0.1.6 30 | 31 | 32 | send_an_email 33 | test 34 | 35 | send-mail 36 | 37 | 38 | smtp.gmail.com 39 | 465 40 | true 41 | true 42 | yourEmail 43 | password 44 | yourEmail 45 | 46 | ${receiver} 47 | 48 | 49 | 50 | ${basedir}/target/surefire-reports 51 | 52 | emailable-report.html 53 | 54 | 55 | 56 | ${basedir}/screenshots 57 | 58 | **/*.png 59 | 60 | 61 | 62 | Important subject 63 | true 64 | 65 | Attached is tests run report.

67 |
68 |

Have a nice day.

69 | ]]> 70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 | 78 | 79 | org.seleniumhq.selenium 80 | selenium-java 81 | 2.37.0 82 | 83 | 84 | org.testng 85 | testng 86 | 6.8 87 | test 88 | 89 | 90 | 91 | 92 | 93 | org.apache.maven.plugins 94 | maven-surefire-report-plugin 95 | 2.7.2 96 | 97 | 98 | 99 |
-------------------------------------------------------------------------------- /selenium_starter_guide.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bbatsalenka/automation-starter-kit/90c4a7d0a9ffe2820aa06f7eb1e34581040190d4/selenium_starter_guide.pdf -------------------------------------------------------------------------------- /src/main/java/pages/LoadTestPage.java: -------------------------------------------------------------------------------- 1 | package pages; 2 | 3 | import org.openqa.selenium.WebDriver; 4 | import org.openqa.selenium.WebElement; 5 | import org.openqa.selenium.support.FindBy; 6 | import org.openqa.selenium.support.PageFactory; 7 | 8 | //NOTE (applicable to Eclipse): if you want to see the method declaration which is used in a different class 9 | //just place the cursor on the method name and click F3 or Fn/ Ctrl F3 (depending on your laptop) 10 | //if there is import missing just click Ctrl + Shift + "O" - do not insert the imports by hand!!! 11 | 12 | public class LoadTestPage extends PageBase { 13 | // LoadTestPage constructor that passes the WebDriver instance to 14 | // PageBase.class 15 | // and instantiates it's WebElements using PageFactory 16 | public LoadTestPage(WebDriver driver) { 17 | super(driver); 18 | PageFactory.initElements(driver, this); 19 | } 20 | 21 | // Below are WebElements located on the LoadTestPage and getters to access 22 | // the elements 23 | @FindBy(linkText = "Performance testing definition") 24 | private WebElement performanceTestingLink; 25 | 26 | @FindBy(linkText = "Stress testing definition") 27 | private WebElement stressTestingLink; 28 | 29 | @FindBy(linkText = "Download load testing tutorial") 30 | private WebElement loadTestingTutorialDownloadLink; 31 | 32 | @FindBy(linkText = "Download performance testing tutorial") 33 | private WebElement performanceTestingTutorialDownloadLink; 34 | 35 | @FindBy(linkText = "Load testing tools") 36 | private WebElement loadToolsLink; 37 | 38 | public WebElement getLoadToolsLink() { 39 | return loadToolsLink; 40 | } 41 | 42 | public WebElement getPerformanceTestingLink() { 43 | return performanceTestingLink; 44 | } 45 | 46 | public WebElement getStressTestingLink() { 47 | return stressTestingLink; 48 | } 49 | 50 | public WebElement getLoadTestingTutorialDownloadLink() { 51 | return loadTestingTutorialDownloadLink; 52 | } 53 | 54 | public WebElement getPerformanceTestingTutorialDownloadLink() { 55 | return performanceTestingTutorialDownloadLink; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/pages/LoadTestingToolsPage.java: -------------------------------------------------------------------------------- 1 | package pages; 2 | 3 | import org.openqa.selenium.WebDriver; 4 | 5 | //NOTE (applicable to Eclipse): if you want to see the method declaration which is used in a different class 6 | //just place the cursor on the method name and click F3 or Fn/ Ctrl F3 (depending on your laptop) 7 | //if there is import missing just click Ctrl + Shift + "O" - do not insert the imports by hand!!! 8 | 9 | public class LoadTestingToolsPage extends PageBase { 10 | // It's a dummy page as in the tests it's used to show how WebDriver will 11 | // identify a 404 error when the page is not found 12 | public LoadTestingToolsPage(WebDriver driver) { 13 | super(driver); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/pages/LoginPage.java: -------------------------------------------------------------------------------- 1 | package pages; 2 | 3 | import org.openqa.selenium.WebDriver; 4 | import org.openqa.selenium.WebElement; 5 | import org.openqa.selenium.support.FindBy; 6 | import org.openqa.selenium.support.PageFactory; 7 | 8 | import utils.Utils; 9 | 10 | //NOTE (applicable to Eclipse): if you want to see the method declaration which is used in a different class 11 | //just place the cursor on the method name and click F3 or Fn/ Ctrl F3 (depending on your laptop) 12 | //if there is import missing just click Ctrl + Shift + "O" - do not insert the imports by hand!!! 13 | 14 | public class LoginPage extends PageBase { 15 | // LoginPage constructor that passes the WebDriver instance to 16 | // PageBase.class 17 | // and instantiates it's WebElements using PageFactory 18 | public LoginPage(WebDriver driver) { 19 | super(driver); 20 | PageFactory.initElements(driver, this); 21 | } 22 | 23 | @FindBy(name = "userid") 24 | private WebElement userNameInputField; 25 | 26 | @FindBy(name = "pswrd") 27 | private WebElement passwordInputField; 28 | 29 | @FindBy(xpath = "//input[@value='Login']") 30 | private WebElement loginButton; 31 | 32 | @FindBy(xpath = "//input[@value='Cancel']") 33 | private WebElement cancelButton; 34 | 35 | // makes sense to place the login process into a method as it's pretty big 36 | // and when 37 | // it's placed in a method the code gets more readable and can be reused 38 | public void login(String user) { 39 | // another useful thing is to place values like username and password 40 | // into a properties file 41 | // the Utils.getValueFromPropertiesFile() method will find the required 42 | // value in the file 43 | // and assign it to a variable 44 | String username = Utils.getValueFromPropertiesFile(user + "_login", 45 | "user.properties"); 46 | String password = Utils.getValueFromPropertiesFile(user + "_password", 47 | "user.properties"); 48 | userNameInputField.sendKeys(username); 49 | passwordInputField.sendKeys(password); 50 | loginButton.click(); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/pages/PageBase.java: -------------------------------------------------------------------------------- 1 | package pages; 2 | 3 | import java.net.HttpURLConnection; 4 | import java.net.URL; 5 | import org.openqa.selenium.WebDriver; 6 | import org.openqa.selenium.WebElement; 7 | import org.openqa.selenium.support.FindBy; 8 | import org.openqa.selenium.support.PageFactory; 9 | import org.testng.Reporter; 10 | 11 | //NOTE (applicable to Eclipse): if you want to see the method declaration which is used in a different class 12 | //just place the cursor on the method name and click F3 or Fn/ Ctrl F3 (depending on your laptop) 13 | //if there is import missing just click Ctrl + Shift + "O" - do not insert the imports by hand!!! 14 | 15 | // each page extends this class that has some common methods and WebElements 16 | public abstract class PageBase { 17 | 18 | protected WebDriver driver; 19 | 20 | // PageBase constructor that initiates WebElement, it gets the WebDriver 21 | // instance from other pages 22 | // when the ones are instantiated 23 | public PageBase(WebDriver driver) { 24 | this.driver = driver; 25 | PageFactory.initElements(driver, this); 26 | } 27 | 28 | // it makes sense to place this element in PageBase.class as it appears on 29 | // all pages that extend PageBase.class 30 | @FindBy(linkText = "Terms of Use") 31 | private WebElement termsOfUseLink; 32 | 33 | // this element is located on most of the pages, even though it's not 34 | // located on LoginPage 35 | // it still makes sense to place it here so that all the pages could inherit 36 | // it 37 | @FindBy(linkText = "Logout") 38 | private WebElement logoutLink; 39 | 40 | @FindBy(linkText = "Back to load testing") 41 | private WebElement backToLoadTestingLink; 42 | 43 | public WebElement getTermsOfUseLink() { 44 | return termsOfUseLink; 45 | } 46 | 47 | public WebElement getLogoutLink() { 48 | return logoutLink; 49 | } 50 | 51 | public WebElement getBackToLoadTestingLink() { 52 | return backToLoadTestingLink; 53 | } 54 | 55 | // this method is useful when you have multiple links on a page and instead 56 | // of click each link 57 | // and verifying the page title or what's written on the page - you can just 58 | // send an http request 59 | // to the link and see what the response is 60 | public boolean isFileDownloadable(String link) { 61 | int code = 0; 62 | Reporter.log("Link: " + link); 63 | try { 64 | URL url = new URL(link); 65 | HttpURLConnection connection = (HttpURLConnection) url 66 | .openConnection(); 67 | connection.setRequestMethod("GET"); 68 | code = connection.getResponseCode(); 69 | Reporter.log("Code: " + code); 70 | } catch (Exception e) { 71 | Reporter.log(e.toString()); 72 | return false; 73 | } 74 | return code == 200 || code == 302; 75 | } 76 | 77 | public WebDriver getWebDriver() { 78 | return driver; 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/main/java/pages/PerformanceTestPage.java: -------------------------------------------------------------------------------- 1 | package pages; 2 | 3 | import org.openqa.selenium.WebDriver; 4 | import org.openqa.selenium.WebElement; 5 | import org.openqa.selenium.support.FindBy; 6 | import org.openqa.selenium.support.PageFactory; 7 | 8 | //NOTE (applicable to Eclipse): if you want to see the method declaration which is used in a different class 9 | //just place the cursor on the method name and click F3 or Fn/ Ctrl F3 (depending on your laptop) 10 | //if there is import missing just click Ctrl + Shift + "O" - do not insert the imports by hand!!! 11 | 12 | public class PerformanceTestPage extends PageBase { 13 | // PerformanceTestPage constructor that passes the WebDriver instance to 14 | // PageBase.class 15 | // and instantiates it's WebElements using PageFactory 16 | public PerformanceTestPage(WebDriver driver) { 17 | super(driver); 18 | PageFactory.initElements(driver, this); 19 | } 20 | 21 | @FindBy(xpath = "//img[@src='stress.jpg']") 22 | private WebElement stressTestingImage; 23 | 24 | public WebElement getStressTestingImage() { 25 | return stressTestingImage; 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/templates/TestTemplate.java: -------------------------------------------------------------------------------- 1 | package templates; 2 | 3 | import java.net.URL; 4 | import java.util.concurrent.TimeUnit; 5 | 6 | import org.openqa.selenium.WebDriver; 7 | import org.openqa.selenium.remote.DesiredCapabilities; 8 | import org.openqa.selenium.remote.RemoteWebDriver; 9 | import org.testng.annotations.AfterClass; 10 | import org.testng.annotations.BeforeClass; 11 | import org.testng.annotations.BeforeSuite; 12 | import org.testng.annotations.Parameters; 13 | 14 | import pages.LoginPage; 15 | import utils.Utils; 16 | 17 | //NOTE (applicable to Eclipse): if you want to see the method declaration which is used in a different class 18 | //just place the cursor on the method name and click F3 or Fn/ Ctrl F3 (depending on your laptop) 19 | //if there is import missing just click Ctrl + Shift + "O" - do not insert the imports by hand!!! 20 | 21 | public class TestTemplate { 22 | 23 | private DesiredCapabilities capability; 24 | private ThreadLocal threadDriver = null; 25 | protected LoginPage loginPage; 26 | 27 | @BeforeSuite(alwaysRun = true) 28 | // clean out the "screenshots" folder before testing 29 | public void prepareSuiteForTesting() throws Exception { 30 | Utils.cleanDirectory("screenshots"); 31 | } 32 | 33 | // pass the test parameters to @BeforeClass() 34 | @Parameters({ "browser", "port", "ipAddress", "user", "environment" }) 35 | @BeforeClass(alwaysRun = true) 36 | public synchronized void beforeTest(String browser, String port, 37 | String ipAddress, String user, String environment) throws Exception { 38 | // WebDriver is set as ThreadLocal() to protect it 39 | // during 40 | // parallel tests run 41 | threadDriver = new ThreadLocal(); 42 | // here we select which browser we want to use 43 | capability = Utils.getBrowserInstance(browser); 44 | // here we set the RemoteWebDriver to be able to use it in Selenium Grid 45 | threadDriver.set(new RemoteWebDriver(new URL("http://" + ipAddress 46 | + ":" + port + "/wd/hub"), capability)); 47 | // here we set the timeout using implicit wait for an element to be 48 | // found 49 | getRemoteWebDriver().manage().timeouts() 50 | .implicitlyWait(35, TimeUnit.SECONDS); 51 | // here we maximize the window 52 | getRemoteWebDriver().manage().window().maximize(); 53 | // here we get the testing environment url from .properties file 54 | getRemoteWebDriver().get( 55 | Utils.getValueFromPropertiesFile(environment, 56 | "environment.properties")); 57 | // instantiate the loginPage and it's WebElements 58 | loginPage = new LoginPage(getRemoteWebDriver()); 59 | // perform login 60 | loginPage.login(user); 61 | } 62 | 63 | @AfterClass(alwaysRun = true) 64 | public synchronized void afterSuite() throws Exception { 65 | getRemoteWebDriver().quit(); 66 | } 67 | 68 | public WebDriver getRemoteWebDriver() { 69 | return threadDriver.get(); 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /src/main/java/utils/ScreenshotOnFailure.java: -------------------------------------------------------------------------------- 1 | package utils; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | 6 | import org.apache.commons.io.FileUtils; 7 | import org.openqa.selenium.OutputType; 8 | import org.openqa.selenium.TakesScreenshot; 9 | import org.openqa.selenium.WebDriver; 10 | import org.openqa.selenium.remote.Augmenter; 11 | import org.testng.IClass; 12 | import org.testng.ITestNGMethod; 13 | import org.testng.ITestResult; 14 | import org.testng.TestListenerAdapter; 15 | 16 | import templates.TestTemplate; 17 | 18 | //NOTE (applicable to Eclipse): if you want to see the method declaration which is used in a different class 19 | //just place the cursor on the method name and click F3 or Fn/ Ctrl F3 (depending on your laptop) 20 | //if there is import missing just click Ctrl + Shift + "O" - do not insert the imports by hand!!! 21 | 22 | public class ScreenshotOnFailure extends TestListenerAdapter { 23 | 24 | @Override 25 | public void onTestFailure(ITestResult iTestResult) { 26 | ITestNGMethod method = iTestResult.getMethod(); 27 | String methodName = method.getMethodName(); 28 | IClass iClassObject = iTestResult.getTestClass(); 29 | String className = iClassObject.getRealClass().toString(); 30 | System.out.println(iTestResult.getInstance().toString()); 31 | Object currentClass = iTestResult.getInstance(); 32 | WebDriver webDriver = ((TestTemplate) currentClass) 33 | .getRemoteWebDriver(); 34 | File screenshot = ((TakesScreenshot) new Augmenter().augment(webDriver)) 35 | .getScreenshotAs(OutputType.FILE); 36 | try { 37 | FileUtils.copyFile( 38 | screenshot, 39 | new File("screenshots\\method " + methodName + " from " 40 | + className + " failed " 41 | + Utils.createDateForFileName() + ".png")); 42 | } catch (IOException ioe) { 43 | ioe.printStackTrace(); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/utils/Utils.java: -------------------------------------------------------------------------------- 1 | package utils; 2 | 3 | import java.io.File; 4 | import java.io.FileInputStream; 5 | import java.io.IOException; 6 | import java.text.SimpleDateFormat; 7 | import java.util.Date; 8 | import java.util.Properties; 9 | import java.util.concurrent.TimeUnit; 10 | 11 | import org.apache.commons.io.FileUtils; 12 | import org.openqa.selenium.firefox.FirefoxDriver; 13 | import org.openqa.selenium.firefox.FirefoxProfile; 14 | import org.openqa.selenium.remote.DesiredCapabilities; 15 | 16 | //NOTE (applicable to Eclipse): if you want to see the method declaration which is used in a different class 17 | //just place the cursor on the method name and click F3 or Fn/ Ctrl F3 (depending on your laptop) 18 | //if there is import missing just click Ctrl + Shift + "O" - do not insert the imports by hand!!! 19 | 20 | public class Utils { 21 | 22 | // below are hardWait methods - which is a basic Thread.sleep() but just 23 | // wrapped into methods 24 | public static void hardWaitMilliSeconds(int milliSeconds) { 25 | try { 26 | TimeUnit.MILLISECONDS.sleep(milliSeconds); 27 | } catch (Exception e) { 28 | e.printStackTrace(); 29 | } 30 | } 31 | 32 | public static void hardWaitSeconds(int seconds) { 33 | try { 34 | TimeUnit.SECONDS.sleep(seconds); 35 | } catch (Exception e) { 36 | e.printStackTrace(); 37 | } 38 | } 39 | 40 | public static void hardWaitMinutes(int minutes) { 41 | try { 42 | TimeUnit.MINUTES.sleep(minutes); 43 | } catch (Exception e) { 44 | e.printStackTrace(); 45 | } 46 | } 47 | 48 | // this method is being used in the ScreenShotOnFailure.class 49 | public static String createDateForFileName() { 50 | Date date = new Date(); 51 | SimpleDateFormat dateFormat = new SimpleDateFormat( 52 | "yyyy-MM-dd HH-mm-ss"); 53 | return dateFormat.format(date); 54 | } 55 | 56 | // method to get a certain value from a certain .properties file 57 | public static String getValueFromPropertiesFile(String value, 58 | String fileName) { 59 | Properties prop = new Properties(); 60 | String selectedItem = null; 61 | 62 | try { 63 | FileInputStream fileInputStream = new FileInputStream(fileName); 64 | prop.load(fileInputStream); 65 | selectedItem = prop.getProperty(value); 66 | fileInputStream.close(); 67 | } catch (IOException ex) { 68 | ex.printStackTrace(); 69 | } 70 | return selectedItem; 71 | } 72 | 73 | // method to select the needed browser 74 | public static DesiredCapabilities getBrowserInstance(String browserName) { 75 | switch (browserName) { 76 | case "firefox": { 77 | DesiredCapabilities capability = DesiredCapabilities.firefox(); 78 | FirefoxProfile firefoxProfile = new FirefoxProfile(); 79 | capability.setCapability(FirefoxDriver.PROFILE, firefoxProfile); 80 | return capability; 81 | } 82 | case "ie": { 83 | //System.setProperty("webdriver.ie.driver", "C:\\IEDriverServer.exe"); 84 | DesiredCapabilities capability = DesiredCapabilities 85 | .internetExplorer(); 86 | return capability; 87 | } 88 | case "chrome": { 89 | // System.setProperty("webdriver.chrome.driver", 90 | // "c:\\chromedriver.exe"); 91 | DesiredCapabilities capability = DesiredCapabilities.chrome(); 92 | return capability; 93 | } 94 | default: { 95 | DesiredCapabilities capability = DesiredCapabilities.firefox(); 96 | return capability; 97 | } 98 | } 99 | } 100 | 101 | // method to clean a certain directory 102 | public static void cleanDirectory(String directoryName) throws Exception { 103 | File directory = new File(directoryName); 104 | if (!directory.exists()) { 105 | directory.mkdir(); 106 | } 107 | FileUtils.cleanDirectory(directory); 108 | } 109 | 110 | } 111 | -------------------------------------------------------------------------------- /src/test/java/tests/FilesDownloadVerification.java: -------------------------------------------------------------------------------- 1 | package tests; 2 | 3 | import org.testng.Assert; 4 | import org.testng.Reporter; 5 | import org.testng.annotations.Test; 6 | 7 | import pages.LoadTestPage; 8 | import templates.TestTemplate; 9 | 10 | //NOTE (applicable to Eclipse): if you want to see the method declaration which is used in a different class 11 | //just place the cursor on the method name and click F3 or Fn/ Ctrl F3 (depending on your laptop) 12 | //if there is import missing just click Ctrl + Shift + "O" - do not insert the imports by hand!!! 13 | 14 | public class FilesDownloadVerification extends TestTemplate { 15 | private LoadTestPage loadTestPage; 16 | 17 | // we use priority = some value to prioritize the order of test execution 18 | @Test(priority = 0) 19 | public void isUserLoggedIn() { 20 | loadTestPage = new LoadTestPage(getRemoteWebDriver()); 21 | Reporter.log("Load testing page title: " 22 | + getRemoteWebDriver().getTitle()); 23 | Assert.assertTrue(getRemoteWebDriver().getTitle() 24 | .equals("Load Testing")); 25 | } 26 | 27 | // we use dependsOnMethods to structure our tests and to make sure that a 28 | // method 29 | // that had dependsOnMethods will be only executed if the method it depends 30 | // on did not fail, 31 | // otherwise the remaining tests that have dependencies will be skipped 32 | @Test(dependsOnMethods = { "isUserLoggedIn" }, priority = 1) 33 | public void isLoadTestTutorialDownloadable() { 34 | // here we get the "href" attribute of the load testing tutorial 35 | // download link which is the 36 | // link of the download file 37 | String loadTestTutorialLink = loadTestPage 38 | .getLoadTestingTutorialDownloadLink().getAttribute("href"); 39 | // if the http response is 200 or 302 the method isFileDownloadable will 40 | // return true 41 | // otherwise it will return false 42 | Assert.assertTrue(loadTestPage.isFileDownloadable(loadTestTutorialLink)); 43 | } 44 | 45 | @Test(priority = 2) 46 | public void isPerformanceTestTutorialDownloadable() { 47 | String performanceTestTutorialLink = loadTestPage 48 | .getPerformanceTestingTutorialDownloadLink().getAttribute( 49 | "href"); 50 | // here we do the same and by design the test should fail as the file is 51 | // not found and 404 response is returned 52 | Assert.assertTrue(loadTestPage 53 | .isFileDownloadable(performanceTestTutorialLink)); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/test/java/tests/LoginTest.java: -------------------------------------------------------------------------------- 1 | package tests; 2 | 3 | import org.testng.Assert; 4 | import org.testng.Reporter; 5 | import org.testng.annotations.Test; 6 | 7 | import templates.TestTemplate; 8 | 9 | //NOTE (applicable to Eclipse): if you want to see the method declaration which is used in a different class 10 | //just place the cursor on the method name and click F3 or Fn/ Ctrl F3 (depending on your laptop) 11 | //if there is import missing just click Ctrl + Shift + "O" - do not insert the imports by hand!!! 12 | 13 | public class LoginTest extends TestTemplate { 14 | 15 | // the simplest login test 16 | // as you remember the login is done in the TestTemplate 17 | // so here we make sure user is logged in by verifying the title of 18 | // LoadTestingPage as 19 | // / it is displayed after successful login 20 | @Test 21 | public void isUserLoggedIn() { 22 | // we user Reporter.log() to add some information to our test report 23 | // generated at the end of tests 24 | // execution 25 | Reporter.log("Load testing page title: " 26 | + getRemoteWebDriver().getTitle()); 27 | // we user Assert.assertTrue() testNG method to assert a statement 28 | // if it fails - the test will be displayed as failed 29 | Assert.assertTrue(getRemoteWebDriver().getTitle() 30 | .equals("Load Testing")); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/test/java/tests/VerifyPagesLoadFine.java: -------------------------------------------------------------------------------- 1 | package tests; 2 | 3 | import org.testng.Assert; 4 | import org.testng.annotations.Test; 5 | 6 | import pages.LoadTestPage; 7 | import pages.PerformanceTestPage; 8 | import templates.TestTemplate; 9 | 10 | //NOTE (applicable to Eclipse): if you want to see the method declaration which is used in a different class 11 | //just place the cursor on the method name and click F3 or Fn/ Ctrl F3 (depending on your laptop) 12 | //if there is import missing just click Ctrl + Shift + "O" - do not insert the imports by hand!!! 13 | 14 | public class VerifyPagesLoadFine extends TestTemplate { 15 | private LoadTestPage loadTestPage; 16 | private PerformanceTestPage performanceTestPage; 17 | 18 | // the purpose of the methods in this class is to 19 | // make sure that each page loads fine 20 | // it's done by verifying the page title 21 | // one of the tests will fail on purpose 22 | 23 | // this test will pass 24 | @Test 25 | public void veifyLoadTestPageLoadsFine() { 26 | loadTestPage = new LoadTestPage(getRemoteWebDriver()); 27 | String loadTestPageTitle = "Load Testing"; 28 | Assert.assertTrue(getRemoteWebDriver().getTitle().equals( 29 | loadTestPageTitle)); 30 | loadTestPage.getPerformanceTestingLink().click(); 31 | } 32 | 33 | // this test will pass 34 | @Test(dependsOnMethods = { "veifyLoadTestPageLoadsFine" }) 35 | public void verifyPerformancePageLoadsFine() { 36 | performanceTestPage = new PerformanceTestPage(getRemoteWebDriver()); 37 | String performanceTestPageTitle = "Performance Testing"; 38 | Assert.assertTrue(getRemoteWebDriver().getTitle().equals( 39 | performanceTestPageTitle)); 40 | performanceTestPage.getBackToLoadTestingLink().click(); 41 | } 42 | 43 | // this test fails on purpose to show how WebDriver will identify and report 44 | // a test failure 45 | @Test(dependsOnMethods = { "verifyPerformancePageLoadsFine" }) 46 | public void verifyLoadTestingToolsPageLoadsFine() { 47 | String loadTestingToolsPageTitle = "Load tools"; 48 | loadTestPage.getLoadToolsLink().click(); 49 | performanceTestPage = new PerformanceTestPage(getRemoteWebDriver()); 50 | Assert.assertTrue(getRemoteWebDriver().getTitle().equals( 51 | loadTestingToolsPageTitle)); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /user.properties: -------------------------------------------------------------------------------- 1 | user1_login=tester1 2 | user1_password=password 3 | user2_login=tester2 4 | user2_password=password 5 | user3_login=tester3 6 | user3_password=password --------------------------------------------------------------------------------