Are you a developer and is struggling to do feature testing for your application? If that is the case then no need to worry as Selenium would give you an opportunity to test your features without any hassle.
It is a web automation testing tool which works well with almost all browsers. With the help of Selenium WebDriver you will be able to save your time and can automate any task with browser which you executed.
Selenium Webdriver is an interface which wraps and sends commands to the browser and implementation of this interface is given by difference browsers such as Mozilla Firefox, Google Chrome and IE.
How It Can Help in Feature Testing?
It depends on the kind of developer you are. If you are a developer who believes in testing all key features after deployment then Selenium Webdriver would be a panacea for you.
But there are many developers who just believe in developing new stuffs and not first testing the existing features and then go ahead with building new ones. This would lead to a lot of bugs and the cost incurred with finding a defect would increase in the defect life cycle.
Also Read : 15 Top Selenium WebDriver Commands For Test Automation
So, the strategy should be testing the existing features and then building new stuffs. If you are thinking that testing existing new features would consume a lot of time then in that case you can use Selenium Webdriver to cut the time taken to test these features.
In this way your code would be bug free and cost associated with defects will decrease.
Let’s now prepare first test with Selenium WebDriver. If you are thinking that you are not a Java Expert; then how would you start writing code and explore. Selenium Webdriver needs minimal use of Java if you want to start with it so doesn’t worry and go ahead!
Set Up Needs To Be Done
First Test With Selenium Webdriver To Test Login Feature
For writing code you need to make a class file in your project. For doing that; click on New -> Class -> Next -> Name your Class -> Finish. Now, you can start writing your code in this section. As of now just copy the code below and run it on your local machine.
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class Test1 {
static WebDriver webDriver;
public static void main(final String[] args) throws InterruptedException {
// Telling the system where to find the chrome driver
System.setProperty(
“webdriver.chrome.driver”,
“C:/PATH/TO/chromedriver.exe”);
// Open the Chrome browser
webDriver = new ChromeDriver();
// Maximize the browser window
webDriver.manage().window().maximize();
if (testlogin()) {
System.out.println(“Test WordPress Login: Passed”);
} else {
System.out.println(“Test WordPress Login: Failed”);
}
// Close the browser and WebDriver
webDriver.close();
webDriver.quit();
}
private static boolean testlogin() {
try {
// Open google.com
webDriver.navigate().to(“https://www.YOUR-SITE.org/wp-admin/”);
// Type in the username
webDriver.findElement(By.id(“user_login”)).sendKeys(“YOUR_USERNAME”);
// Type in the password
webDriver.findElement(By.id(“user_pass”)).sendKeys(“YOUR_PASSWORD”);
// Click the Submit button
webDriver.findElement(By.id(“wp-submit”)).click();
// Wait a little bit (7000 milliseconds)
Thread.sleep(7000);
// Check whether the h1 equals “Dashboard”
if (webDriver.findElement(By.tagName(“h1”)).getText()
.equals(“Dashboard”)) {
return true;
} else {
return false;
}
// If anything goes wrong, return false.
} catch (final Exception e) {
System.out.println(e.getClass().toString());
return false;
}
}
}
Run this you will find Chrome Browser opening up and then testing the login functionality. Let me explain the steps one by one for better understanding.
This statement is to tell your program where it can find chromedriver.exe file in your local.
These commands will open Chromedriver instance and then would maximize the size of the browser.
This would test if the login feature is properly working or not. If it is not working then “Test failed” would be printed else “Test passed”.
Also Read : 52 Software Tester Interview Questions That can Land You the Job
webDriver.navigate().to(“https://www.YOUR-SITE.org/wp-admin/”);
webDriver.findElement(By.id(“user_login”)).sendKeys(“YOUR_USERNAME”);
webDriver.findElement(By.id(“user_pass”)).sendKeys(“YOUR_PASSWORD”);
These would be hit the URL in the browser and then find username and password fields. With the help of sendKeys you will be able to write to these text boxes.
With the help of this command you are clicking on submit form.
This sleep is included in order to follow the test visually. 7000 means 7000 ms that means 7s.
if (webDriver.findElement(By.tagName(“h1”)).getText().equals(“Dashboard”))
{
return true
} else {
return false;
}
Conclusion
Thus after executing one test you would got to know the power of Selenium WebDriver. The more you will dive into it the more you will get proficient. You could even test same test with all browsers at the same time using parallel testing using Selenium GRID. So, when there is a need for you to do feature testing just go with Selenium Webdriver and leverage the benefits out of it. All the best!!
How To Do Security Testing: Best Practices
Sep 25, 2018How to Test a Bank ERP System
Sep 21, 2018How to Integrate Maven and Jenkins with Selenium
Aug 31, 2018How to Effectively Do Project Management in Software Testing
Dec 28, 2018How to Test a Music App like Spotify, YouTube Music etc.
Oct 25, 2018How to Use Analytics for Website Analysis and Testing
Oct 17, 2018How To Hire A Software Testing Team That Fits Your Office Culture
Sep 27, 2018How To Do Responsive Design Testing ? Rules, Challenges and Tips
Sep 26, 2018How To Do Security Testing: Best Practices
Sep 25, 2018How to Test a Bank ERP System
Sep 21, 2018How to Integrate Selenium With Gecko Driver : Full Tutorial
Sep 7, 2018How to write a neat Bug Report? Complete Guide
Aug 17, 2018