EIBIK.COM

    Subscribe to Updates

    Get the latest creative news from FooBar about art, design and business.

    What's Hot

    Rudy Gobert Biography | Career, Awards, Facts, Net Worth & More

    25th June 2022

    24 Best Car Games Unblocked To Play At School Or Work

    25th June 2022

    4 Easy Ways To Be Healthier 

    24th June 2022
    Facebook Twitter Instagram
    EIBIK.COMEIBIK.COM
    • Home
    • News
      • Finance
      • Current Affairs
    • Travel
    • Biography
      • Writer
      • Athlete
      • Politician
      • Scholar
      • People
    • Sports
      • Game
    • Technology
      • Electric & Electronic
    • Contact us
    • Write for us
    EIBIK.COM
    Home » Selenium Automation Testing With TestNG : Step By Step Guide

    Selenium Automation Testing With TestNG : Step By Step Guide

    AdminBy Admin26th May 2022Updated:26th May 2022 Technology 5 Mins Read
    Selenium Automation Testing With TestNG Step By Step Guide
    Share
    Facebook Twitter LinkedIn Pinterest Email

    TestNG by far is the most widely used framework for Selenium automation testing. We have already covered the features of TestNG and what makes it stand out in our TestNG series. Additionally, we have seen how to implement the TestNG framework in Eclipse, but with the increasing use and popularity of IntelliJ, we will now see how TestNG can be installed and implemented in IntelliJ.

    To get started, you will have first to fulfill a few prerequisites –

    • Download IntelliJ IDEA on your machine.
    • Download Selenium WebDriver Language Bindings for Java.

    Since we have already covered the selenium binding download in the Eclipse article, I assume that you know you need to save the jar files at any convenient location on your machine.

    Let us now begin with the installation of TestNG in IntelliJ.

    Table of Contents

    • Installing TestNG in IntelliJ
    • Setting Up TestNG in IntelliJ Project
    • Adding JAR files to the project
    • Adding Maven Dependencies to the project
    • Running first TestNG Test Script in IntelliJ
      • Use Case

    Installing TestNG in IntelliJ

    Step#1 As soon as you launch IntelliJ, navigate to Plugins tab.

    Step#2 You may then click on the Installed tab and search for TestNG. You will see the TestNG plugin displayed in the list. In case you do not see the plugIn you may click on Marketplace, search TestNG and install the same from the list displayed.

    And there you go! Did you see how easy it is to get TestNg in your IntelliJ IDE as compared to Eclipse? Next step is setting up the Java project with Selenium and TestNG libraries to start with our Selenium TestNG journey using IntelliJ.

    Setting Up TestNG in IntelliJ Project

    Once you have installed TestNg to the IntelliJ TDE, the next step is setting up the selenium and TestNG jar files in the IntelliJ project. So, there are two ways to go about it.

    1. First you may add the jars downloaded for Selenium language bindings and TestNG to your project structure.
    2. Alternatively you may create a Maven project and add the desired dependencies to your pom.xml.

    We will review both of these ways and you may select the way that best suits you.

    Adding JAR files to the project

    1. Create a new Java Project by navigating to File>New>Project.
    2. You then need to follow through the windows that appear, give a name to your project and click on Finish.You will see that the project is created as shown in the screenshot below-
    3. The next step is importing the Selenium jar files , i.e. the java language bindings that we have installed in our system.For this you need to go to File>Project Structure.
    4. The Project Structure dialog would open up. You need to click on Modules and then on Dependencies. To add the JARs you will have to click on the ‘+’ icon and then select JARs or Directories
    5. As soon as you select the JARs or Directories, you will see a new pop-up window like below-
    6. Once you select all the desired jars click on OK. You will see that the jar files imported within the External Libraries-
    7. Following the similar way add the TestNG jar file downloaded earlier.

    Your project is now set with Selenium and TestNG JAR files.

    Adding Maven Dependencies to the project

    Rather than adding the jars manually you may alternatively use Maven dependencies for Selenium and TestNG in the Maven project. Instead of the general project we will create a Maven project and follow the steps below to add the dependencies.

    1. You will find the Maven dependencies for Selenium and TestNG from the official Maven website. Let us first see how Selenium dependency is added.
    2. Similarly, you can add TestNG dependency in the pom.xml and save the same.

    Your Selenium TestNG project is now all set and you can proceed with writing your TestNG tests on IntelliJ IDE.

    Running first TestNG Test Script in IntelliJ

    Now that we are done setting up TestNG and Selenium libraries, the next and the final step is writing the test script. We will try and automate the below use case in our test script.

    Use Case

    • Open the LambdaTest website.
    • Compare the page title with the expected title.
    • Print the results.
    • Quit the browser.

    Let us look at how the code for this would look like.

    import org.openqa.selenium.WebDriver;

    import org.openqa.selenium.chrome.ChromeDriver;

    import org.testng.annotations.Test;

    public class TestOne {

    WebDriver driver;

    //TestNG annotation for the test method

    @Test

    public void TestOne(){

    //Setting the system properties to set chrome driver path

    System.setProperty(“webdriver.chrome.driver”, “D:\\Selenium\\chromedriver.exe”);

    driver = new ChromeDriver();

    //Navigating to the website

    driver.get(“https://www.lambdatest.com/”);

    //Method to maximise window

    driver.manage().window().maximize();

    String expectedTitle = “Most Powerful Cross Browser Testing Tool Online | LambdaTest”;

    String actualTitle = driver.getTitle();

    if(actualTitle.equalsIgnoreCase(expectedTitle))

    System.out.println(“We have landed on the correct page 🙂   >>> ” +actualTitle);

    else

    System.out.println(“Looks like it is an incorrect page :O  >>> ” +actualTitle);

    driver.quit();

    }

    }

    On executing the above code you will notice that the web browser opens up and the console logs display the TestNG logs with the test status.

    So now that you have seen how to install and set up TestNG in IntelliJ IDE you may go ahead and start your test automation journey using IntelliJ. But make sure that the jar files for Selenium and TestNG are in sync so that your test doesn’t fail.

    To perform Selenium testing with TestNG, you can choose from a different cloud testing platform like LambdaTest which offers manual and automated cross-browser testing across a wide range of real browsers and operating systems on its cloud-based Selenium Grid.

    Happy testing!

    Keep Reading

    How to Record Zoom Meetings with iTop Screen Recorder

    Here are 5 tips for getting sublimation right the first time

    3 Reasons to set Your Budget Higher for Your Next PC

    Top 3 Streaming Microphones from Razer

    Few Different Types of Resistors Used in Aviation

    Overview of the Best Software for Gaming

    Top Posts

    how to make money online & ways to earn money from online

    17th July 2020

    6 Best Gambling Movies Of All Times, You Need To Watch Right Now.

    15th September 2021

    Why Big Translation Is The Future of Self-Publishing

    24th October 2021

    What is the color of my fetus’ eyes

    5th November 2021
    Don't Miss

    Unblocked Games WTF : Your Easy Solution To Play Games At School

    Game 21st June 2022

    Playing games at school can be problematic when you consider that Internet connections in schools…

    CONTENT CREATION STRATEGY

    27th August 2021

    Industrial Machinery That Keeps People Safe

    4th December 2021

    How to Fix Outlook Crashes on iPhone?

    23rd November 2021
    Stay In Touch
    • Facebook
    • Twitter
    • LinkedIn

    Subscribe to Updates

    Get the latest creative news from SmartMag about art & design.

    Editors Picks

    The Ultimate Couch Cleaning Guide

    29th October 2021

    Google Pixel 6 Pro Review: A Dazzling New Start For Pixel

    26th October 2021

    Exotic Window Covering Styles Sure to Grab Attention

    24th November 2021

    3 Ways to Get Affordable Orthodontic Treatment

    10th January 2022
    Latest Posts

    Are There Long-Term Effects of Electric Shock?

    1st December 2021

    Top 5 UTV Must Have Trail and Off-Road Accessories

    14th February 2022

    What You Should Do If You Need Emergency Plumbing

    27th February 2022
    Advertisement
    © 2022
    • About us
    • Privacy Policy
    • Terms and Conditions

    Type above and press Enter to search. Press Esc to cancel.