{{announcement.body}}
{{announcement.title}}

Complete Guide To Access Forms In Selenium With Java

DZone 's Guide to

Complete Guide To Access Forms In Selenium With Java

This article will help you understand how you can access forms in Selenium to automate browser testing of your web application.

· Performance Zone ·
Free Resource

Have you noticed the ubiquity of web forms while surfing the internet? Almost every website or web-application you visit leverages web-forms to gain relevant information about yourself. From creating an account over a web-application to filling a brief survey, web forms are everywhere! A form comprises web elements such as checkbox, radio button, password, drop down to collect user data.

If you are going to perform automated browser testing for your website or web-application then you simply can’t afford to drop-out the forms from your test automation scripts. Speaking of test automation, Selenium has an API that helps to find these web elements and take subsequent actions on them like selecting a value or entering some text.

You may also like: How To Test a Login Process With Selenium and Java

This article will help you understand how you can access forms in Selenium to automate browser testing of your web application. I will be using the JUnit Framework with some annotations to execute our Selenium automation testing later in this article.

To begin our learning with, we’ll first understand what a WebElement is, how can it be accessed in Selenium Automation, and then go about seeing the basic form elements like the input boxes, buttons, the actions that can be performed on these forms and finally writing a script to handle a form and run it on various browsers. If you are already aware of the basics then feel free to skip through the sections according to yourself:

What Is A WebElement?

In layman’s language, anything present on a webpage constitutes a WebElement. Examples can be a text box, a radio button, etc. Selenium Webdriver offers an interface called the WebElement which is responsible for all the possible interaction that takes place in the web page. To find these WebElements, Selenium WebDriver provides 2 methods viz, findElement() and findElements().

findElement(): This method is used to locate a single web element. Once the element is found it is returned as a WebElement object. Let us now see the syntax of findElement(), but before we start using the WebElement object in our test script we need to make note of one very important point.

We need to import below package before we can start creating objects of the WebElements:

import org.openqa.selenium.WebElement;  

Syntax for findElement(): 

