Sunday 21 May 2017

Selenium 3 – Configure and run a program from Firefox and Chrome

 gecko driver selenium, selenium 3 tutorial, webdriver.gecko.driver system property

gecko driver selenium, selenium 3 tutorial, webdriver.gecko.driver system property,
Selenium 3 – Configure and run a program from Firefox and Chrome

Pre-Requisites:
1.       Java 8 or above
2.       geckodriver

Download Links

1. Download Selenium Standalone Server & Selenium Client & WebDriver Language Bindings

http://www.seleniumhq.org/download/

 

 2. Geckodriver
 

https://github.com/mozilla/geckodriver/releases


Creating a program in eclipse using execution environment as javaSE-1.8

 

Add all jar under “selenium-java-3.4.0-lib” folder

 

Add the “client-combined-3.4.0-nodeps.jar”  from selenium-java-3.4.0

Add the “selenium-server-standalone-3.4.0.jar”

 

package com.p1;

import java.util.concurrent.TimeUnit;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;

public class Sel3 {
      
        public static void main(String[] args) {
               
               System.setProperty("webdriver.gecko.driver","C://Selenium//geckodriver.exe"); 
               
             WebDriver driver = new FirefoxDriver();

             driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
            
             driver.navigate().to("http://www.google.com");
            
             driver.close();

        }

}

In above code,  newly added syntax is System.setProperty("webdriver.gecko.driver","the path where the download is presnet"); 

For Chrome:


System.setProperty("webdriver.chrome.driver", "pathofchromedriver\\chromedriver.exe");

Thursday 18 May 2017

UFT- Difference between TO & RO Properties (Get TOProperties, SetTOProperty and GetROProperty)


get ro property in qtp, getroproperty and settoproperty in qtp, getroproperty syntax in uft, settoproperty syntax in qtp



Difference between TO & RO Properties (Get TOProperties, SetTOProperty and GetROProperty)
TO (Test Object): Object stored in Object Repository
RO (Run Time Object): In Object spy these will be under Properties - Identification
GetTOproperties:
It obtains the current values of the object which are stored in object repository.
Note: Add the object in OR
Example:
systemutil.Run "iexplore.exe", "http://www.google.com"
Set oEdit=Browser("Google").Page("Google").WebEdit("q")
Set oTOPro = oEdit.GetTOProperties
Cnt = oTOPro.Count
i=0

Do            
                
sNameoTOPro(i).Name
                
sValueoTOPro(i).Value
                print
sName & " -- " & sValue 
                 i=i+1
Loop While i<Cnt
 
SetTOproperty :
To set the property value of an object in the object repository. Once the execution is complete object property in OR will roll back.
Sample Code
systemutil.Run "iexplore.exe", "http://www.google.com"
Set oEdit=Browser("Google").Page("Google").WebEdit("q") 
oEdit.SetTOProperty "name","z"
sName= oEdit.GetTOProperty("name")
print "Updated Name: " & sName
 
GetROProperty:
This method is used to get value of specified identification property
 
systemutil.Run "iexplore.exe", "http://www.google.com"
Edit=Browser("Google").Page("Google").WebEdit("q").GetROProperty("value")
print Edit
 
Note : We cannot set RO identification properties

Wednesday 17 May 2017

Selenium-Tweaking proxy server for firefox and JavaScriptExecutor




how to bypass proxy in selenium webdriver, how to set proxy in firefox using selenium web driver, JavaScriptExecutor in selenium web driver example

Tweaking proxy server for firefox and JavaScriptExecutor

FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("network.proxy.type", 4);
profile.setPreference("network.proxy.http", "localhost");
WebDriver dr = new FirefoxDriver(profile);

Integer values are only allowed for the "network.proxy.type".

0 - Direct connection/ Proxy not allowed.
1 - Manual proxy
2 - Proxy auto-configuration
4 - Auto-detect proxy
5 - Use system proxy

While there are issues performing click on any element using element.click, JavaScriptExecutor can be used.
package com.p1;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;

public class JavaScriptExecutorEg {


