12/08/2018, 16:54

Selenium Guideline for Beginners - Part 1

1. Setup tools & configure system 1.1 Install Java (JDK 1.7 or upper) Download and install JDK 8. Create new or edit two system environment variables: • JAVA_HOME. Value: the path of installed JDK folder, for example: C:Program FilesJavaJDK8 • PATH. This is an existing variable, you ...

1. Setup tools & configure system 1.1 Install Java (JDK 1.7 or upper)

  1. Download and install JDK 8.
  2. Create new or edit two system environment variables: • JAVA_HOME. Value: the path of installed JDK folder, for example: C:Program FilesJavaJDK8 • PATH. This is an existing variable, you should append to it a semicolon and a path, exactly like this: ;%JAVA_HOME%in
  3. Check your installation: open Windows command prompt and type: java -version • Open new CMD and type " java -version " to make sure it works. C:UsersHaDT>java -version. Show java version in command is install successfully.

1.2 Install Apache Maven

What is Maven? Maven, by Apache, is a Java tool that supports development very effectively. Maven supports almost all tasks: dependency resolution, compile, build, test, packaging. In term of dependency resolution, Maven has become a standard because of the vast number of Java libraries which are compatible with Maven, are built and released using Maven and are available in Apache Central Repository.

Why Maven? In addition to its power, we use Maven in automation test projects for some reasons: • Java and Maven are enough to run tests in non-development environment • Maven gives compatibility with CI/Jenkins system To be clear, let's say you will write, run and debug your tests in Eclipse, but that's not the way a customer or a CI team will run your tests. Automation requires that your project can be run by a command/script without a human in synchronization. In this session you install Maven, create a Maven project, build it and see how Maven manages dependencies for you.

  1. Install Maven: google "Maven download", download and unzip it to a folder like D:Appsmaven

  2. Create new or edit two System environment variables: • Add new system variable named M2_HOME . Set value to maven directory. • Add new variable named M2 . Set it to %M2_HOME%in • Add the path you used for M2 to your PATH.

  3. Check your installation by typing this command in Windows Command Prompt: mvn -version C:UsersHaDT>mvn -version. Show Apache maven version in command is install successfully.

  4. Configure Maven as follows: • Open configuration file: %M2_HOME%confsettings.xml • The file already has sample configuration, you just need to uncomment some lines and edit them. XML comment is   • Edit local repository to some folder in D drive, for example: D:maven-repo • Edit proxy configuration providing host, port, username and password. Here is a configuration sample:

         <settings ...
          
         <localRepository>D:maven-repo</localRepository>
          
         <proxies>
             <proxy>
                 <id>optional</id>
                 <active>true</active>
                 <protocol>http</protocol>
                 <username>hadt</username>
                 <password>***********</password>
                 <host>tc-proxya</host>
                 <port>8080</port>
                 <nonProxyHosts>local.net|some.host.com</nonProxyHosts>
             </proxy>
         </proxies>
          
    
  5. Create a Maven project. First create a folder, for example: D:seleniummvn-prj

  6. In mvn-prj folder, create a file named pom.xml

  7. Edit pom.xml as below:

     <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
         <modelVersion>4.0.0</modelVersion>
         <groupId>Autotest</groupId>
         <artifactId>selenium</artifactId>
         <version>1.0</version>
         <name>My Project</name>
         <packaging>jar</packaging>
         <description>My Project</description>
         
         <properties>
             <maven.compiler.source>1.8</maven.compiler.source>
             <maven.compiler.target>1.8</maven.compiler.target>
             <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
         </properties>
     </project>
    
  8. The initiated pom.xml does nothing but declares a project. Now you use it to add some libraries (dependencies) to your project: Google "testng maven artifact". You have a high chance to find a ready-to-use configuration for testng, like below. Eliminate "scope" tag if you see it:

         <project ...>
          
         <dependencies>
              <dependency>
                 <groupId>org.testng</groupId>
                 <artifactId>testng</artifactId>
                 <version>6.9.4</version>
             </dependency>
         </dependencies>
         </project>
    
  9. Build your project: mvn clean install. The command will download dependencies for the first time so it might take a long time. What it actually does is download testng library from a remote repository and install it to your local repository. The local repository was configured by you: D:maven-repo. The remote repository is defaulted to Apache Central Repo https://mvnrepository.com/, this address can be changed in the future. If the dependency itself depends on other libraries, Maven will automatically resolve dependency chains for you. That's why, as you watch in the console, it downloads many packages.

  10. Go check the testng dependency in your local: it should be located under D:maven-repoorg estng est-ng6.9.4. The two breadcrumbs org and testng are parts of groupId, the next testng is the artifactId, and 6.9.4 is the version. Under this you will find testng-6.9.4.jar.

In the next sessions, we will continues with TestNG, Importing Maven projects...

0