By using below methods you maximize window in selenium/webdriver
1. selenium.windowMaximize();
2. driver.manage().window().maximize();
3. If above 2 commands doesn't work try the below code.
Refer the below example
TESTEVERYTHING
Friday, 12 October 2012
Sunday, 23 September 2012
Locating elements using DOM, Css and Xpath
Refer the below example
Whole web page
Whole web page
xpath=/html
css=html
document.documentElement
Whole web
page body
xpath=/html/body
css=body
document.body
All text
nodes of web page
//text()
Element
<E> by absolute reference
xpath=/html/body/.../.../.../E
css=body>…>…>…>E
document.body.childNodes[i]...childNodes[j]
Element
<E> by relative reference
//E
css=E
document.gEBTN('E')[0]
Second
<E> element anywhere on page
xpath=(//E)[2]
document.gEBTN('E')[1]
Image
element
//img
css=img
document.images[0]
Element
<E> with attribute A
//E[@A]
css=E[A]
dom=for each (e
in document.gEBTN('E')) if (e.A) e
Element
<E> with attribute A containing text 't' exactly
//E[@A='t']
css=E[A='t']
Element
<E> with attribute A containing text 't'
//E[contains(@A,'t')]
Element
<E> whose attribute A begins with 't'
//E[starts-with(@A,
't')]
Element
<E> whose attribute A ends with 't'
//E[substring(@A,
string-length(@A) - string-length('t')+1)='t']
Element
<E> with attribute A containing word 'w'
//E[contains(concat('⦿', @A, '⦿'), '⦿w⦿')
Element
<E> with attribute A matching regex ‘r’
Element
<E1> with id I1 or element <E2> with id I2
//E1[@id=I1] |
//E2[@id=I2]
css=E1#I1,E2#I2
Element
<E1> with id I1 or id I2
//E1[@id=I1 or
@id=I2]
css=E1#I1,E1#I2
Attribute A
of element <E>
//E/@A {Se: //E@A }
{Se: css=E@A }
document.gEBTN('E')[0].getAttribute('A')
⌦
{Se:
document.gEBTN('E')[0]@A }
Attribute A
of any element
//*/@A {Se: //*@A }
{Se: css=*@A }
Attribute A1
of element <E> where attribute A2 is 't' exactly
//E[@A2='t']/@A1
⌦ {Se: //E[@A2='t']@A1 }
{Se:
css=E[A2='t']@A1 }
Attribute A
of element <E> where A contains 't'
//E[contains(@A,'t')]/@A
⌦ {Se: //E[contains(@A,'t')]@A }
{Se: @A }
Element
<E> with id I
//E[@id='I']
css=E#I
Element with
id I
//*[@id='I']
css=#I
document.gEBI('I')
id=I
Friday, 10 August 2012
Selenium Webdriver 2 Wait /Sleep for time period/wait next step execution/ Set speed for next execution
Some times we have to wait while running the script like for next execution wait for specific duration.But in web driver 2, I did not find the simple way to wait for next step execution after that I have decided to use simplest way to wait in looping statement. I have created a method just call the method with waiting time in seconds.It will wait for given time period.
Thursday, 9 August 2012
Handling Security Cerificates(UntrustedSSLCertificates) using WebDriver(selenium2)
Handling Security Cerificates(UntrustedSSLCertificates) in Internet Explorer (IE) using WebDriver(selenium2)
driver = new InternetExplorerDriver();driver.navigate().to("javascript:document.getElementById('overridelink').click()");
// or using selenium rc
selenium.runScript("document.getElementById('overridelink').click()");
Handling Security Cerificates(UntrustedSSLCertificates) in Firefox using WebDriver(selenium2)
Thursday, 2 August 2012
Set cookies with domain using webdriver
using web driver I have created the script for adding the cookies using domain. Basically here is the things that you must know first open the URL then add the cookies after that again open the URL now it will add.
______________________________________________________
package webdriver;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.Cookie;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.support.ui.Select;
public class RuntestCase {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
WebDriver driver;
System.out.println("firefox");
DesiredCapabilities capability = DesiredCapabilities.firefox();
String appUrl = "http://beta.abc.com/mlb/sweepstakes/y2012/sd/alaska_form.jsp";
capability.setBrowserName("firefox");
capability.setPlatform(org.openqa.selenium.Platform.ANY);
driver = new FirefoxDriver(capability);
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.get(appUrl);
Calendar c = new GregorianCalendar();
int year = 2014;
int month = 6;
int day = 7;
int hour = 10;
int minute = 26;
int second = 47;
c.set(year, month, day, hour, minute, second);
Date expiry = c.getTime();
String name = "betaaccess";
String value = "true";
String domain = ".abc.com";
String path = "/";
Cookie cookie = new Cookie(name, value, domain, path, expiry, false);
driver.manage().addCookie(cookie);
driver.get(appUrl);
}
}
______________________________________________________
package webdriver;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.Cookie;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.support.ui.Select;
public class RuntestCase {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
WebDriver driver;
System.out.println("firefox");
DesiredCapabilities capability = DesiredCapabilities.firefox();
String appUrl = "http://beta.abc.com/mlb/sweepstakes/y2012/sd/alaska_form.jsp";
capability.setBrowserName("firefox");
capability.setPlatform(org.openqa.selenium.Platform.ANY);
driver = new FirefoxDriver(capability);
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.get(appUrl);
Calendar c = new GregorianCalendar();
int year = 2014;
int month = 6;
int day = 7;
int hour = 10;
int minute = 26;
int second = 47;
c.set(year, month, day, hour, minute, second);
Date expiry = c.getTime();
String name = "betaaccess";
String value = "true";
String domain = ".abc.com";
String path = "/";
Cookie cookie = new Cookie(name, value, domain, path, expiry, false);
driver.manage().addCookie(cookie);
driver.get(appUrl);
}
}
Wednesday, 16 May 2012
String Reverse in VB Script Without using any function
Dim yourstr,r,letter,result
yourstr="pro1gr3a6m"
Set r=new regexp
r.pattern="[a-z 0-9 A-Z]"
r.global=true
set s=r.execute(yourstr)
For each letter in s
result= letter.value&result
Next
print result
yourstr="pro1gr3a6m"
Set r=new regexp
r.pattern="[a-z 0-9 A-Z]"
r.global=true
set s=r.execute(yourstr)
For each letter in s
result= letter.value&result
Next
print result
Wednesday, 15 February 2012
Tips to Optimize QTP Scripts to Yield Better Performance
Tips to Optimize QTP Scripts to Yield Better Performance
We use Automated-testing tools to optimize our manual testing processes. But in order to reap full benefits of any automated testing tool, we must know the complete ins and outs of the tool otherwise it would be a huge waste of money spent on automation. We have to learn the automation tool very thoroughly. We also need to learn the language of the automation tool to do coding more effectively and efficiently. I believe that a software testing tool is as good as the person who is actually using it.
I have been getting so many emails from my esteemed readers asking about HP QuickTest Professional tutorials, QTP tips and tricks etc. Some readers even complain that their QTP scripts are too slow to execute. This time I decided to write a post on how to use QTP more effectively which means how to make our QTP scripts perform better. In order words, this post will throw light on some points, which will optimize your QTP scripts.
Some of the QTP optimization tips can be:
Tip – 1: You should not use hard coded wait statement until absolutely necessary. Instead of the wait statement, you should use either exist or synchronization (sync) statements. The wait statement waits for the number of seconds, which have been provided. For example using wait(5) will wait for 5 seconds even if the browser gets into a ready state even after 2 seconds which means a waste of 3 seconds. Imagine how much time would be wasted if you have say 10 wait statements per script and you are running a batch of 500 scripts. A better alternative is using sync or exist statements for example:
Browser("").Page("").Sync
var=Browser("").Page("").Exist(2)
Never use the exist statement without a value as it will take the default object synchronization timeout value from QTP settings. You can navigate to these settings from File->Settings and then go to Run tab. So use Exist(0) instead of Exist(10). Moreover, I will suggest to set the global object synchronization timeout to 1 second.
Tip – 2: Use declared variables instead of using variables on the fly. In order to enforce this in your scripts, use Option Explicit statement which forces the variable declaration. Moreover, using declared variables, scripts perform a bit faster. Also if you are using Option Explicit, it has to be the very first line of the code otherwise you will get an error.
Tip – 3: Using QTP for a longer period of time has a direct impact on the performance. It has been observed that a lot of Random Access Memory(RAM) gets consumed by QTP if QTP is running scripts for prolonged time. QTP starts eating system memory(memory leak) and sooner or later it will get hanged and we will be required to kill the qtpro.exe process and restart QTP all over again. In such a case, I will suggest you is to use QTP on computers with particular good amount of RAM and equally good clock speed.
Tip – 4: Do not load all addins while opening QTP. Use only the addins, which are required. This directly impacts QTP performance.
Tip – 5: I have personally experienced that opening QTP through a vbs file is faster than loading QTP through the icon.
Subscribe to:
Posts (Atom)