Check Selenium Interviewquestions from 1 to 10 below:
Check Selenium-SDET-UIAutomation Questions set 21 to 30:
Check Selenium-SDET-UIAutomation Questions set 41-50:
Q&A Set 41-50
Better Window/Tab Management in Selenium 4
There are several instances in test automation wherein one might need to open a particular link in a new tab or window to perform certain actions. To achieve this in Selenium 3, QAs had to create a new driver object and then perform the switch operation using the WindowHandle method to perform subsequent steps.
This is set to change in Selenium 4 as it comes with a new API – newWindow that allows users to create and switch to a new window/tab without creating a new WebDriver object.
Sample code snippet to open a new window
driver.get("https://www.google.com/"); // Opens a new window and switches to new window driver.switchTo().newWindow(WindowType.WINDOW); // Opens BrowserStack homepage in the newly opened window driver.navigate().to("https://www.browserstack.com/");
Sample code snippet to open a new tab within the same window
driver.get("https://www.google.com/"); // Opens a new tab in existing window driver.switchTo().newWindow(WindowType.TAB); // Opens Browserstack homepage in the newly opened tab driver.navigate().to("https://www.browserstack.com/");
Deprecation of Desired Capabilities
Desired Capabilities were primarily used in the test scripts to define the
test environment (browser name, version, operating system) for execution on the Selenium Grid.
In Selenium 4, capabilities objects are replaced with Options.
This means testers now need to create an Options object, set test requirements,
and pass the object to the Driver constructor.
Listed below are the Options objects to be used going forward for defining browser-specific capabilities:
- Firefox – FirefoxOptions
- Chrome – ChromeOptions
- Internet Explorer (IE) – InternetExplorerOptions
- Microsoft Edge – EdgeOptions
- Safari – SafariOptions
Modifications in the Actions Class
Actions class in Selenium is primarily used to simulate input actions from mouse
and keyboard on specific web elements (For eg: Left click, Right click, Double click, etc)
In Selenium 4, several new methods have been added to the Actions class:
- click(WebElement)
This method is added to Actions class to replace the moveToElement(onElement).click().
It is used to click on a certain web element.
- clickAndHold(WebElement)
This method will replace the moveToElement(onElement).clickAndHold().
It is used to click on an element without releasing the click.
- contextClick(WebElement)
This method will replace moveToElement(onElement).contextClick().
It will perform the right click operation.
- doubleClick(WebElement)
This method is added to replace moveToElement(element).doubleClick().
It will perform a double click on an element.
- release()
This method (user for releasing the pressed mouse button) was initially a part of org.openqa.selenium.interactions.ButtonReleaseAction class.
Now with the updated version of Selenium, it has been moved to Actions class.
Selenium 3 vs Selenium 4
Selenium 3 Selenium 4 The Browser interaction is based on
JSON wire protocol due to which it
needs encoding and decoding of the
API, and JWP connects with browser drivers It follows the W3C standard
Protocol due to which driver and the
browser communication follows the standard
procedure, does not require encoding and decoding
of the API, so communication happens directly.
No comments:
Post a Comment