       public static void  main(String[] args)  {


           FirefoxProfile profile = new FirefoxProfile();
           profile.setPreference("network.proxy.type", 4);
           profile.setPreference("network.proxy.http", "localhost");
           WebDriver dr = new FirefoxDriver(profile);

           dr.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

           dr.manage().window().maximize();
           dr.navigate().to("http://www.bing.com/");
           WebElement SignBTn = dr.findElement(By.id("id_l"));
           JavascriptExecutor executor = (JavascriptExecutor)dr;
           executor.executeScript("arguments[0].click();", SignBTn);

       }

}

Tuesday 16 May 2017

UFT- How to find length of string in vbscript without using len function



str="Vadivel Sekar"
nLength= instrrev(str," ")
print (nLength)

Selenium- Use Apache POI to read Excel(.xlsx)

 

how to read data from excel in selenium webdriver using apache poi, how to read xlsx file in selenium webdriver, selenium webdriver excel examples,

 

Use Apache POI to read Excel(.xlsx)

Add: 'xmlbeans-2.x.x' and 'poi-ooxml-schemas-3.x-xxx' jar’s.

package com.p1;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Iterator;

import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

public class Excel_Read {
       
       public void readExcel (String filePath) {
              InputStream ExcelToRead = null;
              XSSFWorkbook wb = null;
              try {
                     ExcelToRead = new FileInputStream(filePath);
                     wb = new XSSFWorkbook(ExcelToRead);
              } catch (FileNotFoundException e) {
                     e.getMessage();
              } catch (IOException e) {
                     e.getMessage();
              }

              XSSFSheet sh = wb.getSheet("Sheet1");
              XSSFRow row;
              XSSFCell cell;
              
              //Run all the rows
              Iterator rows = sh.rowIterator();

              while (rows.hasNext()) {
                     row = (XSSFRow) rows.next();
                     
                     //Run all the cell of row
                     Iterator cells = row.cellIterator();

                     while (cells.hasNext()) {
                           cell = (XSSFCell) cells.next();

                           if (cell.getCellType() == XSSFCell.CELL_TYPE_STRING) {
                                  System.out.print(cell.getStringCellValue() + " ");
                           } else if (cell.getCellType() == XSSFCell.CELL_TYPE_NUMERIC) {
                                  System.out.print(cell.getNumericCellValue() + " ");
                           } else if (cell.getCellType() == XSSFCell.CELL_TYPE_BOOLEAN) {
                                  System.out.print(cell.getBooleanCellValue() + " ");
                           }else if (cell.getCellType() == XSSFCell.CELL_TYPE_FORMULA) {
                                  System.out.print(cell.getCellFormula() + " ");
                           }else if (cell.getCellType() == XSSFCell.CELL_TYPE_ERROR) {
                                  System.out.print(cell.getErrorCellString() + " ");
                           }                          
                     }
                     System.out.println();
                     try {
                           ExcelToRead.close();
                     } catch (IOException e) {
                           e.printStackTrace();
                     }
              }
       }
       
       public static void main(String[] args) {
              Excel_Read excelRead = new Excel_Read();
              excelRead.readExcel("D:\\Test.xlsx");    
       }
       

}

Monday 15 May 2017

UFT- Reverse string or line without in build functions such as strReverse or Mid

UFT- Reverse string or line without in build functions such as strReverse or Mid

how to reverse a string using split function in vbscript, reverse a string using regular expression in vbscript, reverse a string without using inbuilt function in vbscript


Dim Arr2(0)

'Input sting
sKey="Reverse string or line without inbuilt functions such as strReverse or Mid"

'Array to keep individual strings
Arr1= split (sKey, " ")
k=ubound(Arr1)

For i = 0 To K

    'Store the single string in an array
    Arr2(0)=Arr1(i)
    sKey1=Arr2(0)

    'Store the single string characters in a an array
    Set oRegExp= New RegExp
    oRegExp.Global = True
    oRegExp.Pattern = ".{1}"

    Set col=oRegExp.Execute(sKey1)

    For l = 0 To col.Count-1
        ReDim Preserve Arr3(l)
        Arr3(l)=col.Item(l)
    Next

    'Store the reversed single string
    For j = ubound(Arr3) To 0 Step -1
        rev=rev & Arr3(j)
    Next

    'String the reversed whole input string
    rev = rev & " "
Next
print (rev)

Set oRegExp=Nothing
Set col    =Nothing