Friday 28 December 2012

"Failed to start: SocketListener0@0.0.0.0:4444" while Selenium RC Test Execution

Many of us face this common error while trying to execute tests after a successful test run. This is because of the Selenium server that starts on port 4444 and fail to shutdown, throwing an error message on forthcoming tests.

WARN - Failed to start: SocketListener0@0.0.0.0:4444


There are couple of alternate ways to overcome this

#1
1| Open a new tab from your web browser.
2| Copy and paste the below URL.
http://localhost:4444/selenium-server/driver/?cmd=shutDownSeleniumServer
3| Soon-after hitting Enter button, a get response 'okok' will be obtained; it make sure that the Selenium server is shutdown on port 4444.








4| Now, its time to re-run your test on port 4444.

#2
1| Open cmd
2| Force Selenium server to listen port other other than 4444. i.e., 5555 or other
java -jar selenium-server-standalone-x.xx.x.jar -p 5555

Handling browser-level authentication | Selenium


Whenever a site prompts for an username and password, make use of the following script to override such authentication,

driver.get("http://username:password@site.com/page");

e.g., driver.get("http://admin:root@site.com/page");

Thursday 27 December 2012

Maven | Selenium Test Execution

Text in ORANGE has to be edited by users or mentioned important through-out this BLOG

Maven is the Central Repository [like a server], where it can store the jar files. Here, we use Maven as a test execution framework.

Set Maven Environment

1| Download Maven apache-maven-x.x.x-bin.zip
2| Unzip the folder under C:\Program Files\
3| Create a new System Variable under 'Environment Variables'.
Variable: M2_HOME
Value: C:\Program Files\apache-maven-3.0.4


4| Add Maven path under the variable name, 'Path'
Variable value: %M2_HOME%\bin


5| Make sure that maven is configured properly.
6| Open cmd prompt.
7|Type 'mvn -version'


  
Configure Maven on Eclipse

1| Install Maven plugin in Eclipse IDE using "Eclipse Marketplace.."
2| Create a new 'Maven project' in Eclipse IDE.
Right click on Package Explorer > New > Other
3| Type 'maven' and Click Next.



4| Select the Project location and Click Next.
5| Select an Archetype as shown below and Click Next.


6| Enter the 'Group Id' and 'Artifact Id' and Click Finish.



7| Now, you will see a POM file created below target folder.



Modify POM.xml

1| Create a new class file under src/test/java; Here it is 'AppTest.java'
2| Open the POM xml file.
3| Add the following dependencies for a simple test execution.
JUnit, TestNG, selenium-server, selenium-java

This is how the POM looks like,

<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>mvngrp</groupId>
  <artifactId>mvnart</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>mvnart</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>4.11</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.testng</groupId>
      <artifactId>testng</artifactId>
      <version>6.8</version>
    </dependency>   

    <dependency>
      <groupId>org.seleniumhq.selenium</groupId>
      <artifactId>selenium-server</artifactId>
      <version>2.35.0</version>
    </dependency>
    <dependency>
      <groupId>org.seleniumhq.selenium</groupId>
      <artifactId>selenium-java</artifactId>
      <version>2.35.0</version>
    </dependency>

 
  </dependencies>
</project>


4| The build libraries mentioned under dependencies will automatically added into the project soon-after saving the POM.xml


Maven Test Execution

There are couple of ways to execute Maven Test.

#1
1| In eclipse, right click on the POM.xml > Run As > Maven install


2| In-order to clean existing test results, it is important to 'Maven clean' before executing a new test.
right click on the POM.xml > Run As > Maven clean

#2
1| Open cmd prompt.
2| Move into the project folder.
3| Type 'mvn clean'
4| Type 'mvn install' for test execution



Note| If you've trouble on creating Maven projects using maven-archetype-quickstart [Eclipse],
1| Open cmd prompt
2| Locate the workspace
3| Enter the below to create a maven project
mvn archetype:generate -DgroupId=yourgroupid -DartifactId=yourartifactid -DarchetypeArtifactId=maven-archetype-quickstart