Selenium WebDriver Setup and Basic Methods
This section we are going to add Selenium WebDriver and Cucumber Junit, Selenium WebDriver will operate web browser remotely by calling WebDriver API. For this tutorial we are going to use Chrome WebDriver, Please see the article about Selenium WebDriver Configuration for more clarification.
Step by Step process of Selenium dependencies add to gradle
-
From you projects find the file called build.gradle
-
There will a block which we added last time called dependencies, find the closure.
-
Add the below dependencies into that closure.
testImplementation 'io.cucumber:cucumber-junit:5.6.0'
implementation 'org.seleniumhq.selenium:selenium-java:3.141.59'
implementation 'org.seleniumhq.selenium:selenium-chrome-driver:3.141.59'
Here 1st dependency for Cucumber Junit, rest are for Selenium.
-
After add those dependencies the dependency closure will be like below
....
project.ext {
cucumberVersion = '5.6.0'
}
dependencies {
testImplementation 'io.cucumber:cucumber-java:' + cucumberVersion
testImplementation 'io.cucumber:cucumber-junit:5.6.0'
implementation 'org.seleniumhq.selenium:selenium-java:3.141.59'
implementation 'org.seleniumhq.selenium:selenium-chrome-driver:3.141.59'
}
....
Below methods will use in project
Selenium WebDriver comes with lots of features and control method, we are not gonna discuss all of them, here I listed some methods which will need to use in our current project. Let’s see them.
-
webDriver.manage().window().maximize(): This method responsible for maximize the browser window.
-
webDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS): It’s command browser to wait for certain amount of time.
-
webDriver.get(url): Load the url into browser.
-
webDriver.close(): Closes the current browser associated with the driver.
-
webDriver.quit(): Shutdown the opened browser.
-
webDriver.findElement(By.className("some-class")): It’s allowed to find and select the element by class name.
-
webElement.sendKeys("some-text"): Put value into input box.
-
webElement.click(): Trigger click action to element.
-
webElement.getText(): Bring values from elements.