Thursday, July 11, 2013

Right click in Selenium Web driver



package softwaretesting-guru;

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.interactions.Action;
import org.openqa.selenium.interactions.Actions;

public class RightClick {

       public static void main(String[] args) {
              //Launch the browser
              WebDriver driver=new FirefoxDriver();
              //Enter URL
              driver.get("http://www.gmail.com");
              //Enter the data in gmail username
              driver.findElement(By.id("Email")).sendKeys("Selenium");
              //rightclick on gmail username field
             
              //WebElement represents any HTML element.
              WebElement elementRC = driver.findElement(By.id("Email"));
              //Use this class rather than using the Keyboard or Mouse directly.
               Actions builder = new Actions(driver);
              // Performs a context-click at the current mouse location
               Action rClick = builder.contextClick(elementRC).build();
               //A convenience method for performing the actions without calling build() first.
               rClick.perform();

       }

}

Assertions in Selenium



package com.softwaretesting_guru.help;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.server.SeleniumServer;

import com.thoughtworks.selenium.DefaultSelenium;
import com.thoughtworks.selenium.SeleneseTestCase;

@SuppressWarnings("deprecation")
public class Assertions extends SeleneseTestCase{

       @SuppressWarnings("deprecation")
       @Before
       public void setUp() throws Exception {
              //Starting the server
              SeleniumServer ss=new SeleniumServer();
              ss.start();
              selenium=new DefaultSelenium("localhost",4444,"firefox","http://www.gmail.com");
              selenium.start();
       }

       @After
       public void tearDown() throws Exception {
       }

       @SuppressWarnings("deprecation")
       @Test
       public void test() throws InterruptedException {
              selenium.open("/");
              selenium.waitForPageToLoad("70000");
              Thread.sleep(4000);
              selenium.windowMaximize();
              //Verifying the signin button
              assertTrue(selenium.isElementPresent("id=signIn"));
              //Click on the signin button
              //the below line will pause for 4000 seconds for each line from here
              selenium.setSpeed("4000");
             
              selenium.click("id=signIn");
              //Verifying the warning message displayed when username is not given.
              assertEquals("Enter your email address.",selenium.getText("id=errormsg_0_Email"));
              //Verifying whether the username control is present or not..
              assertTrue(selenium.isElementPresent("id=Email"));
              //Entering the username to username field
              selenium.type("id=Email","selenium");
              //verify whether entered username has been displayed or not by getting the username
              assertEquals("selenium",selenium.getValue("id=Email"));
              //Click on sigin button
              selenium.click("id=signIn");
              //Verifying the warning message displayed when password is not given.
              assertEquals("Enter your password.",selenium.getText("id=errormsg_0_Passwd"));
              //Verifying whether the password control is present or not..
              assertTrue(selenium.isElementPresent("id=Passwd"));
              //Entering the password to password field
              selenium.type("id=Passwd","selenium");
              //verify whether entered password has been displayed or not by getting the password
              assertEquals("selenium",selenium.getValue("id=Passwd"));
             
             
             
       }

      
       }



Tuesday, June 25, 2013

Create log file in QTP

Function LogintoFile(strCode, strMessage) Dim objFS Dim objFile Dim objFolder Dim strFileName Set objFS = CreateObject("Scripting.FileSystemObject") If Not objFS.FolderExists(objFS.GetAbsolutePathName(".") & "\log") Then Set objFolder = objFS.CreateFolder(objFS.GetAbsolutePathName(".") & "\log") End If strFileName = objFS.GetAbsolutePathName(".") & "\log\" & year(date) & month(date) & day(date) & ".log" Set objFile = objFS.OpenTextFile(strFileName, 8, True) On Error Resume Next objFile.Write Date & ", " & Time & ", " & strCode & ", " & strMessage & vbcrlf ' disable the on error statement On Error GoTo 0 objFile.Close Set objFS = Nothing End Function 'Function Calling : call LogintoFile("Fail","Invalid User Credentials")

Monday, June 17, 2013

Handling web table in Web driver


import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.List;

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.support.ui.Select;

public class Kesineni {

    WebDriver driver;
    public void test() throws InterruptedException {
    	//launch the firefox browser
        driver=new FirefoxDriver();
        //enter URL Kesinenitravels application
        driver.get("http://www.kesinenitravels.com");
        //Select source 
        new Select(driver.findElement(By.id("ctl00_cpEndUserMain_ucSearchRoute_ddlSource"))).selectByVisibleText("CHENNAI");
        Thread.sleep(4000);
        //Select Destination
        new Select(driver.findElement(By.id("ctl00_cpEndUserMain_ucSearchRoute_ddlDestination"))).selectByVisibleText("HYDERABAD");
        Thread.sleep(4000);
        //Click on Search button
        driver.findElement(By.id("ctl00_cpEndUserMain_ucSearchRoute_ibtnSearch")).click();
        Thread.sleep(7000);
        //Get the text of ServiceNo's
        List ele=driver.findElements(By.xpath("//table[@id='ctl00_cpEndUserMain_ucOnwardJourney_gvServices']/tbody/tr/td[2]"));
        System.out.println(ele.size());
        //print text
       //Create one list
        List one = new ArrayList();
        for(int i=0;i ele1=driver.findElements(By.xpath("//table[@id='ctl00_cpEndUserMain_grdvCheckFare']/tbody/tr/td[2]"));
        List two = new ArrayList();
        for(int i=0;i

Selenium server start up problems: Failed to start: SocketListener0@0.0.0.0:4444

If the below appear while running the selenium scripts, Failed to start: SocketListener0@0.0.0.0:4444 you need to kill the process "javaw.exe" by going to the task manager If this is a routine case then you can write a reusable function and call it wherever required

Monday, June 10, 2013

Capture ToolTip from QTP


'for Web Elements
msgbox browser("browser").Page("pagename").WebElement("webelementname").Object.title

'for images
msgbox Browser("browser").Page("pagename").Image("imagename").GetROProperty("alt")

'for Links
x=Browser("browser").Page("page").Link("linkname").GetROProperty("OuterHtml")
temp=split(x,chr("34"))
ToolTip=temp(1)
msgbox ToolTip

Friday, June 7, 2013

Delete cookies using QTP

SystemUtil.Run "Control.exe","inetcpl.cpl"
Set objShell = CreateObject("Wscript.Shell")
Do Until delcookie = True
    delcookie = objShell.AppActivate("Internet Properties")
    Wait(1)
Loop
objShell.Sendkeys "%i"
Wait(1)
objShell.Sendkeys "{ENTER}"
Wait(1)
objShell.Sendkeys "%f"
Wait(1)
objShell.Sendkeys "%d"
Wait(1)
objShell.Sendkeys "{ENTER}"
Wait(4)
objShell.Sendkeys "{ENTER}"

AI in Software Testing: How Artificial Intelligence Is Transforming QA

For years, software testing has lived under pressure: more features, faster releases, fewer bugs, smaller teams. Traditional QA has done her...