A blog on Selenium WebDriver, Java, VB Script, Software Testing, SOAPUI, Groovy, SOA Testing, Mobile Testing, Appium etc.
Thursday 2 January 2014
What is Text output & its use in QTP
A Text Output values enables to capture or to output text strings displayed in an AUT during run time. For example, suppose that you want to store the text of any error message that appears after a specific step in the Web application you are testing. You can create a text output value while recording or editing your test.
To create a text output value while recording:
1. Highlight or display the text string you want to use for an output value.
2. Select Insert > Output Value > Text OutputValue. The pointer changes into a pointing hand.
3. In your application, click the text string for which you want to specify a text output value. The Text Output Value Properties dialog box opens.
4. QTP creates a column (using logical name of object) in Global DataTable to store output value.
Sunday 29 December 2013
Selenium - How to highlight Element
It is always a good practice to highlight element before performing an operation. This helps us to know where the Selenium is currently focused or which element it is being executed.
There is no native way to do this, but because Selenium allows to execute JavaScript, it can be accomplished by executing JavaScript method. Code is as follows -
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.testng.annotations.Test;
public class HighLightElement {
WebDriver driver = new FirefoxDriver(); //Launch firefox browser
@Test
public void highlightTest() throws InterruptedException {
driver.get("https://www.facebook.com/"); // open facebook site
driver.manage().window().maximize(); // maximize browser
WebElement emailField = driver.findElement(By.xpath("//*[@id='email']")); //get
reference to email text field
Thread.sleep(2000); //Stop program execution for 2 seconds
highlightElement(emailField); // call to highlight method
}
/** Method which executes Java Script code to highlight page object */
public void highlightElement(WebElement element) {
for (int i = 0; i < 2; i++)
{
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("arguments[0].setAttribute('style', arguments[1]);", element, "color: red; border: 5px solid red;");
js.executeScript("arguments[0].setAttribute('style', arguments[1]);", element, "");
}
}
}
There is no native way to do this, but because Selenium allows to execute JavaScript, it can be accomplished by executing JavaScript method. Code is as follows -
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.testng.annotations.Test;
public class HighLightElement {
WebDriver driver = new FirefoxDriver(); //Launch firefox browser
@Test
public void highlightTest() throws InterruptedException {
driver.get("https://www.facebook.com/"); // open facebook site
driver.manage().window().maximize(); // maximize browser
WebElement emailField = driver.findElement(By.xpath("//*[@id='email']")); //get
reference to email text field
Thread.sleep(2000); //Stop program execution for 2 seconds
highlightElement(emailField); // call to highlight method
}
/** Method which executes Java Script code to highlight page object */
public void highlightElement(WebElement element) {
for (int i = 0; i < 2; i++)
{
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("arguments[0].setAttribute('style', arguments[1]);", element, "color: red; border: 5px solid red;");
js.executeScript("arguments[0].setAttribute('style', arguments[1]);", element, "");
}
}
}
Saturday 28 December 2013
What is the difference between check point and output value
Checkpoint | Output Value |
· A checkpoint is a verification point that compares a current value for a specified property with the expected value for that property. · When the test is run, HP QTP compares the expected results of the checkpoint to the current results. · If the results do not match, the checkpoint fails & results of the checkpoint can be viewed in the Test Results window. · When Checkpoint is added, HP QTP adds a checkpoint with an icon in the test tree and adds a Checkpoint statement in the Expert View. · Checkpoint syntax - Window("Flight Reservation").WinComboBox("Fly To:").Check CheckPoint("Fly To:") · Insert -> Checkpoint -> Select the type of Checkpoint OR Right click the object in the Active Screen and select the type of checkpoint to be added. | · An Output Value is used to retrieve the current value of any object in the application and stores it in a specified location. It can output values from text strings, table cells, databases, and XML documents. Unlike Checkpoints, no PASS/FAIL status is generated. · An output value is a value captured during the test run and entered in the run-time Data Table for use at another point in the test run. · When you create an output value, the test retrieves a value at a specified point during the test run and stores it in a column in the current row of the run-time Data Table. · When the value is needed later in the test run as input, HP QTP retrieves it from the Data Table. · You can output the property values of any objects. · Insert -> Output Value->Select the type of output value OR Right click the object in the Active screen and select the type of output value to be added. |
Thursday 26 December 2013
Selenium - How to read URL of a link
Selenium code to get URL is as follows -
1. Find the link as a Web Element using findElement() method
WebElement Lnk_URL = driver.findElement(By.id("Lnk"));
2. Get URL value using "href" attribute
String URL = Lnk_URL.getAttribute("href");
Subscribe to:
Posts (Atom)