вівторок, 10 червня 2014 р.

How to set path to webdriver ie driver in pom.xml

How to set path to webdriver ie driver in pom.xml?
Selenium give us a possibility to run the same test in different browsers (FireFox, Internet Explorer, Safari, Opera, Chrome), only one thing you should do before that. You should say to Selenium where you driver browser is located, download needed driver. And as usual we have a several ways to make it, I give you an example for IE Driver Server.

1. First and easy way is: just add your driver location to %PATH% environment variable.
2. Second: create environment variable webdriver.ie.driver and set path where you placed driver. After that you can instanciate webdriver in the code
3. Third: or you can set path to driver instantly in the code
 ...  
 File file = new File("C:/Selenium/iexploredriver.exe");  
 System.setProperty("webdriver.ie.driver", file.getAbsolutePath());  
 WebDriver driver = new InternetExplorerDriver();   
 ...  
4. Forth: or you can set driver via line argument when launch tests in command line
 C:\> java -jar -Dwebdriver.ie.driver=""C:/Selenium/iexploredriver.exe"   
5. Fifth: but if we are talking about automation I prefer CI TeamCity, SVN and maven tool. The lovely maven-surefire-plugin give us a possibility to launch tests using maven goal test. Set path to driver as system properties for this plugin.
 ...  
 <webdriver.ie.driver>${basedir}\external_resources\${iedriverserver.version}\IEDriverServer.exe</webdriver.ie.driver>  
 ...  
 <plugin>  
   <groupId>org.apache.maven.plugins</groupId>  
   <artifactId>maven-surefire-plugin</artifactId>  
   <inherited>true</inherited>  
     <configuration>  
       <systemPropertyVariables>  
         <webdriver.ie.driver>${webdriver.ie.driver}</webdriver.ie.driver>  
       </systemPropertyVariables>  
       <testFailureIgnore>true</testFailureIgnore>  
       <includes>  
         <include>**/*Stories.java</include>  
       </includes>  
     </configuration>  
 </plugin>  
 ...  

Useful links:

https://code.google.com/p/selenium/wiki/InternetExplorerDriver

пʼятниця, 9 травня 2014 р.

How to set custom system environment variables using Maven?

How to set custom system environment variables using Maven?
Interenet replete with questions about how to set the system variables using Maven pom.xml and generously distributed tips:
on how to read these same system variables using Maven,
or how to override the variables via the command line parameters during launching mvn.

But how to set system variables via pom.xml?

I found at least one way to set environment variables using the maven-antrun-plugin (with help of this plugin you can do almost everything that and with help of command line shell like cmd)
You have the opportunity same as to specify a specific path to directory and as assign specific values, to become fully acquainted with this wonderful opportunity please check out with the manual
And I also give the simple example:

 <plugin>  
  <groupid>org.apache.maven.plugins</groupid>  
  <artifactid>maven-antrun-plugin</artifactid>  
  <version>${antrun.apache.version}</version>  
  <executions>  
  <execution>  
   <id>copy-app-set-system-variables</id>  
   <phase>pre-clean</phase>  
   <configuration>  
    <target>  
    <property environment="env">  
     <exec executable="${basedir}\external_resources\scripts\copy_app.cmd">  
     <env key="JAVA_HOME" path="${env.JAVA_HOME}" />  
     <env key="JAVA_JRE" path="${env.JAVA_HOME}\bin" />  
     <env key="LOG4J" path="${basedir}\external_resources\apache-tomcat-6.0.37_project_settings\log4j.xml" />  
     <env key="TOMCAT_HOME" path="${basedir}\external_resources\apache-tomcat-6.0.37" />  
     <env key="CATALINA_OPTS" value="-server -Xmx2048m -Xms1024m -XX:MaxPermSize=512m" />  
     <env key="env" value="${env.ENV}" />  
     <env key="CATALINA_HOME" path="${basedir}\external_resources\apache-tomcat-6.0.37" />  
     </exec>  
    </property>  
    </target>  
   </configuration>  
   <goals>  
    <goal>run</goal>  
   </goals>  
  </execution>  
  </executions>  
 </plugin>  



useful links:
Ant Tasks Manual
Maven Properties Guide
Maven Properties