Tuesday, 24 March 2015

Running testng class file from cmd prompt and jenkins

we can run the testng class files through eclipse by adding the testng libraries in Build path.
If we need to run the same testng class files from command prompt and through any tools we could do so by adding the testng libraries to the CLASSPATH variable. or by giving the path with -cp option available in java. Also can add any jar files which are referred in the class files.



set CLASSPATH = %CLASSPATH%;D:\Are\Sel\Ecom_project\TestNG\testng-6.8.jar

D:\Area\Sel\>java org.testng.TestNG testng.xml
[TestNG] Running:
  D:\Are\Sel\Ecom_project\src\scripts\testng.xml

TestNG is working fine
===============================================
Suite1
Total tests run: 1, Failures: 0, Skips: 0
===============================================



To run the same testng scripts via Jenkins can add the CLASSPATH variable at master level or at node level specifying the path of the jar files. Represented the same in below snaps.










 

Friday, 13 March 2015

Selenium grid implementation on two different machines and browsers


This post guides us for the GRID implementation of Selenium where we launch a grid server and register two nodes in two different machines.

Here we launch the HUB in machine1 and start node 1 with two instances of chrome browser and node 2 with two instances of Firefox.


To start Hub

HUB: Machine 1

java -jar selenium-server-standalone-2.43.1.jar -role hub -port 4455

To start nodes

Node : Machine 2 (launching only chrome browser of 2 instances)
 

java -jar selenium-server-standalone-2.43.1.jar -role node -hub http://<ip_of_hub_machine:4455>/grid/register -port 5557 -Dwebdriver.chrome.driver=chromedriver.exe -browser browserName=chrome,platform=WINDOWS,maxInstances=2

Node: Machine 3 (
launching only firefox browser of 2 instances)

java -jar selenium-server-standalone-2.45.0.jar -role node -hub http://
<ip_of_hub_machine:4455>/grid/register -port 5587 -browser browserName=firefox,platform=WINDOWS,maxInstances=2

After launching hub and nodes we can see the instances of the nodes in grid console under URL http://localhost:4455/grid/console

















 

Sample program:

import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.Platform;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;

public class GridTest {

    static DesiredCapabilities dc = null;
    WebDriver driver;

    public GridTest() throws MalformedURLException {
        dc = new DesiredCapabilities();
       

    }

    public void firefox() throws MalformedURLException, InterruptedException {
        dc.setBrowserName(DesiredCapabilities.firefox().getBrowserName());
        excute("firefox");
    }

    public void chorme() throws MalformedURLException, InterruptedException {
        dc.setBrowserName(DesiredCapabilities.chrome().getBrowserName());
        excute("chrome");
    }

    public void excute(String browsername) throws MalformedURLException, InterruptedException {
       
        dc.setPlatform(Platform.WINDOWS);
        driver = new RemoteWebDriver(new URL(
                "http://<ip_of_hub_machine:4455>/wd/hub"), dc);
        driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
        System.out.println("In "+browsername);
        driver.get("https://www.google.co.in/");
        System.out.println(driver.getCurrentUrl());
        driver.quit();
    }

    public static void main(String[] args) throws MalformedURLException, InterruptedException {
        // TODO Auto-generated method stub

        GridTest t1 = new GridTest();

        t1.firefox();
        t1.chorme();

    }
}




Firefox in Machine 1

Chrome in Machine 2

Monday, 29 December 2014

Few selenium webdriver exceptions


NoAlertPresentException - Occurs when Code exists to handle the alert, but there is no alert present in real time during execution. 
UnexpectedAlertPresentException - When there is a alert present which is not handled by the  code, this exception occurs. 
NoSuchElementException - When the Web element doesn't match with the element present in the browser or when the selenium tries to identify the specified element when its actually not  completed  loading the browser. 
NoSuchFrameException - Thrown when Code existsto handle a frame, but the frame didn't actually present execution. 
NoSuchWindowException- Occurs when Code exists to navigate to new window using driver.switchTo().window(session id) , but there is no window exists with the referenced window element. 
StaleElementReferenceException - Occurs when the refereed element is no more on DOM or the element has been deleted entirely by navigating to different page or refreshing the page. 
ElementNotVisibleException - This occurs when the element actually present in the DOM, however not visible or its in hidden to be referred.

Saturday, 27 December 2014

Password field value entered twice on using selenium webdriver

While running webdriver script to login to webpage by provide the username and password credentials, you may notice that the password field is actually entered twice once you enter the username and then entering the password.

The reason is when you have logged in before via manually/script and if the auto save feature of user name and passwords are enabled and saved this may occur.

If Auto save feature is enabled for username and password, after entering the username via script and tabbing out to enter the password itself put the saved password.

Here the password is 7 characters, but 14 characters has been updated.

Password typed twice


Solution:

1. Remove the auto save of user name and password feature at browser level
2. Or do a clear on the fields before entering the values.