Introduction to Automation Testing

Environment Required

TOOLS: JDK,ANT,Eclipse

  • 1. Install ANT
Download:  http://archive.apache.org/dist/ant/binaries/apache-ant-1.9.2-bin.zip   

    a.     First decompression the apache-ant-1.9.2-bin.zip into your hard disk , I put it in ” D:\apache-ant-1.9.2”
    b.     Make a new environment variable, name “ANT_HOME”. Value “D:\apache-ant-1.9.2” (see picture new_variable.jpg)
    c.     Put  %ANT_HOME%/bin;   into the beginning of your system variable ; (see system_variable.jpg)
    d.     To verify whether it is successfully installed,  open your DOC window, and put  ant - version  to verify if you have installed successfully or not
  • 2. Coding
webDriver + testNG
    run in different browser:
                      public void Test_InternetExplorer(String webSite) throws Exception {			 
				System.setProperty("webdriver.ie.driver", ".\\lib\\IEDriverServer.exe");
				DesiredCapabilities capabilities = DesiredCapabilities
						.internetExplorer();
				capabilities
						.setCapability(
								InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,
								true);
				driver = new InternetExplorerDriver(capabilities);
				baseUrl = webSite;
				testElementsExists(driver);
		 
			}

			 @Test
			@Parameters({ "firefox_dir", "webSite" })
			public void Test_Firefox(String firefox_dir, String webSite)
					throws Exception {
		 
				System.setProperty("webdriver.firefox.bin", firefox_dir);

				driver = new FirefoxDriver();

				baseUrl = webSite;
				testElementsExists(driver);
		 
			}

			@Test
			@Parameters({ "webSite" })
			public void Test_Chrome(String webSite) throws Exception {
			 
				System.setProperty("webdriver.chrome.driver", "./lib/chromedriver.exe");
				driver = new ChromeDriver();
				baseUrl = webSite;
				driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
				 testElementsExists(driver);
		 
			}
  • 3. testng.xml setting
a. every test case should be added into testng.xml, so that when you right click on ant.xml to run the cases.
    b. every test case is included like this:
           	  <test name="Test basic elements  " preserve-order="true"> 
	          <classes>
		  <class name="script.TestBasicElements"/>
                  </classes>
	          </test>

    the 'name' is the one that will appear in left of test results page. 
    classes means all the classes that you write should be run.
    <class name="path"> this paths is important, only you write correctly, can it be found.
  • 4. Run Script Method
a. through the eclipse :   Importing the project in eclipse, run ant build script. The XML
   b. throught the DOC window:   -  cd e:\workspace\MMR     -ant
  • 5. see the results
to see the results here: /test-output/Report.html
   if the test Cases are all passed, the it should be Green ,or there will be error info in the red test cases, then you can click the cases, and check the error.