Reputation: 1
So I have written a script in selenium to launch a webpage and extract information like, title name, fitment, number of reviews, verify if some words are present in the page. For example I used this below code:
String text = driver.findElement(By.xpath("//a[@class='text-m']")).getText();
System.out.println(text);
To get number of reviews in the page.
So What I am trying to do here is, I can launch one page at a time and get information. But I want to launch multiple pages, I have used TestNG for parallel execution but I was wondering if there is any way I can use excel sheet with multiple URL's and test them out one by one. Is there a way i can do this in selenium.
Any help would be appreciated. Thank you.
Here is my Script to find the information on a page.
public void test1() throws InterruptedException {
System.out.println("Test1");
System.setProperty("webdriver.chrome.driver", "chromedriver");
driver = new ChromeDriver();
driver.get("https://www.vikingbags.com/victory-high-ball-lamellar-large-leather-covered-non-shock-cutout-hard-saddlebags");
if(driver.getPageSource().contains("Fit"))
{
System.out.println("Fitment Present");
}
else
{
System.out.println("Fitment not present");
}
if(driver.getPageSource().contains("Installation Instructions"))
{
System.out.println("Installation Instructions Present");
}
else
{
System.out.println("Installation Instructions Not Present");
}
if(driver.getPageSource().contains("Watch Installation Video"))
{
System.out.println("Watch Installation Video Present");
}
else
{
System.out.println("Watch Instaltion Video not present");
}
if(driver.getPageSource().contains("Mounting Hardware:"))
{
System.out.println("Mounting Hardware Present");
}
else
{
System.out.println("Mounting Hardware Not Present");
}
if(driver.getPageSource().contains("Patent Number:"))
{
System.out.println("Patent Number Present");
}
else
{
System.out.println("Patent Number Not Present");
}
if(driver.getPageSource().contains("Dimensions:"))
{
System.out.println("Dimensions Present");
}
else
{
System.out.println("Dimensions Not Present");
}
if(driver.getPageSource().contains("Storage Capacity:"))
{
System.out.println("Storage Capacity Present");
}
else
{
System.out.println("Storage Capacity Not Present");
}
if(driver.getPageSource().contains("Turn Signal Relocation Kit:"))
{
System.out.println("Turn Signal RK Present");
}
else
{
System.out.println("Turn Signal RK Not Present");
}
if(driver.getPageSource().contains("Weight:"))
{
System.out.println("Weight Present");
}
else
{
System.out.println("Weight Not Present");
}
if(driver.getPageSource().contains("Lid Opening:"))
{
System.out.println("Lid Opening Present");
}
else
{
System.out.println("Lid Opening Not Present");
}
String text = driver.findElement(By.xpath("//a[@class='text-m']")).getText();
System.out.println(text);
System.out.println(driver.getTitle());
driver.close();
}
In line number 4 driver.get("URL you want to test")
. How do i change this using excel and use different links?
Upvotes: 0
Views: 71
Reputation: 1166
Option 1- Use Testng Dataprovider to send URLs:
@DataProvider(name = "data-provider")
public Object[][] urldataProviderMethod() {
return new Object[][] { { "URL1" }, { "URL2" } };
}
@Test(dataProvider = "data-provider")
public void test1() throws InterruptedException {..
Option 2- By excel sheet: Refer https://www.seleniumeasy.com/testng-tutorials/import-data-from-excel-and-pass-to-data-provider. Hope this helps.
Upvotes: 1