Join us
WebDriver supported "mobile testing drivers" are:
Selenium WebDriver supports the below languages to write Test Cases.
In most circumstances, TypeKeys() will produce a JavaScript event, whereas.type() would not.
The "type" command is used to enter keyboard key values into a software web application's text box. It can also be used to choose values from a combo box, whereas the "typeAndWait" command is used when you finish typing and the software web page begins to reload. This command will wait for the page of the software programme to reload before proceeding. You must use a basic "type" command if there is no page reload event when typing.
findElement(): Using the provided "locating technique," it is used to locate the first element on the current page. It gives you a single WebElement as a result.
findElements() searches the current page for all elements using the supplied "locating mechanism." It gives you a list of web elements as a result.
For AJAX-based applications, Selenium Webdriver introduces the concept of waits. There are two kinds of waiting times:
Waiting Time Implicit Waiting Time Explicit Waiting Time Implicit Waiting Time Exp
Implicit wait has the main disadvantage of slowing down test performance.
Another drawback of implicit waiting is that:
Assume you've established a waiting time limit of ten Seconds. Because you ordered it to wait a maximum of 10 seconds, and the elements show in the DOM in 11 seconds, your tests will fail.
Selenium Grid enables you to deploy your tests across numerous machines at the same time. As a result, the same text script may be used to run tests on both a Windows and a Mac machine. It cuts down on test execution time and gives immediate feedback.
The get command is used to retrieve the inner text of a web element. The get command takes no parameters and returns a string type value. It's also one of the most commonly used commands for checking messages, labels, and errors, among other things, from web pages.
We use the WebDriver's Select class to select the value in the dropdown.
Syntax:
selectByValue:
selectByVisibleText:
The navigation commands are as follows.
navigate().back()
The above command needs no parameters and takes back the user to the previous webpage.
Example
driver.navigate().back();
navigate().forward()
The above command allows the user to navigate to the next web page with reference to the browser's history.
Example
driver.navigate().forward();
navigate().refresh()
The navigate().refresh() command allows the user to refresh the current web page by reloading all the web elements.
Example
driver.navigate().refresh();
navigate().to()
The navigate().to() command allows the user to launch a new web browser window and navigate to the specified URL.
Example
driver.navigate().to("https://google.com");
An inline frame abbreviates as an iframe. It is used to insert another document within the current document. These document can be HTML document or simply web page and nested web page.
Select iframe by id
driver.switchTo().frame("ID of the frame");
Locating iframe using tagName
driver.switchTo().frame(driver.findElements(By.tagName("iframe").get(0));
Locating iframe using index
frame(index)
driver.switchTo().frame(0);
frame(Name of Frame)
driver.switchTo().frame("name of the frame");
frame(WebElement element)
Select Parent Window
driver.switchTo().defaultContent();
To use HtmlUnit first use the RemoteWebDriver and pass it in the desired capabilities
IWebDriver driver= new RemoteWebDriver(DesiredCapabilities.HtmlUnit())
For the Firefox implementation to run, use
IWebDriver driver= new RemoteWebDriver(DesiredCapabilities.HtmlUnitWithJavaScript())
Selenium facilitates with a PROXY class to redirect browsing from a proxy. Look at the example below.
Example
String PROXY = "199.201.125.147:8080";
org.openqa.selenium.Proxy proxy = new.org.openqa.selenium.Proxy();
proxy.setHTTPProxy(Proxy)
.setFtpProxy(Proxy)
.setSslProxy(Proxy)
DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability(CapabilityType.PROXY, proxy);
WebDriver driver = new FirefoxDriver(cap);
The Page Object Model is a design approach for storing web UI elements in an object directory. Each web page must have its own page class. The page class is in charge of locating WebElements in web pages and performing operations on them.
The following are some of the advantages of adopting POM.
It enhances code readability by separating actions and flows in the UI from Verification.
Because the Object Repository is independent of Test Cases, it can be used by several tests.
Coding reusability
Below is the program to capture screenshot in WebDriver.
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.io.File;
import java.io.IOException;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class TakeScreenshot {
WebDriver drv;
@Before
public void setUp() throws Exception {
driver = new FirefoxDriver();
drv.get("https://google.com");
}
@After
public void tearDown() throws Exception {
drv.quit();
}
@Test
public void test() throws IOException {
//capture the screenshot
File scrFile = ((TakeScreenshot)drv).getScreenshotAs(OutputType.FILE);
// paste the screenshot in the desired location
FileUtils.copyFile(scrFile, new File("C:\\Screenshot\\Scr.jpg"))
}
}
The sendKeys("String to be entered") is used to enter the string in a textbox.
Syntax
WebElement username = drv.findElement(By.id("Email"));
// entering username
username.sendKeys("sth");
WebDriver allows user to check the visibility of the web elements. These web elements can be buttons, radio buttons, drop, checkboxes, boxes, labels etc. which are used with the following methods.
Syntax:
isDisplayed():
boolean buttonPresence = driver.findElement(By.id("gbqfba")).isDisplayed();
isSelected():
boolean buttonSelected = driver.findElement(By.id("gbqfba")).isSelected();
isEnabled():
boolean searchIconEnabled = driver.findElement(By.id("gbqfb")).isEnabled();
driver.findElement(By.linkText("Google")).click();
The above command search the element using a link text, then click on that element and thus the user will be re-directed to the corresponding page.
The following command can access the link mentioned earlier.
driver.findElement(By.partialLinkText("Goo")).click();
Join other developers and claim your FAUN account now!
Founder, www.dridhon.com
@dridhoneInfluence
Total Hits
Posts
Only registered users can post comments. Please, login or signup.