id | title | sidebar_label | description | keywords | url | site_name | slug | ||||
---|---|---|---|---|---|---|---|---|---|---|---|
getting-started-with-selenium-4 |
Getting Started With Selenium 4 On LambdaTest Platform |
Getting Started |
Now run automated tests with Selenium 4 using the LambdaTest Selenium Grid across 3000+ browsers and operating systems. |
|
LambdaTest |
getting-started-with-selenium-4/ |
Now run automated tests with Selenium 4 using the LambdaTest Selenium Grid across 3000+ browsers and operating systems. With this LambdaTest and Selenium 4 integration, LambdaTest not only allows you to perform Selenium 4 testing on an online automation cloud, but also allows you to perform cross-browser testing at scale.
This Selenium 4 documentation will act as your step-by-step guide on your journey to test using Selenium 4 on LambdaTest.
Note: As of now, the sample test script is only available in Java. But worry not! We are working on adding the test scripts on other languages too.
As a part of this step-by-step guide, we will run a Selenium 4 test that perform the following action:
- Open google.com.
- Enter a search string LambdaTest in the browser.
- Click the Google Search button.
- Assert the page URL.
- Mark the status of the test as either passed or failed based on the assertion.
To select the OS-device-browser combination for running the test, use LambdaTest's capability generator. After selecting the combination, replace the capabilities given in the sample test script with the chosen combination.
As the sample test script is only available in Java, we recommend using it to run your first Selenium 4 test on LambdaTest. The offered test script uses the updated Action class features and the relative locators of Selenium 4.
Relative Locators helps users locate any complex UI elements, elements that might be relevant to a critical UI element, in fewer lines of code. Selenium 4 has the following relative locators: above
, below
, toLeftOf
, toRightOf
, and near
. For the sake of this test, the script uses the toLeftof
locator to locate the Google Search button on the Google home page.
Some other use cases for Relative Locators are:
- In the case of an e-commerce website, relative locators can help identify a particular button if there are multiple buttons with the same name on a single website page.
- UI elements that do not include unique IDs
- UI elements with complex CSS or XPath expression.
Selenium 4 comes with a changed syntax of the Action class. It is used for handling mouse and keyboard events on a specific element. For this test, the script uses the moveToElement(onElement).click()
method to simulate the click action of your mouse.
Along with these features, Selenium 4 offers other CDP features that LambdaTest supports. Check them out now.
In your Java project, create a new file JavaSample.java and copy the following code to this file:
Note: As of now, the sample test script is only available in Java. But worry not! We are working on adding the test scripts on other languages too.
Warning: Ensure that you include the driver.quit() statement at the end of the test script to avoid timeout issues. If you skip adding the statement, the test continues to run leading to a timeout.
You can run the file using the Run command in your IDE after the test script is created.
After running the test successfully, the dashboard and the command line will view your result. In addition, you get access to text logs, video recordings ,and screenshots of your test execution.