How to run test case using TestNG

0 votes
I am beginner in testNG. Can someone tell me as how can I create test case to check wether my browser is working or not?

Thank you in advance.
Jan 8, 2019 in Selenium by Anjali
• 2,950 points
1,233 views

1 answer to this question.

0 votes

I am assuming that you want to create test case where you open the different webdriver related to different browser.

You need to start by creating a testNG class, here you will create test cases for different browsers. Then you will create a xml file where you will create the different class and test cases.

Here is a sample testNG class that I created that works for Chrome and Morzilla Firefox.

package testNG;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;

public class MultipleTest
{
    WebDriver driver;
    String url = "https://www.google.com";
    @Parameters("browserType")
    @Test
    public void invokebrowser(String browserType) throws InterruptedException
    {
        browserType = browserType.trim();
        if (browserType.equalsIgnoreCase("chrome"))
        {
            System.setProperty("webdriver.chrome.driver","C:\\Users\\Downloads\\chromedriver.exe");
            driver = new ChromeDriver();
        }
        else if(browserType.equalsIgnoreCase("firefox"))
        {
            System.setProperty("webdriver.gecko.driver", "C:\\Users\\Downloads\\geckodriver.exe");
            driver = new FirefoxDriver();
        }
        else
        {
            System.out.println("Invalid Browser");
        }
        driver.manage().window().maximize();
        driver.get(url);
        Thread.sleep(2000);
        driver.close();
        
    }
}

Here is the XML file for the testNG class 

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="ParellelTesting" parallel = 'tests'>

    <test name = "Chrome Testing">

        <parameter name = 'browserType' value = 'chrome'/>
        
            <classes>

                <class name = 'testNG.MultipleTest'/>

            </classes>

    </test>

    <test name = "Firefox Testing">
    
        <parameter name = 'browserType' value = 'firefox'/>
            
            <classes>
            
                <class name = 'testNG.MultipleTest'/>
                
            </classes>
    
    </test>

</suite>

Hope this will help.

answered Jan 8, 2019 by Nabarupa

Related Questions In Selenium

0 votes
1 answer
0 votes
1 answer

How to run a group of test cases using TestNG in Selenium Webdriver?

Hey Kajal, TestNG allows you to perform ordered ...READ MORE

answered Jun 12, 2019 in Selenium by Abha
• 28,140 points
2,695 views
0 votes
1 answer

How to run a test case on remote webdriver using ruby selenium?

Hey Dhanush, you can follow the below ...READ MORE

answered Aug 23, 2019 in Selenium by Abha
• 28,140 points
1,355 views
0 votes
1 answer

How to run Selenium test case file from command line?

You’ll need Selenium RC for this: http://seleniumhq.org/download/  And the ...READ MORE

answered Apr 23, 2018 in Selenium by Vardy
• 2,360 points
14,183 views
0 votes
1 answer

How to disable a test case in testNG?

You can use the enable method to ...READ MORE

answered Jan 3, 2019 in Selenium by Nabarupa
1,833 views
0 votes
1 answer

How to run test scripts in Selenium using PhantomJS?

Hey @Shushil, you can run your test ...READ MORE

answered May 17, 2019 in Selenium by Abha
• 28,140 points
1,521 views
0 votes
2 answers

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,500 points
12,615 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
8,571 views
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,910 points
6,629 views
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 3, 2020 in Selenium by Sri
• 3,190 points
7,517 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP