Selenium Java Tutorial: Automation Testing Of User Signup Form

Tags: selenium, csharp, java, webdev
Published: 2019-11-20 12:28:36

If you are just starting with Selenium automation testing of your product, the first page you would probably want to automate would be the SignUp or Login Page. If you have an online platform like an ecommerce company or a Software-as-a-Service product, the Signup page acts as the door to welcome your web application visitors. It is one of the simplest yet one of the most important pages of your platform, and comes at the start of every possible user journey that you may want to test. Hence, it is also one of the most important web pages for your web application.

So today, we are going deeper into how you can [perform Selenium automation testing](https://www.lambdatest.com/feature?utm_source=dev&utm_medium=Blog&utm_campaign=Ramit-20112019&utm_term=Ramit) of Signup form page. We are going to execute automation testing with Selenium and Java. In one of our previous [Selenium Java tutorials](https://www.lambdatest.com/blog/selenium-java-tutorial-how-to-test-login-process/?utm_source=dev&utm_medium=Blog&utm_campaign=Ramit-20112019&utm_term=Ramit), we demonstrated how to automate the login process using Selenium automation testing.

Today, we will take an example of a Registration Page / Sign Up Page from LambdaTest. We will start our discussion with the test cases and process for the registration page of LambdaTest and then move to the Automation part to see how we can increase our browser coverage for efficient [cross browser testing](https://www.lambdatest.com/) and accelerate automation testing through [parallel testing on Selenium Grid](https://www.lambdatest.com/blog/setup-selenium-grid-for-parallel-execution/).

Before moving forward, let’s look at the workflow in a bit more detail and see how [Sign Up page of LambdaTest](https://accounts.lambdatest.com/register?utm_source=dev&utm_medium=Blog&utm_campaign=Ramit-20112019&utm_term=Ramit) works.

As a first step, we enter URL [https://www.lambdatest.com](https://www.lambdatest.com?utm_source=dev&utm_medium=Blog&utm_campaign=Ramit-20112019&utm_term=Ramit) in any browser to reach the landing page of the LambdaTest website. You can refer following screenshot for the landing page.

![LambdaTest](https://www.lambdatest.com/blog/wp-content/uploads/2019/10/selenium-java.png)

From there we are going to click on **‘Free Signup’** button and reach to the [Registration page](https://accounts.lambdatest.com/register) of the LambdaTest.

![Registration](https://www.lambdatest.com/blog/wp-content/uploads/2019/10/selenium-java1.png)

Now, let us check the Functional fields on this Registration page and list them down.

- **Organization** / **Company Name** (Text field)
- **Full Name** of the user (Text field)
- **Work Email** Id (Text field)
- **Desired Password** (Text field)
- **Phone** number of the user (Text field)
- **Terms and Privacy Policy** (checkbox)
- **Free Signup** (button)

## WorkFlow Of The Sign Up Page

Enter all the required fields: Full Name, Work Email, Desired Password, Phone number, Terms and Privacy policy checkbox.

Validate the fields:

1. Work email : Should not be an existing user, valid email.
2. Password : Should provide minimum required length for password.
3. Phone Number
4. Terms and Privacy policy checkbox

Till now, we have discussed all the basic things about the registration page, specifically related to the [registration page of LambdaTest](https://accounts.lambdatest.com/register?utm_source=dev&utm_medium=Blog&utm_campaign=Ramit-20112019&utm_term=Ramit). So let us proceed with [writing test cases](https://www.lambdatest.com/blog/17-lessons-i-learned-for-writing-effective-test-cases/?utm_source=dev&utm_medium=Blog&utm_campaign=Ramit-20112019&utm_term=Ramit) for this page.

## Possible Test Scenarios of the Sign Up Page

[![Web UI Testing with Python and LambdaTest](https://www.lambdatest.com/webinar/blog-cta/webinar-image.png)](https://www.lambdatest.com/webinar/cross-browser-testing-with-Selenified-and-LambdaTest?utm_source=dev&utm_medium=Blog&utm_campaign=Ramit-20112019&utm_term=Ramit)

### Elements

Check if all buttons, title, checkboxes are present on the page and if those are working by clicking on all buttons and checkboxes. In case of LambdaTest registration page, we should check the following buttons, text fields, terms and privacy policy checkbox, etc.

### Links

Check if all the links present on the page are redirects to the expected pages.  
We also need to check if:

- **LambdaTest** link redirects to LambdaTest are launching the correct page.
- **Terms of Service** link opens a new tab with redirection to the Terms of service page.
- **Privacy Policy** link opens a new tab with redirection to the Privacy Policy page.
- **Login** link redirects from registration page to login page.

### Optional Fields

In case of LambdaTest registration page, only optional is Organization or Company Name. So we shall try to register with and without providing Organization or Company name, and it should be possible to complete the registration in both the cases (considering user has provided all other information correctly).

### Required Fields

In case of LambdaTest registration page, we have the following required fields , so let us discuss about the cases related to each field.  
 ![Required Fields](https://www.lambdatest.com/blog/wp-content/uploads/2019/10/selenium-java2.png)

#### **Full Name**
 

→ Verify without providing Full name, it should give the respective error and it should not be possible to proceed further the registration page.

→ verify with providing Full name, it should be possible to complete the registration (considering user has provided all other information correctly).

#### **Work Email**
 

→ Verify with valid email ID, but have an existing account on LambdaTest platform with that email ID, then in that case, it should not be allowed to register with that email ID and should give a respective error message (considering user has provided all other information correctly).

→ Verify without providing any details in the Work Email field, it should not be allowed to register without any email ID and should give a respective error message.

→ Verify with valid email ID, which does not have any account on LambdaTest platform with that email ID, so the user should be able to proceed and register successfully (considering user has provided all other information correctly).

#### **Desired Password**
 

→ Verify without providing any password in the Desired Password field, it should give the respected error message to provide the password.

→ As we can see that there is a minimum length of characters for the password is required, which is at least 8 characters are required. So we can make use of test design technique Boundary Value Analysis (BVA), as we have minimum criteria of 8 characters so we can test with lengths 7, 8 and 9 characters.

- When it is less than 7 then it should give the error to the user and user can proceed to complete the registration process.
- When it is 8 then it should be possible for the user to complete the registration process successfully without any error. (considering user has provided all other information correctly).
- When it is 9 then also it should be possible for the user to complete the registration process successfully without any error. (considering user has provided all other information correctly).

#### **Phone**
 

→ Verify without providing any phone number in the field, as it is also mandatory field so user should not be able to proceed and complete the registration without providing phone number.

→ Verify with providing invalid phone number ( phone number with 2-3 digit), in this case also user should not be able to proceed and complete the registration with invalid providing phone number.

→ Verify with providing valid phone number in the field, in this case the user should be able to register successfully with valid phone number (considering user has provided all other information correctly).

#### **Terms of Service checkbox:**
 

→ Verify without checking Terms of Services checkbox, as it is required field in the registration process user can not proceed to complete the registration process without checking this checkbox.

→ Verify with Terms of services checkbox is selected, then user can complete the registration successfully without any error (considering user has provided all other information correctly).

**So we have seen till now**

- What are the fields generally present on the Registration Page, along with the example of registration page of LambdaTest.
- Expected workflow of the registration page.
- Test cases/scenarios for the Registration page

## Automating User SignUp Form Using Selenium and Java

So far in this Selenium Java tutorial, you have established a fair understanding of what you need to test on the Signup page. With that in mind, let us roll into action and automate this Signup page by performing Selenium automation testing with Java and TestNG.

We will now come up with a Selenium automation scripts and execute it on an online Selenium Grid. We will also leverage the power of parallel testing to fast track our automated cross browser testing. But before all that, you should be ready with the below prerequisites.

### Prerequisites

Before moving to the script, let us go through some basic prerequisites to write and execute Selenium Automation test script.

1. **JDK and JRE** – This is required to execute any Java program in our system. You can download it from the official website of Oracle.  
[https://www.oracle.com/technetwork/java/javase/downloads/jdk11-downloads-5066655.html](https://www.oracle.com/technetwork/java/javase/downloads/jdk11-downloads-5066655.html)

![Java](https://www.lambdatest.com/blog/wp-content/uploads/2019/10/selenium-java3.png)

2. **Eclipse IDE** – We have used Eclipse to write our program or test script. You can download it from the [official website of Eclipse](https://www.eclipse.org/downloads/) or you can use any other IDE as per your choice.

![Eclipse](https://www.lambdatest.com/blog/wp-content/uploads/2019/10/selenium-java4.png)

3. **Selenium Jars** – To write any Selenium automation testing script, it is required to have Selenium Jars in the project. You can download Selenium Jars from the [official website of Selenium](https://www.seleniumhq.org/download/).
4. **TestNG Framework** – In the following test script we have used TestNG framework for Selenium automation testing which will help us in generating test reports, prioritizing test cases, grouping the test cases and also for parallel execution on different browsers.  
You can either download TestNG Jars or you can directly add it inside Eclipse from Eclipse Marketplace using the [TestNG Eclipse URL](http://beust.com/eclipse) or you may refer to [TestNG to download](https://testng.org/doc/download.html).

In the below example, we have integrated our test script with LambdaTest, a cross browser testing tool. Wondering why we are running our Selenium automation tests on cloud-based Selenium testing tool such as LambdaTest?

Although, Selenium empowers you to automate your web application testing across different browsers. You can only perform Selenium automation testing on browsers installed on your machine where the local webdriver is running. Now, installing hundreds of browsers and maintaining the library for your inhouse Selenium infrastructure can be very strenous, not to forget, time-consuming too.

This is why it is recommended to run Selenium automation testing on an online [Selenium testing tool](https://www.lambdatest.com/selenium-automation?utm_source=dev&utm_medium=Blog&utm_campaign=Ramit-20112019&utm_term=Ramit) such as LambdaTest but that is not the only reason to it. LambdaTest is a lot more!

### What is LambdaTest?

LambdaTest is a cross browser testing tool on cloud which offers both manual and automated browser compatibility testing on a Selenium Grid consisting 2000+ real browsers on cloud. LambdaTest allows you to execute parallel testing, generate detailed test reports of Selenium automation testing, provides you with recorded video of the entire test script execution, along with the ability to seamlessly integrate your Selenium automation testing suite with your favourite CI/CD tools. It also offers native plugins for Jenkins, and more.

## Selenium Automation Testing For SignUp Page With LambdaTest

So, now let’s discuss the process of how we can integrate our test script with LambdaTest and execute it to see the results.In our selenium test script we initialize the WebDriver as,

```
WebDriver driver = new ChromeDriver();
Or 
WebDriver driver = new FirefoxDriver();
Or 
WebDriver driver = new EdgeDriver();
```

While to start with, when we want to run test script on LambdaTest Selenium grid we have to initialize the WebDriver as

```
WebDriver driver = new RemoteWebDriver(new URL("https://" + username + ":" + accesskey + "@hub.lambdatest.com/wd/hub"),
DesiredCapabilities.firefox()); 
```

Now few questions will arise like what are these username and accesskey is for? So we can generate these username and accesskey from [LambdaTest Capabilities Generator](https://lambdatest.com/capabilities-generator/?utm_source=dev&utm_medium=Blog&utm_campaign=Ramit-20112019&utm_term=Ramit).

![LambdaTest Capabilities Generator.](https://www.lambdatest.com/blog/wp-content/uploads/2019/10/selenium-java5.png)

Here once we select the OS, Browser, Selenium WebDriver version etc., we can get the username and accesskey for our users which we can use in the test script.

**Note:** To generate this username and accesskey, you should be registered and logged in your LambdaTest account.

![Registeration](https://www.lambdatest.com/blog/wp-content/uploads/2019/10/selenium-java6.png)

So after we generate those username and accesskey, we can use those in our test script in integration with LambdaTest. We have created the following test script for the LambdaTest registration page/ Sign Up page, we have covered the test scenarios which we have discussed above as manual test cases and scenarios.

While executing any automation test cases, there are few steps which are common and required to perform at the start of the test suite while few needs to perform before every test case which we can call as pre conditions for the test case.  
For example: While executing every test case, we need to open the browser and navigate to the target URL before starting to execute the actual test case, delete cookies, etc..

For this purpose we use @BeforeClass and @BeforeMethod annotations from Test NG, so in our case we will need

- to set few capabilities (browser, platform etc.)
- Open the browser
- Delete cookies
- Open LambdaTest platform and navigate to Signup page
 
```
public String username = "yadneshshah91";  //your LambdaTest username
    public String accesskey = "1234ABCD";      //your LambdaTest access key
    public static RemoteWebDriver driver = null;
    public String gridURL = "@hub.lambdatest.com/wd/hub"; //LambdaTest Hub URL
    boolean status = false;
  
    
    //Setting up capabilities to run our test script
    @Parameters(value= {"browser","version"})
    @BeforeClass
    public void setUp(String browser, String version) throws Exception {
        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability("browserName", browser);
        capabilities.setCapability("version", version);
        capabilities.setCapability("platform", "win10"); // If this cap isn't specified, it will just get the any available one
        capabilities.setCapability("build", "LambdaTestSampleApp");
        capabilities.setCapability("name", "LambdaTestJavaSample");
        capabilities.setCapability("network", true); // To enable network logs
        capabilities.setCapability("visual", true); // To enable step by step screenshot
        capabilities.setCapability("video", true); // To enable video recording
        capabilities.setCapability("console", true); // To capture console logs
        try {
            driver = new RemoteWebDriver(new URL("https://" + username + ":" + accesskey + gridURL), capabilities);
        } catch (MalformedURLException e) {
            System.out.println("Invalid grid URL");
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
               
    }
    
    //Opening browser with the given URL and navigate to Registration Page
    @BeforeMethod
    public void openBrowser()
    {
    	driver.manage().deleteAllCookies();
    	
		driver.get("https://www.lambdatest.com/");
        
        driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
        driver.manage().timeouts().pageLoadTimeout(15, TimeUnit.SECONDS);
        
        WebElement signUpButton = driver.findElement(By.xpath("//a[contains(text(),'Free Signup')]"));
        signUpButton.click(); 
        
    }
```

In the above part of code, notice the DesiredCapabilities object. This object is used to set capabilities like browser, version, operating system etc, and instructs LambdaTest grid to run tests on the desired configurations. If you want to run tests locally, then you would not necessarily need this object. , then we opened the browser, deleted cookies, navigate to default page of the LambdaTest and then click on the Sign Up button to redirect to our target page which is Sign Up page.

Same is the case for the operations/tasks which are required to perform at the end or after the execution of test cases.  
For Example: Closing the browser session, etc.

For this we have used @AfterMethod or @AfterMethod annotations from TestNG. If you are new to TestNG, then I suggest you read our detailed article on [TestNG annotations](https://www.lambdatest.com/blog/complete-guide-on-testng-annotations-for-selenium-webdriver/?utm_source=dev&utm_medium=Blog&utm_campaign=Ramit-20112019&utm_term=Ramit).

```
// Closing the browser session after completing each test case
    @AfterClass
    public void tearDown() throws Exception {
       if (driver != null) {
            ((JavascriptExecutor) driver).executeScript("lambda-status=" + status);
            driver.quit();
        }
    } 
```


In the above part of the code, you can see that we have closed the browser session which we need to do after every test case.

As we have seen, what and how it works before and after every test case now let us execute Selenium automation testing for the test cases, discussed above. In any Selenium automation test script, to perform any actions on the elements of the web page, we need to locate them first. For this, we make use of [Selenium Locators](https://www.lambdatest.com/blog/locators-in-selenium-webdriver-with-examples/?utm_source=dev&utm_medium=Blog&utm_campaign=Ramit-20112019&utm_term=Ramit).

## Diving Deep Into Test Cases

Let’s look into our test cases to comprehend our test scenarios that we need to automate with Selenium testing.

### Test Case 1

To verify if the expected elements are available on the Sign Up page.

```
//Verifying elements on Registration page
    @Test
    public void verifyElemntsOnPageTest()
    {
    	WebElement lambdaTestLogo = driver.findElement(By.xpath("//p[@class='signup-titel']"));
    	lambdaTestLogo.isDisplayed();
    	
    	WebElement signUpTitle = driver.findElement(By.xpath("//p[@class='signup-titel']"));
    	signUpTitle.isDisplayed();
    	
    	WebElement termsText = driver.findElement(By.xpath("//label[@class='woo']"));
    	termsText.isDisplayed();
    	
    	WebElement loginLinkText = driver.findElement(By.xpath("//p[@class='login-in-link test-left']"));
    	loginLinkText.isDisplayed();
    	
    }
```

In the above test case function verifyElemntsOnPageTest, we have located a few elements like LambdaTest logo, Sign up title, terms of services text, etc. To locate the web elements we can use different locating strategies like ID, XPath, CSS Selector, ClassName, etc.. In the above case, we have located those elements using XPath.

Once those elements are located, we have verified each of them if those are displayed using method isDisplayed().

### Test Case 2

```
To verify the redirections with the links present on the pages.

//Verifying redirection to the terms and conditions page
    @Test
    public void termsRedirectionTest()
    {
    	WebElement termsLink = driver.findElement(By.xpath("//a[contains(text(),'Terms')]"));
    	termsLink.click();    	
    	
    	Set <String> allWindows = driver.getWindowHandles();
    	
    	for(String handle : allWindows)
    	{
    		driver.switchTo().window(handle);
    	}    	        	
    	  	
    	String expectedURL = "https://www.lambdatest.com/terms-of-service";
    	String actualURL = driver.getCurrentUrl();
    	//System.out.println(actualURL);
    	Assert.assertEquals(actualURL, expectedURL);
    	
    	String expectedTitle = "Terms of Service - LambdaTest";
    	String actualTitle = driver.getTitle();
    	//System.out.println(actualTitle);
    	Assert.assertEquals(actualTitle, expectedTitle);    	
    }

//Verifying Privacy policy page redirection
    @Test
    public void privacyPolicyRedirectionTest()
    {
    	WebElement privacyPolicyLink = driver.findElement(By.xpath("//a[contains(text(),'Privacy')]"));
    	privacyPolicyLink.click();
    	
    	Set <String> allWindows = driver.getWindowHandles();
    	
    	for(String handle : allWindows)
    	{
    		driver.switchTo().window(handle);
    	}    	        	
    	  	
    	String expectedURL = "https://www.lambdatest.com/privacy";
    	String actualURL = driver.getCurrentUrl();
    	//System.out.println(actualURL);
    	Assert.assertEquals(actualURL, expectedURL);
    	
    	String expectedTitle = "Privacy Policy | LambdaTest";
    	String actualTitle = driver.getTitle();
    	//System.out.println(actualTitle);
    	Assert.assertEquals(actualTitle, expectedTitle);
    }    
    
    //Verifying redirection to the Login page from Registration page
    @Test
    public void loginRedirectionTest()
    {
    	WebElement loginLink = driver.findElement(By.xpath("//a[contains(text(),'Login')]"));
    	loginLink.click();
    	
    	String expectedURL = "https://accounts.lambdatest.com/login";
    	String actualURL = driver.getCurrentUrl();
    	//System.out.println(actualURL);
    	Assert.assertEquals(actualURL, expectedURL);
    	
    	String expectedTitle = "Login - LambdaTest";
    	String actualTitle = driver.getTitle();
    	//System.out.println(actualTitle);
    	Assert.assertEquals(actualTitle, expectedTitle);    	
    }
    
    //Verifying redirection to the landing page
    @Test
    public void landingPageRedirectionTest()
    {
    	WebElement lambdaTestLogo = driver.findElement(By.xpath("//p[@class='logo-home']//a//img"));
    	lambdaTestLogo.click();
    	
    	String expectedURL = "https://www.lambdatest.com/";
    	String actualURL = driver.getCurrentUrl();
    	Assert.assertEquals(actualURL, expectedURL);
    	
    	String expectedTitle = "";
    }
```

So here, you can see we have added 4 methods for different links present on the Sign Up page and we have verified after clicking those links user is redirected to the correct URL and page or not. In the above methods, we have also added assertions to verify if the redirection is done as expected.

### Test Case 3

To verify Registration process with providing valid input data.

```
// Registration with all valid data
    @Test
    public void validRegistrationTest(){            
              
        WebElement companyName = driver.findElement(By.name("organization_name"));
        companyName.sendKeys("TestCompany");
             
        WebElement fullName = driver.findElement(By.name("name"));
        fullName.sendKeys("TestName");
             
        WebElement email = driver.findElement(By.name("email"));
        email.sendKeys("test6.lambdatest@gmail.com");
         
        WebElement password = driver.findElement(By.name("password"));
        password.sendKeys("Test@12345");
 
        WebElement phone = driver.findElement(By.name("phone"));
        phone.sendKeys("9876543210");
            
        WebElement termsOfServices = driver.findElement(By.id("terms_of_service"));
        termsOfServices.click();
              
        WebElement signUp = driver.findElement(By.xpath("//button[contains(@class,'btn sign-up-btn-2 btn-block')]"));
        signUp.click();
        
        String expectedURL = "https://accounts.lambdatest.com/email/verify";
        String actualURL = driver.getCurrentUrl();
        Assert.assertEquals(actualURL, expectedURL);
        
        String expectedTitle = "Verify Your Email Address - LambdaTest";
        String actualTitle = driver.getTitle();
        Assert.assertEquals(actualTitle, expectedTitle);
                
    }
```
### Test Case 4

To verify registration process with different invalid input data.

```
// Registration without providing Company Name field
    @Test
    public void emptyCompanyNameTest()
    {
    	 WebElement companyName = driver.findElement(By.name("organization_name"));
         companyName.sendKeys("");
              
         WebElement fullName = driver.findElement(By.name("name"));
         fullName.sendKeys("TestName");
              
         WebElement email = driver.findElement(By.name("email"));
         email.sendKeys("test7.lambdatest@gmail.com");
          
         WebElement password = driver.findElement(By.name("password"));
         password.sendKeys("Test@12345");
  
         WebElement phone = driver.findElement(By.name("phone"));
         phone.sendKeys("9876543210");
             
         WebElement termsOfServices = driver.findElement(By.id("terms_of_service"));
         termsOfServices.click();
               
         WebElement signUp = driver.findElement(By.xpath("//button[contains(@class,'btn sign-up-btn-2 btn-block')]"));
         signUp.click();         
         
		/*
		 * Set <String> allWindows = driver.getWindowHandles();
		 * 
		 * for(String handle : allWindows) { driver.switchTo().window(handle); }
		 */ 
         
         String expectedURL = "https://accounts.lambdatest.com/email/verify";
         String actualURL = driver.getCurrentUrl();
         Assert.assertEquals(actualURL, expectedURL);
         
         String expectedTitle = "Verify Your Email Address - LambdaTest";
         String actualTitle = driver.getTitle();
         Assert.assertEquals(actualTitle, expectedTitle);
    }
    
    // Registration without providing Name field
    @Test
    public void emptyNameTest()
    {
        WebElement companyName = driver.findElement(By.name("organization_name"));
        companyName.sendKeys("TestCompany");
          
        WebElement fullName = driver.findElement(By.name("name"));
        fullName.sendKeys("");
         
        WebElement email = driver.findElement(By.name("email"));
        email.sendKeys("test@test.com");
                 
        WebElement password = driver.findElement(By.name("password"));
        password.sendKeys("Test@123");
          
        WebElement phone = driver.findElement(By.name("phone"));
        phone.sendKeys("9876543210");
            
        WebElement termsOfServices = driver.findElement(By.id("terms_of_service"));
        termsOfServices.click();
         
        WebElement signUp = driver.findElement(By.xpath("//button[contains(@class,'btn sign-up-btn-2 btn-block')]"));
        signUp.click();
        
        String expectedErrorMsg = "Please enter your Name";
        
        WebElement exp = driver.findElement(By.xpath("//p[contains(text(),'Please enter your Name')]"));
        String actualErrorMsg = exp.getText();
        		
        Assert.assertEquals(actualErrorMsg, expectedErrorMsg);
        
    }
    
    // Registration without providing user email field
    @Test
    public void emptyEmailTest()
    {
    	WebElement companyName = driver.findElement(By.name("organization_name"));
        companyName.sendKeys("TestCompany");
          
        WebElement fullName = driver.findElement(By.name("name"));
        fullName.sendKeys("test");
         
        WebElement email = driver.findElement(By.name("email"));
        email.sendKeys("");
                 
        WebElement password = driver.findElement(By.name("password"));
        password.sendKeys("Test@123");
          
        WebElement phone = driver.findElement(By.name("phone"));
        phone.sendKeys("9876543210");
            
        WebElement termsOfServices = driver.findElement(By.id("terms_of_service"));
        termsOfServices.click();
         
        WebElement signUp = driver.findElement(By.xpath("//button[contains(@class,'btn sign-up-btn-2 btn-block')]"));
        signUp.click();
        
        String expectedErrorMsg = "Please enter your Email Address";
        
        WebElement exp = driver.findElement(By.xpath("//p[contains(text(),'Please enter your Email Address')]"));
        String actualErrorMsg = exp.getText();
        		
        Assert.assertEquals(actualErrorMsg, expectedErrorMsg);
    }
    
    // Registration with email id which already have account
    @Test
    public void invalidEmailTest()
    {
        
        WebElement companyName = driver.findElement(By.name("organization_name"));
        companyName.sendKeys("TestCompany");
          
        WebElement fullName = driver.findElement(By.name("name"));
        fullName.sendKeys("TestName");
         
        WebElement email = driver.findElement(By.name("email"));
        email.sendKeys("test@test.com");
                 
        WebElement password = driver.findElement(By.name("password"));
        password.sendKeys("Test@123");
          
        WebElement phone = driver.findElement(By.name("phone"));
        phone.sendKeys("9876543210");
            
        WebElement termsOfServices = driver.findElement(By.id("terms_of_service"));
        termsOfServices.click();
         
        WebElement signUp = driver.findElement(By.xpath("//button[contains(@class,'btn sign-up-btn-2 btn-block')]"));
        signUp.click();
        
        String expectedErrorMsg = "This email is already registered";
        
        WebElement exp = driver.findElement(By.xpath("//p[@class='error-mass']"));
        String actualErrorMsg = exp.getText();
        		
        Assert.assertEquals(actualErrorMsg, expectedErrorMsg);
    }
    
    // Registration without providing password field
    @Test
    public void emptyPasswordTest()
    {
    	WebElement companyName = driver.findElement(By.name("organization_name"));
        companyName.sendKeys("TestCompany");
          
        WebElement fullName = driver.findElement(By.name("name"));
        fullName.sendKeys("TestName");
         
        WebElement email = driver.findElement(By.name("email"));
        email.sendKeys("test@test.com");
                 
        WebElement password = driver.findElement(By.name("password"));
        password.sendKeys("");
          
        WebElement phone = driver.findElement(By.name("phone"));
        phone.sendKeys("9876543210");
            
        WebElement termsOfServices = driver.findElement(By.id("terms_of_service"));
        termsOfServices.click();
         
        WebElement signUp = driver.findElement(By.xpath("//button[contains(@class,'btn sign-up-btn-2 btn-block')]"));
        signUp.click();
        
        String expectedErrorMsg = "Please enter a desired password";
        
        WebElement exp = driver.findElement(By.xpath("//p[contains(text(),'Please enter a desired password')]"));
        String actualErrorMsg = exp.getText();
        		
        Assert.assertEquals(actualErrorMsg, expectedErrorMsg);
    }
    
    // Registration with invalid password
    @Test
    public void inValidPasswordTest()
    {
        WebElement companyName = driver.findElement(By.name("organization_name"));
        companyName.sendKeys("TestCompany");
          
        WebElement fullName = driver.findElement(By.name("name"));
        fullName.sendKeys("TestName");
         
        WebElement email = driver.findElement(By.name("email"));
        email.sendKeys("test@test.com");
                 
        WebElement password = driver.findElement(By.name("password"));
        password.sendKeys("T");
          
        WebElement phone = driver.findElement(By.name("phone"));
        phone.sendKeys("9876543210");
            
        WebElement termsOfServices = driver.findElement(By.id("terms_of_service"));
        termsOfServices.click();
         
        WebElement signUp = driver.findElement(By.xpath("//button[contains(@class,'btn sign-up-btn-2 btn-block')]"));
        signUp.click();
        
        String expectedErrorMsg = "Password should be at least 8 characters long";
        
        WebElement exp = driver.findElement(By.xpath("//p[contains(text(),'Password should be at least 8 characters long')]"));
        String actualErrorMsg = exp.getText();
        		
        Assert.assertEquals(actualErrorMsg, expectedErrorMsg);
    	//Password should be at least 8 characters long
    }
  
    // Registration without providing user phone number field
    @Test
    public void emptyPhoneTest()
    {
    	WebElement companyName = driver.findElement(By.name("organization_name"));
        companyName.sendKeys("TestCompany");
          
        WebElement fullName = driver.findElement(By.name("name"));
        fullName.sendKeys("TestName");
         
        WebElement email = driver.findElement(By.name("email"));
        email.sendKeys("test@test.com");
                 
        WebElement password = driver.findElement(By.name("password"));
        password.sendKeys("Test@123");
          
        WebElement phone = driver.findElement(By.name("phone"));
        phone.sendKeys("");
            
        WebElement termsOfServices = driver.findElement(By.id("terms_of_service"));
        termsOfServices.click();
         
        WebElement signUp = driver.findElement(By.xpath("//button[contains(@class,'btn sign-up-btn-2 btn-block')]"));
        signUp.click();
        
        String expectedErrorMsg = "The phone field is required.";
        
        WebElement exp = driver.findElement(By.xpath("//p[contains(text(),'The phone field is required.')]"));
        String actualErrorMsg = exp.getText();
        		
        Assert.assertEquals(actualErrorMsg, expectedErrorMsg);
    }
    
    // Registration with providing invalid user phone number field
    @Test
    public void inValidPhoneTest()
    {
        WebElement companyName = driver.findElement(By.name("organization_name"));
        companyName.sendKeys("TestCompany");
          
        WebElement fullName = driver.findElement(By.name("name"));
        fullName.sendKeys("TestName");
         
        WebElement email = driver.findElement(By.name("email"));
        email.sendKeys("test@test.com");
                 
        WebElement password = driver.findElement(By.name("password"));
        password.sendKeys("Test@123");
          
        WebElement phone = driver.findElement(By.name("phone"));
        phone.sendKeys("98");
            
        WebElement termsOfServices = driver.findElement(By.id("terms_of_service"));
        termsOfServices.click();
         
        WebElement signUp = driver.findElement(By.xpath("//button[contains(@class,'btn sign-up-btn-2 btn-block')]"));
        signUp.click();
        
        String expectedErrorMsg = "Please enter a valid Phone number";
        
        WebElement exp = driver.findElement(By.xpath("//p[contains(text(),'Please enter a valid Phone number')]"));
        String actualErrorMsg = exp.getText();
        		
        Assert.assertEquals(actualErrorMsg, expectedErrorMsg);
        
    	//Please enter a valid Phone number
    }
    
    // Registration without accepting terms and condition tickbox
    @Test
    public void uncheckedTerms()
    {
        WebElement companyName = driver.findElement(By.name("organization_name"));
        companyName.sendKeys("TestCompany");
          
        WebElement fullName = driver.findElement(By.name("name"));
        fullName.sendKeys("TestName");
         
        WebElement email = driver.findElement(By.name("email"));
        email.sendKeys("test@test.com");
                 
        WebElement password = driver.findElement(By.name("password"));
        password.sendKeys("Test@123");
          
        WebElement phone = driver.findElement(By.name("phone"));
        phone.sendKeys("9876543210");
            
        //WebElement termsOfServices = driver.findElement(By.id("terms_of_service"));
        //termsOfServices.click();
         
        WebElement signUp = driver.findElement(By.xpath("//button[contains(@class,'btn sign-up-btn-2 btn-block')]"));
        signUp.click();
        
        String expectedTermsErrorMessage = "To proceed further you must agree to our Terms of Service and Privacy Policy";
        WebElement uncheckedTermCheckbox = driver.findElement(By.xpath("//p[@class='error-mass mt-2']"));
    	String actualTermsErrorMessage = uncheckedTermCheckbox.getText();
        //To proceed further you must agree to our Terms of Service and Privacy Policy
    	
    	Assert.assertEquals(actualTermsErrorMessage, expectedTermsErrorMessage);
    }
```


In the above part of code, you can see that we have covered different cases in which one or other field is provided with invalid input data. Also, at the end of every method we have added assertion along with expected error messages for the invalid input we have provided.

## Entire Test Script To Automate Sign Up Using Selenium And Java

As we have seen the Selenium automation testing script and different test cases in bits and pieces, now, let us combine this code to present the entire test script which we can be executed on multiple browsers which we provide as parameter.  
So please also refer the testng.xml file which is provided at the end, which is very important to execute Selenium automation testing in parallel across different browsers.

Automation test script for LambdaTest Registration Page:

```
package com.lambdatest;


//TestNG Todo : Sample App
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.Platform;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
import org.testng.asserts.Assertion;

import com.beust.jcommander.Parameter;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.Set;
import java.util.concurrent.TimeUnit;
 
public class SignUpTest{
    
	public String username = "yadneshshah91";
    public String accesskey = "iD4oCZKyC8R2kwH1kLhTxAGgXZFANGoyzGDzY9RTqDTx9jskZo";
    public static RemoteWebDriver driver = null;
    public String gridURL = "@hub.lambdatest.com/wd/hub";
    boolean status = false;
  
    
    //Setting up capabilities to run our test script
    @Parameters(value= {"browser","version"})
    @BeforeClass
    public void setUp(String browser, String version) throws Exception {
        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability("browserName", browser);
        capabilities.setCapability("version", version);
        capabilities.setCapability("platform", "win10"); // If this cap isn't specified, it will just get any available one
        capabilities.setCapability("build", "LambdaTestSampleApp");
        capabilities.setCapability("name", "LambdaTestJavaSample");
        capabilities.setCapability("network", true); // To enable network logs
        capabilities.setCapability("visual", true); // To enable step by step screenshot
        capabilities.setCapability("video", true); // To enable video recording
        capabilities.setCapability("console", true); // To capture console logs
        try {
            driver = new RemoteWebDriver(new URL("https://" + username + ":" + accesskey + gridURL), capabilities);
        } catch (MalformedURLException e) {
            System.out.println("Invalid grid URL");
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
               
    }
    
    //Opening browser with the given URL and navigate to Registration Page
    @BeforeMethod
    public void openBrowser()
    {
    	driver.manage().deleteAllCookies();
    	
		driver.get("https://www.lambdatest.com/");
        
        driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
        driver.manage().timeouts().pageLoadTimeout(15, TimeUnit.SECONDS);
        
        WebElement signUpButton = driver.findElement(By.xpath("//a[contains(text(),'Start Free Testing')]"));
        signUpButton.click(); 
        
    }
    
    //Verifying elements on Registration page
    @Test
    public void verifyElemntsOnPageTest()
    {
    	WebElement lambdaTestLogo = driver.findElement(By.xpath("//p[@class='signup-titel']"));
    	lambdaTestLogo.isDisplayed();
    	
    	WebElement signUpTitle = driver.findElement(By.xpath("//p[@class='signup-titel']"));
    	signUpTitle.isDisplayed();
    	
    	WebElement termsText = driver.findElement(By.xpath("//label[@class='woo']"));
    	termsText.isDisplayed();
    	
    	WebElement loginLinkText = driver.findElement(By.xpath("//p[@class='login-in-link test-left']"));
    	loginLinkText.isDisplayed();
    	
    }
    
    //Verifying redirection to the terms and conditions page
    @Test
    public void termsRedirectionTest()
    {
    	WebElement termsLink = driver.findElement(By.xpath("//a[contains(text(),'Terms')]"));
    	termsLink.click();    	
    	
    	Set <String> allWindows = driver.getWindowHandles();
    	
    	for(String handle : allWindows)
    	{
    		driver.switchTo().window(handle);
    	}    	        	
    	  	
    	String expectedURL = "https://www.lambdatest.com/terms-of-service";
    	String actualURL = driver.getCurrentUrl();
    	//System.out.println(actualURL);
    	Assert.assertEquals(actualURL, expectedURL);
    	
    	String expectedTitle = "Terms of Service - LambdaTest";
    	String actualTitle = driver.getTitle();
    	//System.out.println(actualTitle);
    	Assert.assertEquals(actualTitle, expectedTitle);    	
    }
    
    //Verifying Privacy policy page redirection
    @Test
    public void privacyPolicyRedirectionTest()
    {
    	WebElement privacyPolicyLink = driver.findElement(By.xpath("//a[contains(text(),'Privacy')]"));
    	privacyPolicyLink.click();
    	
    	Set <String> allWindows = driver.getWindowHandles();
    	
    	for(String handle : allWindows)
    	{
    		driver.switchTo().window(handle);
    	}    	        	
    	  	
    	String expectedURL = "https://www.lambdatest.com/privacy";
    	String actualURL = driver.getCurrentUrl();
    	//System.out.println(actualURL);
    	Assert.assertEquals(actualURL, expectedURL);
    	
    	String expectedTitle = "Privacy Policy | LambdaTest";
    	String actualTitle = driver.getTitle();
    	//System.out.println(actualTitle);
    	Assert.assertEquals(actualTitle, expectedTitle);
    }    
    
    //Verifying redirection to the Login page from Registration page
    @Test
    public void loginRedirectionTest()
    {
    	WebElement loginLink = driver.findElement(By.xpath("//a[contains(text(),'Login')]"));
    	loginLink.click();
    	
    	String expectedURL = "https://accounts.lambdatest.com/login";
    	String actualURL = driver.getCurrentUrl();
    	//System.out.println(actualURL);
    	Assert.assertEquals(actualURL, expectedURL);
    	
    	String expectedTitle = "Login - LambdaTest";
    	String actualTitle = driver.getTitle();
    	//System.out.println(actualTitle);
    	Assert.assertEquals(actualTitle, expectedTitle);    	
    }
    
    //Verifying redirection to the landing page
    @Test
    public void landingPageRedirectionTest()
    {
    	WebElement lambdaTestLogo = driver.findElement(By.xpath("//p[@class='logo-home']//a//img"));
    	lambdaTestLogo.click();
    	
    	String expectedURL = "https://www.lambdatest.com/";
    	String actualURL = driver.getCurrentUrl();
    	Assert.assertEquals(actualURL, expectedURL);
    	
    	
    }
  
    // Registration with all valid data
    @Test
    public void validRegistrationTest(){            
              
        WebElement companyName = driver.findElement(By.name("organization_name"));
        companyName.sendKeys("TestCompany");
             
        WebElement fullName = driver.findElement(By.name("name"));
        fullName.sendKeys("TestName");
             
        WebElement email = driver.findElement(By.name("email"));
        email.sendKeys("test6.lambdatest@gmail.com");
         
        WebElement password = driver.findElement(By.name("password"));
        password.sendKeys("Test@12345");
 
        WebElement phone = driver.findElement(By.name("phone"));
        phone.sendKeys("9876543210");
            
        WebElement termsOfServices = driver.findElement(By.id("terms_of_service"));
        termsOfServices.click();
              
        WebElement signUp = driver.findElement(By.xpath("//button[contains(@class,'btn sign-up-btn-2 btn-block')]"));
        signUp.click();
        
        String expectedURL = "https://accounts.lambdatest.com/email/verify";
        String actualURL = driver.getCurrentUrl();
        Assert.assertEquals(actualURL, expectedURL);
        
        String expectedTitle = "Verify Your Email Address - LambdaTest";
        String actualTitle = driver.getTitle();
        Assert.assertEquals(actualTitle, expectedTitle);
        
        
    }
    
    // Registration without providing Company Name field
    @Test
    public void emptyCompanyNameTest()
    {
    	 WebElement companyName = driver.findElement(By.name("organization_name"));
         companyName.sendKeys("");
              
         WebElement fullName = driver.findElement(By.name("name"));
         fullName.sendKeys("TestName");
              
         WebElement email = driver.findElement(By.name("email"));
         email.sendKeys("test7.lambdatest@gmail.com");
          
         WebElement password = driver.findElement(By.name("password"));
         password.sendKeys("Test@12345");
  
         WebElement phone = driver.findElement(By.name("phone"));
         phone.sendKeys("9876543210");
             
         WebElement termsOfServices = driver.findElement(By.id("terms_of_service"));
         termsOfServices.click();
               
         WebElement signUp = driver.findElement(By.xpath("//button[contains(@class,'btn sign-up-btn-2 btn-block')]"));
         signUp.click();
         
         
		/*
		 * Set <String> allWindows = driver.getWindowHandles();
		 * 
		 * for(String handle : allWindows) { driver.switchTo().window(handle); }
		 */ 
         
         String expectedURL = "https://accounts.lambdatest.com/email/verify";
         String actualURL = driver.getCurrentUrl();
         Assert.assertEquals(actualURL, expectedURL);
         
         String expectedTitle = "Verify Your Email Address - LambdaTest";
         String actualTitle = driver.getTitle();
         Assert.assertEquals(actualTitle, expectedTitle);
    }
    
    // Registration without providing Name field
    @Test
    public void emptyNameTest()
    {
        WebElement companyName = driver.findElement(By.name("organization_name"));
        companyName.sendKeys("TestCompany");
          
        WebElement fullName = driver.findElement(By.name("name"));
        fullName.sendKeys("");
         
        WebElement email = driver.findElement(By.name("email"));
        email.sendKeys("test@test.com");
                 
        WebElement password = driver.findElement(By.name("password"));
        password.sendKeys("Test@123");
          
        WebElement phone = driver.findElement(By.name("phone"));
        phone.sendKeys("9876543210");
            
        WebElement termsOfServices = driver.findElement(By.id("terms_of_service"));
        termsOfServices.click();
         
        WebElement signUp = driver.findElement(By.xpath("//button[contains(@class,'btn sign-up-btn-2 btn-block')]"));
        signUp.click();
        
        String expectedErrorMsg = "Please enter your Name";
        
        WebElement exp = driver.findElement(By.xpath("//p[contains(text(),'Please enter your Name')]"));
        String actualErrorMsg = exp.getText();
        		
        Assert.assertEquals(actualErrorMsg, expectedErrorMsg);
        
    }
    
    // Registration without providing user email field
    @Test
    public void emptyEmailTest()
    {
    	WebElement companyName = driver.findElement(By.name("organization_name"));
        companyName.sendKeys("TestCompany");
          
        WebElement fullName = driver.findElement(By.name("name"));
        fullName.sendKeys("test");
         
        WebElement email = driver.findElement(By.name("email"));
        email.sendKeys("");
                 
        WebElement password = driver.findElement(By.name("password"));
        password.sendKeys("Test@123");
          
        WebElement phone = driver.findElement(By.name("phone"));
        phone.sendKeys("9876543210");
            
        WebElement termsOfServices = driver.findElement(By.id("terms_of_service"));
        termsOfServices.click();
         
        WebElement signUp = driver.findElement(By.xpath("//button[contains(@class,'btn sign-up-btn-2 btn-block')]"));
        signUp.click();
        
        String expectedErrorMsg = "Please enter your Email Address";
        
        WebElement exp = driver.findElement(By.xpath("//p[contains(text(),'Please enter your Email Address')]"));
        String actualErrorMsg = exp.getText();
        		
        Assert.assertEquals(actualErrorMsg, expectedErrorMsg);
    }
    
    // Registration with email id which already have account
    @Test
    public void invalidEmailTest()
    {
        
        WebElement companyName = driver.findElement(By.name("organization_name"));
        companyName.sendKeys("TestCompany");
          
        WebElement fullName = driver.findElement(By.name("name"));
        fullName.sendKeys("TestName");
         
        WebElement email = driver.findElement(By.name("email"));
        email.sendKeys("test@test.com");
                 
        WebElement password = driver.findElement(By.name("password"));
        password.sendKeys("Test@123");
          
        WebElement phone = driver.findElement(By.name("phone"));
        phone.sendKeys("9876543210");
            
        WebElement termsOfServices = driver.findElement(By.id("terms_of_service"));
        termsOfServices.click();
         
        WebElement signUp = driver.findElement(By.xpath("//button[contains(@class,'btn sign-up-btn-2 btn-block')]"));
        signUp.click();
        
        String expectedErrorMsg = "This email is already registered";
        
        WebElement exp = driver.findElement(By.xpath("//p[@class='error-mass']"));
        String actualErrorMsg = exp.getText();
        		
        Assert.assertEquals(actualErrorMsg, expectedErrorMsg);
    }
    
    // Registration without providing password field
    @Test
    public void emptyPasswordTest()
    {
    	WebElement companyName = driver.findElement(By.name("organization_name"));
        companyName.sendKeys("TestCompany");
          
        WebElement fullName = driver.findElement(By.name("name"));
        fullName.sendKeys("TestName");
         
        WebElement email = driver.findElement(By.name("email"));
        email.sendKeys("test@test.com");
                 
        WebElement password = driver.findElement(By.name("password"));
        password.sendKeys("");
          
        WebElement phone = driver.findElement(By.name("phone"));
        phone.sendKeys("9876543210");
            
        WebElement termsOfServices = driver.findElement(By.id("terms_of_service"));
        termsOfServices.click();
         
        WebElement signUp = driver.findElement(By.xpath("//button[contains(@class,'btn sign-up-btn-2 btn-block')]"));
        signUp.click();
        
        String expectedErrorMsg = "Please enter a desired password";
        
        WebElement exp = driver.findElement(By.xpath("//p[contains(text(),'Please enter a desired password')]"));
        String actualErrorMsg = exp.getText();
        		
        Assert.assertEquals(actualErrorMsg, expectedErrorMsg);
    }
    
    // Registration with invalid password
    @Test
    public void inValidPasswordTest()
    {
        WebElement companyName = driver.findElement(By.name("organization_name"));
        companyName.sendKeys("TestCompany");
          
        WebElement fullName = driver.findElement(By.name("name"));
        fullName.sendKeys("TestName");
         
        WebElement email = driver.findElement(By.name("email"));
        email.sendKeys("test@test.com");
                 
        WebElement password = driver.findElement(By.name("password"));
        password.sendKeys("T");
          
        WebElement phone = driver.findElement(By.name("phone"));
        phone.sendKeys("9876543210");
            
        WebElement termsOfServices = driver.findElement(By.id("terms_of_service"));
        termsOfServices.click();
         
        WebElement signUp = driver.findElement(By.xpath("//button[contains(@class,'btn sign-up-btn-2 btn-block')]"));
        signUp.click();
        
        String expectedErrorMsg = "Password should be at least 8 characters long";
        
        WebElement exp = driver.findElement(By.xpath("//p[contains(text(),'Password should be at least 8 characters long')]"));
        String actualErrorMsg = exp.getText();
        		
        Assert.assertEquals(actualErrorMsg, expectedErrorMsg);
    	//Password should be at least 8 characters long
    }
  
    // Registration without providing user phone number field
    @Test
    public void emptyPhoneTest()
    {
    	WebElement companyName = driver.findElement(By.name("organization_name"));
        companyName.sendKeys("TestCompany");
          
        WebElement fullName = driver.findElement(By.name("name"));
        fullName.sendKeys("TestName");
         
        WebElement email = driver.findElement(By.name("email"));
        email.sendKeys("test@test.com");
                 
        WebElement password = driver.findElement(By.name("password"));
        password.sendKeys("Test@123");
          
        WebElement phone = driver.findElement(By.name("phone"));
        phone.sendKeys("");
            
        WebElement termsOfServices = driver.findElement(By.id("terms_of_service"));
        termsOfServices.click();
         
        WebElement signUp = driver.findElement(By.xpath("//button[contains(@class,'btn sign-up-btn-2 btn-block')]"));
        signUp.click();
        
        String expectedErrorMsg = "The phone field is required.";
        
        WebElement exp = driver.findElement(By.xpath("//p[contains(text(),'The phone field is required.')]"));
        String actualErrorMsg = exp.getText();
        		
        Assert.assertEquals(actualErrorMsg, expectedErrorMsg);
    }
    
    // Registration with providing invalid user phone number field
    @Test
    public void inValidPhoneTest()
    {
        WebElement companyName = driver.findElement(By.name("organization_name"));
        companyName.sendKeys("TestCompany");
          
        WebElement fullName = driver.findElement(By.name("name"));
        fullName.sendKeys("TestName");
         
        WebElement email = driver.findElement(By.name("email"));
        email.sendKeys("test@test.com");
                 
        WebElement password = driver.findElement(By.name("password"));
        password.sendKeys("Test@123");
          
        WebElement phone = driver.findElement(By.name("phone"));
        phone.sendKeys("98");
            
        WebElement termsOfServices = driver.findElement(By.id("terms_of_service"));
        termsOfServices.click();
         
        WebElement signUp = driver.findElement(By.xpath("//button[contains(@class,'btn sign-up-btn-2 btn-block')]"));
        signUp.click();
        
        String expectedErrorMsg = "Please enter a valid Phone number";
        
        WebElement exp = driver.findElement(By.xpath("//p[contains(text(),'Please enter a valid Phone number')]"));
        String actualErrorMsg = exp.getText();
        		
        Assert.assertEquals(actualErrorMsg, expectedErrorMsg);
        
    	//Please enter a valid Phone number
    }
    
    // Registration without accepting terms and condition tickbox
    @Test
    public void uncheckedTerms()
    {
        WebElement companyName = driver.findElement(By.name("organization_name"));
        companyName.sendKeys("TestCompany");
          
        WebElement fullName = driver.findElement(By.name("name"));
        fullName.sendKeys("TestName");
         
        WebElement email = driver.findElement(By.name("email"));
        email.sendKeys("test@test.com");
                 
        WebElement password = driver.findElement(By.name("password"));
        password.sendKeys("Test@123");
          
        WebElement phone = driver.findElement(By.name("phone"));
        phone.sendKeys("9876543210");
            
        //WebElement termsOfServices = driver.findElement(By.id("terms_of_service"));
        //termsOfServices.click();
         
        WebElement signUp = driver.findElement(By.xpath("//button[contains(@class,'btn sign-up-btn-2 btn-block')]"));
        signUp.click();
        
        String expectedTermsErrorMessage = "To proceed further you must agree to our Terms of Service and Privacy Policy";
        WebElement uncheckedTermCheckbox = driver.findElement(By.xpath("//p[@class='error-mass mt-2']"));
    	String actualTermsErrorMessage = uncheckedTermCheckbox.getText();
        //To proceed further you must agree to our Terms of Service and Privacy Policy
    	
    	Assert.assertEquals(actualTermsErrorMessage, expectedTermsErrorMessage);
    }
    
    // Closing the browser session after completing each test case
    @AfterClass
    public void tearDown() throws Exception {
       if (driver != null) {
            ((JavascriptExecutor) driver).executeScript("lambda-status=" + status);
            driver.quit();
        }
    }
}
```

In above test script example you can observe that we have used parameterized option to provide browser name and browser version, so that we can provide the browser and browser version as per our requirement on which we need to test above test script. We can also provide multiple browsers and version to execute our test script parallely.

And to achieve this we need to provide these value of browser name and version from testng.xml file, which we use with every TestNG script.  
For example, you can refer following testng.xml in which we have provided 2 browsers (Chrome and Firefox) with their respective versions.

```
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite thread-count="3" name="LambaTestSuite" parallel="tests">
  
  <test name="FirefoxTest">
  <parameter name="browser" value="firefox"/>
  <parameter name="version" value="69.0"/>
    <classes>
      <class name="com.lambdatest.SignUpTest"/>
    </classes>
  </test> <!-- Test -->
  
  <test name="ChromeTest">
  <parameter name="browser" value="chrome"/>
  <parameter name="version" value="77.0"/>
    <classes>
      <class name="com.lambdatest.SignUpTest"/>
    </classes>
  </test> <!-- Test -->
  
    <test name="EdgeTest">
  <parameter name="browser" value="edge"/>
  <parameter name="version" value="44.0"/>
    <classes>
      <class name="com.lambdatest.SignUpTest"/>
    </classes>
  </test> <!-- Test -->
  
</suite> <!-- Suite --> 
```


![test_cases](https://cdn.lambdatest.com/blog/wp-content/uploads/2019/10/pasted-image-0.png)

![test cases 2](https://www.lambdatest.com/blog/wp-content/uploads/2019/10/test-cases-2.png)

Below is a snapshot of the final execution that was triggered over the LambdaTest platform. We have executed the cross browser testing automation script over two browsers i.e. Google Chrome 77 and Mozilla Firefox 69.

![lambdatest dashboard](https://cdn.lambdatest.com/blog/wp-content/uploads/2019/10/lambdatest_testing.png)

If you gaze over the LambdaTest [automation dashboard](https://automation.lambdatest.com/?utm_source=dev&utm_medium=Blog&utm_campaign=Ramit-20112019&utm_term=Ramit), you will be able to notice multiple tabs representing different types of logs for your test automation script. You get tabs to analyze command logs, network logs, raw Selenium logs, metadata, and more. You also get a full video-recording of your cross browser testing script over the LambdaTest cloud servers, along with command-by-command screenshot.

## That Was All

Now, you are good to go with automation for Signup page using Selenium and Java. In this Selenium Java tutorial, we gazed upon the registration process of LambdaTest. We thought of different test cases, compiled a test script to have them executed and the [Selenium Automation testing](https://www.lambdatest.com/selenium-automation?utm_source=dev&utm_medium=Blog&utm_campaign=Ramit-20112019&utm_term=Ramit) script was then analyzed to run for different browsers in parallel.

The Selenium automation test scripts were executed using Selenium and Java, with the help of TestNG framework. In case you feel I missed out on a peculiar test cases regarding the LambdaTest registration page then feel free to let me know. I am all ears! Happy testing. 🙂

[![Adword  Dark Blue.jpg](https://ucarecdn.com/d28b6b28-2b25-4262-917b-357613768dc1/)](https://accounts.lambdatest.com/register/?utm_source=dev&utm_medium=Blog&utm_campaign=Ramit-20112019&utm_term=Ramit)