WebElement ele = driver.findElement(By.xpath(---xpath---);  

findElements(): It returns a list of WebElements that corresponds to the locator defined in the method. The syntax for findElements() is as shown below:

List<WebElement> ele = driver.findElements(By.xpath(---xpath---);  

Now that we are thorough with the understanding of the WebElement interface, along with the difference between findElement() and findElements() method in Selenium automation testing.
It is time to deep dive into these web elements. We will now list down all the web fields that may be involved in your website or web application form. We will then notice how to access forms in Selenium WebDriver.

Types Of Fields To Access In Forms With Selenium

To subsequently build the scripts to access forms in Selenium WebDriver, we need to understand the various fields that we will have to handle in our test automation scripts. Let us try to dig a little more about these WebElements one by one.

Input Box

The input box is a primary element in any form. No form is complete without user input. It can be of two types:

  1. Text Field Box – Text boxes that display the value as is entered by the user.
  2. Password Field Box – Text boxes that display special characters (mostly ‘*’) when the value is entered by the user.

Here is an image representing the input boxes inside a form.

empty form

Buttons

One of the most important fields to consider while you access forms for Selenium automation testing. There is no point in filling up a form if there is no interface to submit the same. Buttons are simply used to submit whatever information we have filled in our text boxes. This can be submitting some form of data or simply submitting the sign-in information to the server.

free sign up

CheckBox

In most of the websites that are widely used we see a small box that enables us to check or uncheck it. Mostly in agreement sections wherein the user needs to confirm the understanding of these policies. CheckBox is used to return a boolean value, if it is checked then it would return True else would return false.

checkbox

Radio Button

Remember seeing a circular element on the screens when we select our Gender in any of the signup forms? That is what a radio button is. It is similar to a checkbox only difference being if we are given multiple radio buttons we can select just one, while in the case of multiple checkboxes, we can opt multiple of them.

radio button

Link

We all face the common problem of forgetting our account passwords. Noticed the Forgot Password link on the screens? That is what a link is. It redirects us to a new web page or a new window pop-up or a similar thing. It links us to a new URL altogether.

link

Drop Down

There are times for a website where there are multiple options for a specific category. Say a website to book your flight tickets. To pick up the Origin & Destination city we often see a list with multiple values. This list which has an arrow at the rightmost end to expand and show the values is called a drop-down. It provides a list of options to the user thereby giving access to one or multiple values as per the requirement.

Below is a snapshot of how Facebook uses forms.

create an account

How To Web Elements In A Form With Selenium?

Now that we know what different types of web elements we can come across in our application, We need to identify these web elements through our Selenium automation testing scripts, and to do so we use Selenium locators. Locators are the parameters given to the findElement() or findElements() methods which help to retrieve the web element by using its properties like the ID, Name, Class, etc. In general, we have eight locators in Selenium that are widely used:

  • ID
  • Name
  • Tag Name
  • Class Name
  • LinkText
  • Partial LinkText
  • XPath
  • CSS Selector

Few of the examples are:

Java
 




x


1
WebElement eid = driver.findElement(By.id(“email”);
2
WebElement pswd = driver.findElement(By.name(“password”);
3
WebElement sbmtBtn = driver.findElement(By.xpath(//input[@value=”submit”]”);



In a similar way we can use By.className, By.CSSSelector(), By.linktext(), etc.

Interacting With Web Elements By Accessing Forms In Selenium

Finding these web elements is only half-way of your journey while accessing forms through Selenium automation testing. Now, comes the crux of accessing form in Selenium. Performing actions and interacting with the forms using Selenium.! Let us see how different actions can be performed on each one of them.

1. Input Box

To handle any input box, we must be able to enter information, clear information or get information from the box. Different methods that Selenium offers to work with text boxes are:

  • sendKeys()
  • clear()
  • getText()

To enter text into a textbox we can use the sendKeys method which would input the user required text from our automation script.

driver.findElement(By.id(“username”).sendKeys(“abc@gmail.com”); 

The above statement would enter the Email ID as abc@gmail.com into a text box whose ID is username. Now, to clear a pre-entered text or the text that you last entered can be wiped clean with the clear() method. 

driver.findElement(By.id(“username”)).clear(); 

The third method that can be used on a text box is the getText() method. It’ll fetch the text that is written in a text box in case we need to validate some existing or entered text. 

String nameText = driver.findElement(By.id(“username”)).getText(); 

The above line of code would return the text, let us take the text entered by the first line of code above, i.e. abc@gmail.com and store it in nameText variable of string type. There might be chances when the text is present in the value property. In such a scenario we will use the getAttribute() method in place of getText().

String nameText = driver.findElement(By.id(“username”)).getAttribute(“value”); 

2. Buttons

We can submit the information by using buttons. This can be done though click actions on the same. Below are the methods available in selenium to perform actions on buttons.

  • click()
  • submit()

It might look like there is no difference in both the methods, but a very minute detail changes the usage of each method. Both of these methods would eventually submit the form data to the server, but we need to understand the type of the web element present. If the element type is either ‘submit’ or ‘button’, click() method would work for both, but if the element type is ‘submit’ with the button being inside

tag, then only submit() would work. If any of the conditions is false then submit() won’t work.

Below is the syntax for both:

driver.findElement(By.id(“submtLogIn”).click(); 

driver.findElement(By.id(“submtLogIn”).submit() 

3. Check Box

While working with checkbox, we’ll use below Selenium methods:

  • click()
  • isSelected()

To select or check a value we use the click() method. It simply changes the state from unchecked to checked and vice-versa.

driver.findElement(By.id(“name”)).click(); 

Now that we can check/uncheck a checkbox, we might first need to know the state of a checkbox before performing a certain action with Selenium automation testing. To get the state we use isSelected() method which would return a boolean value. This means if the checkbox is checked we’d get a True else we’ll get False. 

boolean state = driver.findElement(By.id(“name”)).isSelected(); 

4. Radio Button

The actions performed on the radio button are similar to those on a checkbox and we can use the same methods as above for the radio button as well.

  • click()
  • isSelected()

5. Link

Links are generally embedded in a web page for us to navigate to a new screen or a pop-up or a form. We can either do a click action on them or can get the text that it holds and then proceed with our execution.

  • click()
  • getText()

Both of the above methods can be used in a way similar as stated above.

6. Dropdown

Dropdowns are very common in web applications and are widely used for selecting among a range of options. There is a wide variety of methods that we can use with dropdowns. Let us see them and their corresponding syntax and usage one by one.

  • selectByVisibleText(String) — It selects the option by comparing the visible text wherein String value passed in the method is what is compared.
  • selectByIndex(int) — Selects option based on the index in the drop-down menu with integer parameter passed as the index.
  • selectByValue(String) — Selects the option based on the option value in string format

In a similar way we can deselect any selected value from the dropdown using any of the below options:

  • deselectByVisibleText(String)
  • deselectByIndex(int)
  • deselectByValue(String)
  • deSelectAll() — This would deselect all the options selected from a dropdown.

To use any of the above methods in your selenium code, syntax can be as follows:

Java
 




xxxxxxxxxx
1


 
1
Select se=new Select(driver.findElement(By.id("nation"))); 
2
se.selectByValue("Ind"); 



There are times while performing Selenium automation testing of our web app, where we need to validate the options coming in our dropdown list, or if we can select multiple options. These are very easily sorted using selenium which gives us the leverage to perform a few more actions. Listed below are a few of them:

  • getAllSelectedOptions() — We may come across dropdowns wherein we can select multiple options. Now, to get the list of all the selected options we can use this method.
  • getFirstSelectedOption() — This method would return the first option that has been selected from the dropdown and unlike the above method it would return a single web element and not a list.
  • getOptions() — This method would enable us to get a list of all available options in a dropdown.
  • isMultiple() — To check if a dropdown can take multiple options, we can use isMultiple() method which would return a boolean value.

To get a list of options we can write our piece of code by referencing a list object:

Java
 




xxxxxxxxxx
1


 
1
Select se=new Select(driver.findElement(By.id("nation"))); List<WebElement> 
2
list=se.getOptions();



Now that we know the basic operations and handling of Web Elements let us go forward implementing these in a Selenium script. In the next section, I’ll show you a simple program that handles the Form Elements on a demo site.

Handling Form Elements Through Selenium WebDriver

Now, we will automate the Facebook Sign Up functionality to access the form in Selenium, as we perform actions on the web elements. Here is a test script to access forms in Selenium with Java using the JUnit framework.

Java
 




xxxxxxxxxx
1
69


 
1
//Complete code to run the test of facebook sign up
2
 
          
3
import org.junit.AfterClass;
4
import org.junit.BeforeClass;
5
import org.junit.Test;
6
import org.openqa.selenium.By;
7
import org.openqa.selenium.WebDriver;
8
import org.openqa.selenium.WebElement;
9
import org.openqa.selenium.chrome.ChromeDriver;
10
import org.openqa.selenium.support.ui.Select;
11
 
12
public class TestForms {
13
 
14
    static WebDriver driver;
15
    
16
    @BeforeClass
17
    public static void setUp(){
18
            System.out.println("-----This is the beginning of our test !!!-----");
19
        System.setProperty("webdriver.chrome.driver", "C:\\Users\\admin\\Downloads\\chromedriver_win32(1)\\chromedriver.exe");
20
            driver = new ChromeDriver();
21
            driver.manage().window().maximize();
22
            driver.get("https://facebook.com");
23
    }
24
    
25
    @Test
26
    public void fillForm(){
27
            System.out.println("-----Let us start the sign up process!!!-----");
28
            /*
29
             * Handling text boxes to enter and clear values
30
             */
31
            WebElement fName = driver.findElement(By.xpath("//input[@name='firstname']"));
32
            fName.sendKeys("--Enter you name here--");
33
            WebElement lName = driver.findElement(By.xpath("//input[@name='lastname']"));
34
            lName.sendKeys("--Enter your last name--");
35
            //Clear the textbox
36
            lName.clear();
37
            lName.sendKeys("XYZ");
38
            WebElement eMail = driver.findElement(By.xpath("//input[@name='reg_email__']"));
39
            eMail.sendKeys("--Enter mail or contact number--");
40
            WebElement pwd = driver.findElement(By.xpath("//input[@name='reg_passwd__']"));
41
            pwd.sendKeys("--Enter a valid password here--");
42
            /*
43
             * Handling dropdown to select date of birth
44
             */
45
            Select date = new Select(driver.findElement(By.xpath("(id('day'))")));
46
            date.selectByVisibleText("15");
47
            Select month = new Select(driver.findElement(By.xpath("(id('month'))")));
48
            month.selectByVisibleText("Jan");
49
            Select year = new Select(driver.findElement(By.xpath("(id('year'))")));
50
            year.selectByVisibleText("1990");
51
            
52
            /*
53
             * Handling Radio buttons to select gender
54
             */
55
        driver.findElement(By.className("_58mt")).click();
56
            
57
            /*
58
             * Handling the Sign Up button to perform click action
59
             */
60
            
61
            WebElement sgnUp = driver.findElement(By.xpath("//button[@id='u_0_13']"));
62
            sgnUp.click();
63
    }
64
    @AfterClass
65
    public static void tearDown(){
66
            System.out.println("-----We're now closing the session...-----");
67
            driver.quit();
68
    }
69
} 



By running the above script, you will be able to access forms in Selenium using the JUnit. If you guys are not familiar with JUnit. Here is an end-to-end guide for running your first Selenium automation testing script with JUnit.

Thoughts About Scalability For A Faster Test Cycle?

Job well done! However, if you are to access forms in Selenium for your web-application then chances are that your test suites are going to be bigger and complex. You will need to access forms in Selenium on hundreds of browsers + operating systems. Wondering why?

Well, your form may not be as cross browser compatible as you may assume them to be! Here is how a simple DateTime input field may differ in rendering.

DateTime

DateTime in IE8

DateTime in Google Chrome 72


Which brings us back to a major question! How do you access forms in Selenium WebDriver over hundred of browsers + OS?

Well, for starters you can go-ahead and set up a Selenium Grid in-house. However, if you are having a bigger test suite, abundant testing requirements then you may have to spend a considerable amount of money and time in order to scale your in-house Selenium Grid. You will need to keep adding the latest device, browsers, operating systems that are being launched to your Selenium Grid. Considering the adoption of Agile, Kanban, and other modern SDLCs(Software Development Life Cycles), the major browser vendors, operating systems are launching a new version every month.

SDLCs(Software Development Life Cycles), the major browser vendors, operating systems are launching a new version every month.

Access Forms In Selenium Grid On-Cloud

Let me demonstrate to you a scalable approach to access forms in Selenium. I will be using online Selenium Grid of LambdaTest to parallelly run the above script in different browsers & operating systems. Before we go-ahead to run our script on LambdaTest we need to take care of a few points which are listed below:

  • Instead of invoking the regular FirefoxDriver, we’ll have to use the Remote WebDriver along with the capabilities related to the browser, its version, OS, etc.

Since we have already created our script locally, we’ll use the Selenium Desired Capability Generator wherein just by providing some details like the OS, Resolution, Browser(& it’s version), selenium version, location, etc, this generator would provide us a few lines of code which would look like below based on our selections.

  • Now we just need to declare the LambdaTest authentication credentials in the Selenium automation testing scripts. That way, the WebDriver would know the correct Hub URL it needs to address. Below is the final script that we will be using to run our tests on LambdaTest. The changes to our existing script are highlighted.
Java
 




xxxxxxxxxx
1
89


 
1
import java.net.MalformedURLException;
2
import java.net.URL;
3
import org.junit.AfterClass;
4
import org.junit.BeforeClass;
5
import org.junit.Test;
6
import org.openqa.selenium.By;
7
import org.openqa.selenium.WebElement;
8
import org.openqa.selenium.remote.DesiredCapabilities;
9
import org.openqa.selenium.remote.RemoteWebDriver;
10
import org.openqa.selenium.support.ui.Select;
11
 
12
public class TestForms {
13
 
14
    static String username = "Your UserName";
15
    static String accesskey = "Your Access Key";
16
    static RemoteWebDriver driver = null;
17
    static String gridURL = "@hub.lambdatest.com/wd/hub";
18
    boolean status = false;
19
    
20
    @BeforeClass
21
    public static void setUp(){
22
            System.out.println("-----This is the beginning of our test !!!-----");
23
            DesiredCapabilities capabilities = new DesiredCapabilities();
24
            capabilities.setCapability("build", "TestFormsV1.0");
25
            capabilities.setCapability("name", "SeleniumForms");
26
        capabilities.setCapability("platform", "Windows 10");
27
        capabilities.setCapability("browserName", "Chrome");
28
        capabilities.setCapability("version","79.0");
29
        capabilities.setCapability("selenium_version","3.13.0");
30
        capabilities.setCapability("geoLocation","IN");
31
        capabilities.setCapability("chrome.driver","78.0");
32
            
33
            try {
34
            driver = new RemoteWebDriver(new URL("https://" + username + ":" + accesskey + gridURL), capabilities);
35
             }
36
             catch (MalformedURLException e) {
37
              System.out.println("Invalid grid URL");
38
             } catch (Exception e) {
39
              System.out.println(e.getMessage());
40
             }
41
            driver.manage().window().maximize();
42
    }
43
    
44
    @Test
45
    public void fillForm(){
46
            driver.get("https://facebook.com");
47
            System.out.println("-----Let us start the sign up process!!!-----");
48
            /*
49
             * Handling text boxes to enter and clear values
50
             */
51
            WebElement fName = driver.findElement(By.xpath("//input[@name='firstname']"));
52
            fName.sendKeys("--Enter you name here--");
53
            WebElement lName = driver.findElement(By.xpath("//input[@name='lastname']"));
54
            lName.sendKeys("--Enter your last name--");
55
            //Clear the textbox
56
            lName.clear();
57
            lName.sendKeys("XYZ");
58
            WebElement eMail = driver.findElement(By.xpath("//input[@name='reg_email__']"));
59
            eMail.sendKeys("--Enter mail or contact number--");
60
            WebElement pwd = driver.findElement(By.xpath("//input[@name='reg_passwd__']"));
61
            pwd.sendKeys("--Enter a valid password here--");
62
            /*
63
             * Handling dropdown to select date of birth
64
             */
65
            Select date = new Select(driver.findElement(By.xpath("(id('day'))")));
66
            date.selectByVisibleText("15");
67
            Select month = new Select(driver.findElement(By.xpath("(id('month'))")));
68
            month.selectByVisibleText("Jan");
69
            Select year = new Select(driver.findElement(By.xpath("(id('year'))")));
70
            year.selectByVisibleText("1990");
71
            
72
            /*
73
             * Handling Radio buttons to select gender
74
             */
75
        driver.findElement(By.className("_58mt")).click();
76
            
77
            /*
78
             * Handling the Sign Up button to perform click action
79
             */
80
            
81
            WebElement sgnUp = driver.findElement(By.xpath("//button[@id='u_0_13']"));
82
        sgnUp.click();
83
    }
84
    @AfterClass
85
    public static void tearDown(){
86
            System.out.println("-----We're now closing the session...-----");
87
            driver.quit();
88
    }
89
}



You can run the above code directly through Eclipse or through Command Line following the same steps that we have already done earlier. The results would be available in your Lambda Test Dashboard upon the execution of the script. I’ll show you the corresponding result page once we execute the script with parallel browsers all at once. Next comes the most interesting part where we can run our tests in parallel browsers without the need of changing the browser details every time we intend to run our test. 

But before doing so we will have to create a helper class that will lead the testing. Subsequently, we will have to make a few changes to our main class that contains the test script and we are good to go. In the following part, you’ll see our final test script to run our test in parallel on different browsers using Lambda Test.

Test Script Container Class

The below code would contain the main test script that we intend to execute. This is similar to what has been written above with some minor tweaks in variables. This example shows execution on 3 different browsers. You can modify your script based on your requirement of execution.

Java
 




xxxxxxxxxx
1
116


 
1
import java.net.MalformedURLException;
2
import java.net.URL;
3
import java.util.LinkedList;
4
import org.junit.After;
5
import org.junit.Before;
6
import org.junit.Test;
7
import org.junit.runner.RunWith;
8
import org.junit.runners.Parameterized;
9
import org.openqa.selenium.By;
10
import org.openqa.selenium.WebElement;
11
import org.openqa.selenium.remote.DesiredCapabilities;
12
import org.openqa.selenium.remote.RemoteWebDriver;
13
import org.openqa.selenium.support.ui.Select;
14
 
15
@RunWith(ParallelHelper.class)
16
public class TestForms {
17
 
18
    static String username = "Your User Name";
19
    static String accesskey = "Your Access Key";
20
    static RemoteWebDriver driver = null;
21
    static String gridURL = "@hub.lambdatest.com/wd/hub";
22
    public static String platform;
23
    public static String browserName;
24
    public static String browserVersion; 
25
    boolean status = false;
26
    
27
    /*
28
     * Creating parameters for the browsers to be used
29
     */
30
    @Parameterized.Parameters
31
    public static LinkedList<String[]> getEnvironments() throws Exception {
32
    LinkedList<String[]> env = new LinkedList<String[]>();
33
    env.add(new String[]{"WIN10", "chrome", "79.0"});
34
    env.add(new String[]{"WIN10","firefox","71.0"});
35
    env.add(new String[]{"WIN10","internet explorer","11.0"});
36
    return env;
37
   }
38
 
39
    public TestForms(String platform, String browserName, String browserVersion) {
40
        this.platform = platform;
41
        this.browserName = browserName;
42
        this.browserVersion = browserVersion;
43
    }
44
 
45
    @Before
46
    public void setUp() {
47
            System.out.println("-----This is the beginning of our test !!!-----");
48
            DesiredCapabilities capabilities = new DesiredCapabilities();
49
            capabilities.setCapability("build", "TestFormsV1.0");  //Can provide you Build Name
50
            capabilities.setCapability("name", "SeleniumForms");  //Provide your Test Name
51
        capabilities.setCapability("platform", platform);         //Would pass the OS to  be invoked
52
        capabilities.setCapability("browserName", browserName); //Would pass the Browser name to be invoked
53
            capabilities.setCapability("version", browserVersion);  //Would pass the Browser Version to be invoked
54
        capabilities.setCapability("selenium_version", "3.13.0");
55
        capabilities.setCapability("geoLocation", "IN");
56
 
57
            try {
58
                driver = new RemoteWebDriver(new URL("https://" + username + ":" + accesskey + gridURL), capabilities);
59
            } catch (MalformedURLException e) {
60
                System.out.println("Invalid grid URL");
61
            } catch (Exception e) {
62
                System.out.println(e.getMessage());
63
            }
64
    }
65
 
66
    /*
67
     * This is our main test script
68
     */
69
    @Test
70
    public void fillForm() {
71
            driver.get("https://facebook.com");
72
            driver.manage().window().maximize();
73
            System.out.println("-----Let us start the sign up process!!!-----");
74
            /*
75
             * Handling text boxes to enter and clear values
76
             */
77
            WebElement fName = driver.findElement(By.xpath("//input[@name='firstname']"));
78
            fName.sendKeys("--Enter you name here--");
79
            WebElement lName = driver.findElement(By.xpath("//input[@name='lastname']"));
80
            lName.sendKeys("--Enter your last name--");
81
            // Clear the textbox
82
            lName.clear();
83
            lName.sendKeys("XYZ");
84
            WebElement eMail = driver.findElement(By.xpath("//input[@name='reg_email__']"));
85
            eMail.sendKeys("--Enter mail or contact number--");
86
            WebElement pwd = driver.findElement(By.xpath("//input[@name='reg_passwd__']"));
87
            pwd.sendKeys("--Enter a valid password here--");
88
            /*
89
             * Handling dropdown to select date of birth
90
             */
91
            Select date = new Select(driver.findElement(By.xpath("(id('day'))")));
92
            date.selectByVisibleText("15");
93
            Select month = new Select(driver.findElement(By.xpath("(id('month'))")));
94
            month.selectByVisibleText("Jan");
95
            Select year = new Select(driver.findElement(By.xpath("(id('year'))")));
96
            year.selectByVisibleText("1990");
97
 
98
            /*
99
             * Handling Radio buttons to select gender
100
             */
101
        driver.findElement(By.className("_58mt")).click();
102
 
103
            /*
104
             * Handling the Sign Up button to perform click action
105
             */
106
 
107
            WebElement sgnUp = driver.findElement(By.xpath("//button[@id='u_0_13']"));
108
            sgnUp.click();
109
    }
110
 
111
    @After
112
    public void tearDown() {
113
            System.out.println("-----We're now closing the session...-----");
114
            driver.quit();
115
    }
116
}



Test Script Helper/Runner Class

This class contains the code that would enable parallel execution of test on different browsers.

Java
 




x
37


 
1
import java.util.concurrent.ExecutorService;
2
import java.util.concurrent.Executors;
3
import java.util.concurrent.TimeUnit;
4
import org.junit.runners.Parameterized;
5
import org.junit.runners.model.RunnerScheduler;
6
 
7
public class ParallelHelper extends Parameterized {
8
    
9
    private static class ThreadPoolScheduler implements RunnerScheduler {
10
        private ExecutorService exec; 
11
        public ThreadPoolScheduler() {
12
            String threads = System.getProperty("junit.parallel.threads", "10");
13
            int numThreads = Integer.parseInt(threads);
14
            exec= Executors.newFixedThreadPool(numThreads);
15
        }
16
 
17
        public void finished() {
18
            exec.shutdown();
19
            try {
20
                exec.awaitTermination(10, TimeUnit.MINUTES);
21
            } catch (InterruptedException exc) {
22
                throw new RuntimeException(exc);
23
            }
24
        }
25
 
26
        public void schedule(Runnable childStatement) {
27
            exec.submit(childStatement);
28
        }
29
    }
30
    
31
    
32
    
33
    public ParallelHelper(Class<?> klass) throws Throwable {
34
            super(klass);
35
            // TODO Auto-generated constructor stub
36
    }
37
}



On running the above class we’ll see that our test runs on the Lambda Test Cloud and the results of the test are generated. Note that you can see the progress on your Eclipse IDE & subsequently the results(like the Execution Video) are available on the Lambda Test Automation Dashboard. Below is a snapshot of how the Execution results would look like in Lambda Test Dashboard:

The Eclipse IDE Console and results, on the other hand, would show up as below:

Were You Able To Access Forms In Selenium WebDriver?

I hope this Selenium Java tutorial has helped you access forms in Selenium WebDriver. Remember, forms are fundamental for every business running online. Almost every web application is gathering user information through forms. As an automation tester, you need to ensure two things:

  1. All your forms are functionally working as they should.
  2. All your forms are cross-browser compatible so they are accessed by every customer.

If you aren’t sure about forms being used in your web-application then you can go ahead and leverage an online Selenium Grid such as LambdaTest. Your first 100 automation testing minutes are absolutely free, along with lifetime free access to our cross-browser testing tool. Leverage parallel testing to ensure all your test cycles are delivered on-time. Happy testing!


Further Reading

Discover the Top Tips and Tricks of the Selenium WebDriver

Best Practices For Using Selenium for Test Automation

Topics:
selenium automated testing ,selenium automation ,automation testing ,java ,selenium 3.0 ,performance

Published at DZone with permission of Aditya Dwivedi . See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}