Wednesday, September 4, 2013

Selenium : HighLighting WebElements

Selenium : WebDriver 2.0 HighLight


 public static void highlightElement(WebDriver driver, WebElement element)
 {
   JavascriptExecutor js = (JavascriptExecutor) driver;
   for (int i = 0; i < 3; i++)
   {       
    js.executeScript("arguments[0].setAttribute('style', arguments[1]);",element, "color: yellow; border: 4px dashed orange;");
     try
     {
      Thread.sleep(150);
      } catch (InterruptedException e) {
       e.printStackTrace();
       }
          js.executeScript("arguments[0].setAttribute('style',arguments[1]);",element, "");
      try
      {
        Thread.sleep(150);
        } catch (InterruptedException e) {
          e.printStackTrace();
           }
         }
 js.executeScript("arguments[0].setAttribute('style', arguments[1]);",element, "");
   }

}






Here is the full program implementation of the same :


import javax.swing.JOptionPane;

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;


public class Sample1
{

       public static void main(String[] args)  
       {
              WebDriver oDriver;
              WebElement oTitle;        
              String sRes="Not Found";
             
              oDriver=new FirefoxDriver();
              oDriver.get("https://www.google.co.in");
              oTitle=oDriver.findElement(By.id("pmocntr2"));//gs_htif0
             
              if (oTitle!=null)
              {
                      sRes="Found";
                      highlightElement(oDriver,oTitle);      
              }     
             
              JOptionPane.showMessageDialog(null, sRes);                   
       }
      
       public static void highlightElement(WebDriver driver, WebElement element)
       {
               JavascriptExecutor js = (JavascriptExecutor) driver;
           for (int i = 0; i < 3; i++)
           {        
               js.executeScript("arguments[0].setAttribute('style', arguments[1]);",element, "color: yellow; border: 4px dashed orange;");
               try
               {
                           Thread.sleep(150);
                     } catch (InterruptedException e) {
                           e.printStackTrace();
                     }
               js.executeScript("arguments[0].setAttribute('style', arguments[1]);",element, "");
               try
               {
                           Thread.sleep(150);
                     } catch (InterruptedException e) {
                           e.printStackTrace();
                     }
           }
           js.executeScript("arguments[0].setAttribute('style', arguments[1]);",element, "");
       }

}


Selenium : Check Variable Type

Selenium : Check Variable Type


class Typetester 
 {
    void printType(byte x) {
        System.out.println(x + " is an byte");
    }
    void printType(int x) {
        System.out.println(x + " is an int");
    }
    void printType(float x) {
        System.out.println(x + " is an float");
    }
    void printType(double x) {
        System.out.println(x + " is an double");
    }
    void printType(char x) {
        System.out.println(x + " is an char");
    }
}
 
 
 
Then:
 

Typetester t = new Typetester();
t.printType( yourVariable );
 

Selenium : Cover basic Browser opening and using Xpath


Selenium : Cover basic Browser opening and using Xpath 


Good Post From Gautirao's Blog





package my.example.test;
import java.util.concurrent.TimeUnit;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;

public class BasicAppTest {

WebDriver currentBrowser;

@Test
public void runTestForInternetExpolrer()
 {
// Instantiate internet explorer browser instance
this.currentBrowser =new InternetExplorerDriver();
this.clickOnSubmitButton();
}

@Test
public void runTestForFireFox()
 {
this.currentBrowser = new FirefoxDriver();
this.searchSomethingOnGoogle();
}

private void searchSomethingOnGoogle() 
{
 
// this ensure the driver queries dom  for 20 seconds before throwing //NoSuchElementFoundException if an element is not found
this.currentBrowser.manage().timeouts().implicitlyWait(20,TimeUnit.SECONDS);
//Types http://google.co.uk in the address bar and hits enter
this.currentBrowser.get("http://google.co.uk");
//findElement method of the driver takes and By instance . We can search for the element //using By.id, By.xpath,By.name etc
WebElement searchInput = this.currentBrowser.findElement(By.xpath("//input[@name='q']"));
searchInput.sendKeys("Hello World");
WebElement myButton = this.currentBrowser.findElement(By.xpath("//input[@name='btnG' and @value='Google Search']"));
myButton.click();
}

@After
public void tearDown() throws Exception 
{
this.currentBrowser.quit();
}
}

Thursday, July 11, 2013

QTP : Installing Infragistics Test Advantage 12.2 for Qtp 11

How to make Infragistics test advantage working for you


  1. Install Qtp , select dot net addin  during installation.
  2. Once Qtp is installed.Open Qtp to make sure it has installed properly.
  3. Install Infragistics test Advanatge 12.2 and select CLR 4.0   (in our case ) ..... :-)
  4. Open  Sample applications (Documents and settings > search Type "infragistics ")
  5. Try recording and spying .

Wednesday, July 10, 2013

Qtp : Setting Timers , Object Sync Timeout and Iterations in Run Time

 

Timer Methods
  1. Continue Method - Continue counting
  2. Reset Method - Reset timer
  3. Start Method - Starts Timer
  4. Stop Method - Stops Timer

Object Sync Timeout
 
msgbox "current timeout "& Setting("ObjectSyncTimeOut")
Setting("DefaultTimeout")=5000


msgbox "new timeout "& Setting("ObjectSyncTimeOut")




Example :
  Setting("DefaultTimeout")=5000
   MercuryTimers("T1").Start
   If oObj.exist then Reporter.ReportEvent micPass,"title","Info"
   MercuryTimers("T1").Stop

   print MercuryTimers("T1").ElapsedTime