Thursday, 27 August 2015

selenium testing using eclipse/java


1. support for browsers other than firefox (chrome, ie, safari ...)
  • take chrome for example
  • chrome driver is a separable executable that webdriver use to control chrome
  • download chrome driver @http://www.seleniumhq.org/download/
  • change code accordingly when using browsers other than firefox
  • selenium api communicate with webdrivers (ie, firefox, chrome etc) rest service via json wire protocol

2. using testng
  • install testng on eclipse (help -> install new software @http://beust.com/eclipse
  • more flexible in annotation, parametrization, grouping and report than junt
  • easy for parallel execution
  • in testng, a test suite is a 'test***.xml', which can contain java class or package 
  • if using testng with eclipse, can specify 'parallel' in 'test***.xml'
       <suite name="suite1" verbose="1" parallel="methods" thread-count="5">
           <test name="regression1">
               <classes>
                   <class name="NoPackageTest" />
               </classes>
            </test>
            <test name="regression2">
                <packages>
                    <package name="test.sample" />
                </packages>
            </test>
       </suite>

3. using junit
  • using 'Suite' as test runner
      import org.junit.runner.RunWith;
      import org.junit.runners.Suite;

      @RunWith(Suite.class)
      @Suite.SuiteClasses({
             TestFeatureLogin.class,
             TestFeatureLogout.class,
             TestFeatureNavigate.class,
             TestFeatureUpdate.class
      })


4. using maven
  • maven is a java build tool
  • maven manage jar files via pom.xml
  • maven manage build and test
  • maven can execute junit or testng test cases (may or maynot need surefire plugin) 
  • all maven tests of project must be under src/test/java folder
  • by default maven uses the following naming conventions when looking for tests to run under all subdirectories of src/test/java: Test*, *Test, *TestCase
  • install maven on eclipse (help -> install new software @http://download.eclipse.org/technology/m2e/release/)
  • in some selenium and browser version combination, only add
       <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>2.45.0</version>
        </dependency>

       is not enough, will still have build error, need to add

        <dependency>
            <groupId>com.google.guava</groupId>Maven Standard Directory Layout
            <artifactId>guava</artifactId>
            <version>18.0</version>
        </dependency>


        as well


5.  data driven
  • testng @DataProvider annotation
  • apache poi (java api for microsoft office document) to read/write from excel

6. eclipse
  • new folder vs. new source folder vs. new package
  • new source folder add folder to buildpath, new package create the package and the source folder

7. phantomjs
  • use phantomjs-maven-plugin
  • it will download phantomjs, put the path to executable in a phantomjs.binary property file

references
1. testng
2. maven surefire plugin using testng 
3. maven surefire plugin using junit
4. why do we need IEdriver and ChromeDriver but no Firefox driver?
5. selenium webdriver architecture
6. maven standard directory layout
7. difference between “new folder”, “new source folder” and “new package”?
8. java project with cucumber, testng and maven


No comments:

Post a Comment