Friday, November 13, 2015

Steps to install and setup Selenium IDE

Steps to install and setup Selenium IDE

PRE REQUISITE - Install latest version of Java.

Selenium IDE - is a Firefox extension. It is generally used to record and playback the tests. We can simply record the tests like recording a video and play the tests like playing the recorded video

1. Launch Firefox Browser
3. Download the latest version of Selenium IDE 


 4. Now Install Selenium Standalone server



5. Restart Firefox
6. Open Toolbar -> Customize. Drag and drop Selenium IDE to toolbar

























7. All set, now open Selenium plugin and Click on red button to start record and play.


Thursday, November 12, 2015

Steps to setup Java and Maven environment in Bash profile

Follow below steps
1) Start the Terminal app.
2) Open bash profile - 
$ vi ~/.bash_profile
2) Press key 'i' from keyboard to Insert text in bash profile
3) Insert Java and maven environments -
export M2_HOME=/usr/local/apache-maven/apache-maven-3.3.3
export M2=$M2_HOME/bin
export PATH=$M2:$PATH
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home
export PATH=$JAVA_HOME:$PATH

4) Press key 'Esc
4) Press key ':wq!' to save and quit bash profile
5) Now run source command to refresh
source ~/.bash_profile
6) Verify Java and Maven works fine
Run command - echo $JAVA_HOME
The response should be something like- /Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home
Run command - mvn --version
The response should be something like-
Apache Maven 3.3.3 (7994120775791599e205a5524ec3e0dfe41d4a06; 2015-04-22T04:57:37-07:00)
Maven home: /usr/local/apache-maven/apache-maven-3.3.3
Java version: 1.8.0_60, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.11.1", arch: "x86_64", family: "mac"

7) Lastly, run maven project by cd into the Java project directory (enter your project path)- 
cd /Users/[User]/Documents/workspace/Hybrid_TestNG

and run command mvn test
This should run the project successfully. 

Remember, each time you start new session, you will have to source bash profile by running below command - 

source ~/.bash_profile

---------------------------------------------------------------------------------

Friday, October 9, 2015

How to have all jars from Maven into Eclipse?

How to have include jars from Maven into Eclipse?


