Selenium
Store Variables, Echo, Alert, PopUp handling in Selenium IDE
In this tutorial, we will learn, Store commands, Echo commands, Alerts and Popup handling. Storing...
AJAX stands for Asynchronous JavaScript & XML, and it allows the Web page to retrieve small amounts of data from the server without reloading the entire page.
Ajax is a technique used for creating fast and dynamic web pages. This technique is asynchronous and uses a combination of Javascript and XML .
It will updates the part/s of a web page without reloading the whole page.
Some of the famous applications that uses AJAX technique are Gmail, Google Maps, Facebook, Youtube, etc.
In this tutorial, you will learn-
For example, when you click on submit button, JavaScript will make a request to the server, interpret the result and update the current screen without reloading the webpage.
From a tester's point of view, if you are checking the content or the element to be displayed , you need to wait till you get the response. During AJAX call the data is stored in XML format and retrieved from the server.
The biggest challenge in handling Ajax call is knowing the loading time for the web page. Since the loading of the web page will last only for a fraction of seconds, it is difficult for the tester to test such application through automation tool. For that, Selenium Webdriver has to use the wait method on this Ajax Call.
So by executing this wait command, selenium will suspend the execution of current Test Case and wait for the expected or new value. When the new value or field appears, the suspended test cases will get executed by Selenium Webdriver.
Following are the wait methods that Selenium Webdriver can use
But the problem with all these waits is, you have to mention the time out unit. What if the element is still not present within the time? So there is one more wait called Fluent wait.
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
public class Ajaxdemo {
private String URL = "http://demo.gtupapers.com/test/ajax.html";
WebDriver driver;
WebDriverWait wait;
@BeforeClass
public void setUp() {
System.setProperty("webdriver.chrome.driver",".\\chromedriver.exe");
//create chrome instance
driver = new ChromeDriver();
driver.manage().window().maximize();
driver.navigate().to(URL);
}
@Test
public void test_AjaxExample() {
By container = By.cssSelector(".container");
wait = new WebDriverWait(driver, 5);
wait.until(ExpectedConditions.presenceOfElementLocated(container));
//Get the text before performing an ajax call
WebElement noTextElement = driver.findElement(By.className("radiobutton"));
String textBefore = noTextElement.getText().trim();
//Click on the radio button
driver.findElement(By.id("yes")).click();
//Click on Check Button
driver.findElement(By.id("buttoncheck")).click();
/*Get the text after ajax call*/
WebElement TextElement = driver.findElement(By.className("radiobutton"));
wait.until(ExpectedConditions.visibilityOf(TextElement));
String textAfter = TextElement.getText().trim();
/*Verify both texts before ajax call and after ajax call text.*/
Assert.assertNotEquals(textBefore, textAfter);
System.out.println("Ajax Call Performed");
String expectedText = "Radio button is checked and it's value is Yes";
/*Verify expected text with text updated after ajax call*/
Assert.assertEquals(textAfter, expectedText);
driver.close();
}
}
In this tutorial, we will learn, Store commands, Echo commands, Alerts and Popup handling. Storing...
In this tutorial, you will learn how to integrate Cucumber with Selenium Webdriver. What is...
There are two types of HTML tables published on the web- Static tables : Data is static i.e....
What is a Scrollbar? A Scrollbar is a lets you move around screen in horizontal or vertical...
Selenium installation is a 3 step process: Install Java SDK Install Eclipe Install Selenium...
Breakpoints are used to check the execution of your code. Whenever you implement a breakpoint in...