Examples of Selenium Webdriver Scripts

Examples of Selenium Webdriver Scripts

Now its time to code and execute the selenium webdriver scripts after installation of TestNG framework successfully.

Example 1: Create a class as “Example” copy and paste the below mentioned code and right click on classname and mouse over on "Run As" option and click on  “TestNG Test” option.


package Newpack;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.firefox.FirefoxDriver;

import org.testng.annotations.Test;

public class Example  {

            public String baseUrl= "http://www.google.com/";

            public WebDriver driver = new FirefoxDriver();


public void verifyHomePageTitle() {


        // Find the text input element by its name

        WebElement element = driver.findElement(By.name("q"));

        // Enter something to search for



        // Now submit the form. WebDriver will find the form for us from the element


        // Check the title of the page

        System.out.println("Page title is: " + driver.getTitle());





Results of running the Testng Test Case

13. Give it few minutes to complete the execution, once it is finished the results will look like this in the TestNg Result window.


It displayed ‘passed: 1′. This means test is successful and passed.

There are 3 sub tabs. “All Tests”, “Failed Tests” and “Summary”. Just click “All Tests” to see what is there.

all test

There is information of which test cases are executed and their duration.

14. TestNG also produce HTML reports. To access those reports go to test-output folder and open ‘emailable-report.html‘, as this is a html report open it with browser.


15. TestNG also produce ‘index.html‘ report and it resides in the same test-output folder. This reports gives the link to all the different component of the TestNG reports like Groups & Reporter Output. On clicking these will display detailed descriptions of execution. In the advance chapter of TestNG we will go though each of the TestNG topics.


Example 2: Create a script for Login and logout scenario as shown below and right click on classname and mouse over on "Run As" option and click on  “TestNG Test” option.


package com.test.webdriver;

import static org.testng.AssertJUnit.assertEquals;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.firefox.FirefoxDriver;

import org.testng.annotations.AfterClass;

import org.testng.annotations.BeforeClass;

import org.testng.annotations.Test; 

public class Driver {

private WebDriver driver;


 public void Startup(){

  driver = new FirefoxDriver();


 @Test (description="Google Login")

 public void GoogleLogin() throws Exception{


  assertEquals("Sign in", driver.findElement(By.id("signIn")).getAttribute("value"));









assertEquals("Sign in to Gmail", driver.findElement(By.id("button")).getText());



 public void teardown(){






Connect apps and integrate data with workflows using Azure Logic Apps

Implementing complex business process has been made easy. Logic Apps in azure provide a way to imple...

Read More >

TFS to VSTS Migrations

The next evolution of TFSWhether you’re a startup or Enterprise or you’re a team of just...

Read More >

CfMD services -Dynamics NAV

CfMD services help ISVs minimize the time and effort needed to get their software solution through t...

Read More >

Upcoming Webinar - Offshore support to North American Dynamics NAV partners

Offshore support to North American Dynamics NAV partners whose customers are moving to NAV '16Wh...

Read More >

Microsoft Azure Consultant

·         Executing technical feasibility as...

Read More >

Customer Feedback

Your feedback is important to us. Please share your experience working with Canarys & the journe...

Read More >


Multi-taskingIt is a concept of performing multiple tasks over a certain period of time by executing...

Read More >

Partnership Program

We understand that the world of technology is changing rapidly from day to day and businesses have m...

Read More >

Partnership Program

The Canarys Partner Program:Canarys is all set to expand its business reach across the Globe and is ...

Read More >

Upcoming Webinar US - Plugging for Cloud, Right or Wrong

Plugging for Cloud, Right or Wrong?Cloud computing continues to be one of the most advertising topic...

Read More >



Thanks for your post! Through your pen I found the problem up interesting! I believe there are many other people who are interested in them just like me! Thanks your shared!... I hope you will continue to have similar posts to share with everyone! I believe a lot of people will be surprised to read this article! Best DevOps online training in hyderabad
3/3/2020 4:57:02 PM | Reply
This is so cool! I love to read technical articles because the ideas will surely help me become better in my niche. There’s so much to learn from this blog. Got interested in selenium testing training after reading its importance and features. I’m sure, it will help with a rocketing career .keep going!
2/29/2020 5:53:55 PM | Reply
It was really a nice post and I was really impressed by reading this
1/24/2020 10:32:22 AM | Reply
I genuinely enjoyed this. It was extremely educational as well as helpful. I will return to examine on new posts.
1/20/2020 12:56:47 PM | Reply
I like reading through an article that can make men and women think. Also, many thanks for permitting me to comment!
12/23/2019 4:55:10 PM | Reply
You are so cool! I don't believe I have read a single thing like that before. So great to discover someone with a few unique thoughts on this subject. Seriously.. thanks for starting this up. This site is one thing that is required on the internet, someone with some originality!
12/23/2019 4:54:30 PM | Reply
Spot on with this write-up, I actually think this amazing site needs a great deal more attention. I’ll probably be back again to read through more, thanks for the information!
12/23/2019 4:54:03 PM | Reply
The very next time I read a blog, I hope that it won't disappoint me just as much as this one. I mean, Yes, it was my choice to read, but I genuinely thought you would have something useful to say. All I hear is a bunch of crying about something you can fix if you were not too busy searching for attention.
12/23/2019 4:53:35 PM | Reply
After I initially left a comment I seem to have clicked on the -Notify me when new comments are added- checkbox and from now on each time a comment is added I receive 4 emails with the exact same comment. Is there an easy method you can remove me from that service? Thanks a lot!
12/23/2019 4:53:04 PM | Reply
thank you very much to share this information to get some idea's.
10/14/2019 1:10:00 PM | Reply
very informative blog and useful article thank you for sharing with us, keep posting learn more Technology Dot net Course
9/20/2019 4:16:16 PM | Reply
The information which you have provided is very good. It is very useful who are looking for deep learning
8/20/2019 10:33:11 AM | Reply

Post a Comment

  • Recent
  • Popular
  • Tag
Monthly Archive

Contact Us
  • *
  • *