Showing posts with label selenium frames. Show all posts
Showing posts with label selenium frames. Show all posts

Monday, May 15, 2017

Jenkins - Adding a conditional build step.

In Jenkins, at times we may require Jenkins to execute some build step on one condition and another in case of other condition. For e.g: It may be required to run a particular test/batch command on Weekdays and some other batch condition on weekends. We can create a job to perform different tasks based on the condition satisfied. 

To add a conditional build step, follow below steps in Jenkins.

  • Navigate to Jenkins>Manage Jenkins>Manage Plugins and go to available tab.
  • Search for Conditional buildstep as shown below and click on install without restart.
  • It will install the plugin and will show success once installation completes.
  • Now the plugin can be used in the Jenkins job as shown below.In the job, add build step as Conditional step (single)

  • Provide the conditional step from the list as shown below and execute the build command.







Saturday, April 22, 2017

Switching between multiple frames in selenium


There can be multiple iframes in a webPage. To perform action on webelements in a frame, we need to first identify the frame and then perform action on the element.
We can switch to a particular frame based on the below identifiers:


By Index: The index depends on the order of frame in the Page. A numeric value is assigned to the frame based on the order in which it appears in the page.

driver.SwitchTo().Frame(0);

By Name: We can switch to a frame based on the name of the frame.

driver.SwitchTo().Frame("FrameName");

By Id: We can switch to a frame based on the id defined for the frame

driver.SwitchTo().Frame("FrameId");

Switch to a frame by locator for WebElement. In the below example frameElement is the locator for the frame

driver.switchTo().frame(frameElement);

e.g: 

driver.SwitchTo().Frame(driver.FindElement(By.CssSelector(cssfortheelement)));


Frame inside frames: There can be scenario in which there are frame inside of the parent frame.Please note in case of frame inside frame, we need to first switch to the outer frame, and then switch to the inner frame to perform action on the webelement.


To acess the main webPage and come out of the frame, below code is used

driver.SwitchTo().DefaultContent()

Sunday, November 27, 2016

Validating conditions using assert and verify in Selenium IDE

The purpose of any automation/manual tests is to validate the application is working correctly and validating the actual outcome with the expected outcome for a condition.


  • Now the first question arises, what are the commands in selenium IDE which validates the outcome of condition There are different commands in different tools/automated suite. In selenium IDE, we can use assert or verify commands to validate the results.
  • Now the question two arises, what is the difference between assert and verify commands, When we use Assert command, it checks whether the given condition is true or false and stops further test execution if the assert statement fails. In case of verify command, in case the execution fails, the execution moves to next step in the test although the test is marked as failed.
  • Now coming to question three, when to use verify or assert command. In case of critical condition failing and no point to continue with test, use assert command. In case of minor condition failing in the test and we still wants to continue with further steps in the test, we can use verify statement.
  • So what is the next logical question in mind, when and how  to add the validation steps in test.Since Selenium IDE is a record and play tool,
    • Record execution flow. Once execution flow is recorded, we can add assertions in Selenium IDE.
    • Just right click the element on which the condition needs to be verified in Firefox browser e.g : Validating the text of the link. 
    • Click on the assertion to be added as shown below:

Add assertions selenium IDE


Similar to assert/verify commands in selenium IDE, we can use assert and soft.assert class for assert and verify command in Selenium Webdriver.

How to run test with random data in Selenium IDE: store and storeText Command

Selenium IDE is a tool for record and play functionality, which runs the script with same set of data, however we can generate random data. store the values in a variable , and use the value stored in the variable in the later steps in the test.


Expected Learning from this article:

  • Store command to store random generated data in the a variable. 
  • Using the stored information in later steps in the test.
  • Using command storeText to store value of an object in the test and storing in a test.
  • Using the stored information in later stage in the test.



Below screenshot shows how to use store and storetext in the test:




  • In the above test, we open an application and save the text of the link in variable using command storeText. test in Value is the variable in each we can store the value of the link/object.
  • In the next step, we can use the value in the variable using ${variable_name} which is ${test} in our example.
  • Similarly using store command and javascript, we can generate random data, store in the variable and use further in the test.
  • We have saved the test in an html file and the test file looks as below:


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head profile="http://selenium-ide.openqa.org/profiles/test-case">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="selenium.base" href="https://www.google.co.in/" />
<title>testing stored value</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">testing stored value</td></tr>
</thead><tbody>
<tr>
 <td>open</td>
 <td>/search?q=selenium&amp;ie=utf-8&amp;oe=utf-8&amp;client=firefox-b-ab&amp;gfe_rd=cr&amp;ei=r4E6WIqnEeXI8AfOn6awBw</td>
 <td></td>
</tr>
<tr>
 <td>storeText</td>
 <td>link=Selenium - Web Browser Automation</td>
 <td>test</td>
</tr>
<tr>
 <td>type</td>
 <td>id=lst-ib</td>
 <td>${test}</td>
</tr>
<tr>
 <td>click</td>
 <td>name=btnG</td>
 <td></td>
</tr>
<tr>
 <td>store</td>
 <td>javascript{&quot;Selenium&quot; +Math.random();}</td>
 <td>testrandom</td>
</tr>
<tr>
 <td>type</td>
 <td>id=lst-ib</td>
 <td>${testrandom}</td>
</tr>
<tr>
 <td>click</td>
 <td>name=btnG</td>
 <td></td>
</tr>

</tbody></table>
</body>
</html>

Copy paste the code in a text file and save in html format. Open the test in Selenium Ide and try to run the test and understand how to run test with random data in selenium IDE.

Sunday, September 25, 2016

Switching to frame, Windows, alert in Selenium WebDriver

1. How to Switch from one frame to another

 // How to Switch from one frame to another  
 WebElement iFrmeElement = driver.findElement(By.xpath("xPath for Frame"));  
 driver.switchTo().frame(frameElement);  
 //Or  
 driver.switchTo().frame(id or name)  
 //Or  
 driver.switchTo().frame(index of frame)  

2. We can switch to default again by:

 driver.switchTo().defaultContent();  

3. We can switch to a window based on name, Id or Windows handle

 driver.switchTo().window("windowName");  

4. We can switch to an alert

 Alert alert = driver.switchTo().alert();  
 // We can close an alert using methods for alert object  
 alert. accept();