Assuming Project has been imported to eclipse
(If not sure, view previous post at http://selenium2testing.blogspot.com/2015/10/what-is-maven-and-how-to-setup-maven-in.html and
http://selenium2testing.blogspot.com/2015/10/create-mvn-project.html)

Find .M2 repository path (If not sure, View previous post at http://selenium2testing.blogspot.com/)
Copy the .M2 repository path. Ex - /Users/[user]/.m2/repository

Open Eclipse
Import this project
Click on Properties
Click on 'Java Build Path'
Click on Libraries Tab
Click on 'Add Variable' button
Click 'Configure Variables' button
Click New button
Give Name ' M2_REPO' . //Make sure its in caps
Give Repo Path - /Users/[user]/.m2/repository



Run command - mvn eclipse:eclipse is encountering issues with downloading of dependencies

                                                                                                                  

Where is .m2 folder maven repository on mac?

Where is .m2 folder maven repository on mac? 

If you search directly it won't appear so please follow as below steps to see .M2 repository path.
Go-> Find folder ->  type this ~/.m2 and click go
"~/.m2 "

Create MVN Project, Update POM and convert it into Eclipse project

Open terminal / cmd prompt

cd into workspace location  - cd /Users/[username]/Documents/workspace
2. mvn archetype:generate
3. Now hit enter when you will see, 
Choose a number or apply filter (format: [groupId:]artifactId, case sensitive contains): 657:  
4. Again hit enter when you see ,
Choose a number: 6: 
5. Enter package name that you are using in your project. ex -
Define value for property 'groupId': : com.selenium.framework.hybrid
6. Enter project name ex -
Define value for property 'artifactId': :  Hybrid_TestNG
7. Enter version 1. ex - Define value for property 'version':  1.0-SNAPSHOT: :  1
8. Just hit enter
Define value for property 'package':  com.selenium.framework.hybrid: : 
9. Hit enter to confirm properties
Confirm properties configuration:
groupId: com.selenium.framework.hybrid
artifactId: Hybrid_TestNG
version: 1
package: com.selenium.framework.hybrid
 Y: : 

You should now see ‘BUILD SUCCESS’ message

Next, Go to Workspace location, Click on the maven project and open pom.xml

Copy paste below dependencies into the pom.xml.. 
Note - Update dependencies versions.

<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>com.selenium.framework.hybrid</groupId>
  <artifactId>Hybrid_TestNG</artifactId>
  <version>1</version>
  <packaging>jar</packaging>

  <name>Hybrid_TestNG</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
</project>

 <!-- Selenium -->
  <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>2.47.1</version>
      </dependency>
   <!-- POI -->
   <dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.13</version>
   </dependency>
   <dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.13</version>
   </dependency>
  <dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml-schemas</artifactId>
<version>3.13</version>
  </dependency>
  <dependency>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
<version>1.1</version>
</dependency>

<dependency>
<groupId>org.apache.xmlbeans</groupId>
<artifactId>xmlbeans</artifactId>
<version>2.6.0</version>
</dependency>
<!--  Log4J  -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<!-- JavaMail  -->
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4</version>
</dependency>
  </dependencies>
    <build>
        <plugins>
            
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-report-plugin</artifactId>
              <configuration>
                <suiteXmlFiles>
    <suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
</suiteXmlFiles>
                    <!-- Skip the normal tests, we'll run them in the integration-test phase -->
                    <skip>true</skip>               
                 </configuration>               
            </plugin>
            </plugins>
    </build>
 <reporting>
    <plugins>
    <!-- TestNG-xslt related configuration. -->
      <plugin>
        <groupId>org.reportyng</groupId>
        <artifactId>reporty-ng</artifactId>
        <version>1.2</version>
        <configuration>
          <!-- Output directory for the testng xslt report -->
          <outputdir>/target/testng-xslt-report</outputdir>
          <sorttestcaselinks>true</sorttestcaselinks>
          <testdetailsfilter>FAIL,SKIP,PASS,CONF,BY_CLASS</testdetailsfilter>
          <showruntimetotals>true</showruntimetotals>
        </configuration>
      </plugin>
    </plugins>
  </reporting>  
 <pluginRepositories>
    <pluginRepository>
      <id>reporty-ng</id>
      <url>https://github.com/cosminaru/reporty-ng/raw/master/dist/maven</url>
    </pluginRepository>
  </pluginRepositories>
  
</project>

Lastly, to use Maven project as Eclipse project, you need to convert by running following command - 


mvn eclipse:eclipse

Once complete, you should see 'BUILD SUCCESS' message.

You can now, Import this Project in your Eclipse

What is maven and how to setup maven in mac OS X yosemite

MAVEN


Maven is a "build management tool", it is for defining how your .java files get compiled to .class, packaged into .jar (or .war or .ear) files, (pre/post)processed with tools, managing your CLASSPATH, and all others sorts of tasks that are required to build your project. It is similar to Apache Ant or Gradle or Makefiles in C/C++, but it attempts to be completely self-contained in it that you shouldn't need any additional tools or scripts by incorporating other common tasks like downloading & installing necessary libraries etc.
It is also designed to around "build portability" so that you don't get issues that the same code with the same build script works on one computer but not on another one (this is a known issue, we have VMs of Windows 98 machines since we couldn't get some of our Delphi applications compiling anywhere else). Because of this, it is also the best way to work on a project between people who use different IDEs since IDE-generated Ant scripts are hard to import into other IDEs, but all IDEs nowadays understand and support Maven (IntelliJ, Eclipse, and NetBeans). Even if you don't end up liking Maven, it ends up being the point of reference for all other modern builds tools.

Why you should use it
There are three things about Maven that are very nice.
1 Maven will (after you declare which ones you are using) download all the libraries that you use and and the libraries that they they use for you automatically. This is very nice, and makes dealing with lots of libraries ridiculously easy. This lets you avoid "depenendency hell". It is similar to Apache Ant's Ivy.
2 It uses "Convention over Configuration" so that by default you don't need to define the tasks you want to do. You don't need to write a "compile", "test", "package", or "clean" step like you would have to in Ant or a Makefile. Just put the files in the places Maven expects them and it should work off of the bat.
3 Maven also has lots of nice plug-ins that you can install that will handle many routine tasks from generating Java classes from an XSD schema using JAXB to measuring test coverage with Cobertura. Just add them to your pom.xml and they will integrate with everything else you want to do.
The initial learning curve is steep, but (nearly) every professional Java developer uses Maven or wishes they did. You should use Maven on every project although don't be surprised if it takes you a while to get used to it and that sometimes you wish you could just do things manually, since learning something new sometimes hurts. However, once you truly get used to Maven you will find that build management takes almost no time at all.


How to set up MAVEN in MAC OX X

Open terminal and run command - Java -version Enter the same path in Java_Home command
export JAVA_HOME=`/usr/libexec/java_home -v 1.8`
To confirm path run this - echo $JAVA_HOME 
# JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home

1. Go to the apache maven website and download the latest stable binary file which is Maven 3.3.3
2. Extract the zip or the tar ball and copy the entire folder to the /usr/local/apache-maven directory.
3. Please create the apache-maven folder under /usr/local directory. So, the final path will look something like this : /usr/local/apache-maven/apache-maven-3.3.3
4. Now, open the terminal and go to the above location by typing the following command: cd /usr/local/apache-maven/apache-maven-3.3.3
5. Now run the following commands in a sequential order:
$export M2_HOME=/usr/local/apache-maven/apache-maven-3.3.3
$export M2=$M2_HOME/bin
$export PATH=$M2:$PATH
6. Now check whether you have the proper JAVA_HOME environment variable set on your machine by running the following command : $echo $JAVA_HOME
It should look something like this:
/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
7. You are done with the installation. Now, simply type mvn –version to check if it echoes the details of the maven version installed on your system. You will see the following if the maven is successfully installed.

Apache Maven 3.3.3 (ea8b2b07643dbb1b84b6d16e1f08391b666bc1e9; 2014-02-14T23:07:52+05:30)
Maven home: /usr/local/apache-maven/apache-maven-3.3.3
Java version: 1.6.0_65, vendor: Apple Inc.
Java home: /Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8 

OS name: "mac os x", version: "10.10.5", arch: "x86_64", family: "mac"

cd into Maven project if this doesn't work - cd /Users/[Users]/Documents/workspace/Hybrid_TestNG and try again

Thursday, July 19, 2012

How to handle/switch windows, Tabbed browser and Pop ups in Selenium 2 Webdriver



Below is java code which explains how window switching/different windows(Tabs or Popups) are handled in Selenium. This example is performed on expedia.com.

Copy paste the below code in eclipse and run.

Choose Easy Way



Note 1 - Selenium opens all the tab windows as POPUPS all the time.
Note 2 - Each window has a unique id which helps in its identification and therefore switching.


import java.util.Iterator;
import java.util.Set;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;


public class HandlingBrowser {


public static void main(String[] args) throws InterruptedException {

WebDriver driver = new FirefoxDriver();

System.out.println("************Open Expedia website************");
driver.get("http://www.expedia.com");

//This will get window ID's
Set<String> windowIds = driver.getWindowHandles();
Iterator<String> iter = windowIds.iterator();
while(iter.hasNext()){
System.out.println("This is First Id - " + iter.next());

}

//Click on Feedback
driver.findElement(By.xpath(".//*[@id='nav-tool-feedback']")).click();

windowIds = driver.getWindowHandles();
iter = windowIds.iterator();
while(iter.hasNext()){
System.out.println("This is Second Id - " + iter.next());
}

windowIds = driver.getWindowHandles();
iter = windowIds.iterator();
String mainWindowId = iter.next();
String tabbedWindowId = iter.next();

driver.close();

System.out.println("************ Windows Switching has been handled successfully************");
//This will switch window control to the other window
driver.switchTo().window(tabbedWindowId);
driver.findElement(By.xpath(".//*[@id='main']/tbody/tr[2]/td[2]/table/tbody/tr[2]/td[1]/input")).click();
driver.findElement(By.xpath(".//*[@id='submitImage']")).click();

windowIds = driver.getWindowHandles();
iter = windowIds.iterator();

driver.close();
System.out.println("************Test successful************");

}

}