Hi,
I am new to selenium webdriver and written the script on search functionality for one of the website.
I have also included Extentreport code into it using some videos shared on google.
Query:
I am facing the issue: ExtentReports cannot be resolved to a type.
Below is code:
package com.learnTestNG;
import org.testng.annotations.Test;
import static org.testng.Assert.*;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.TimeUnit;
import
org.openqa.selenium.By;
import org.openqa.selenium.StaleElementReferenceException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
/*import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;*/
//import org.testng.annotations.Test;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.AfterTest;
//import org.testng.annotations.Optional;
//import com.beust.jcommander.Parameter;
import com.relevantcodes.extentreports.ExtentReports;
import com.relevantcodes.extentreports.ExtentTest;
import com.relevantcodes.extentreports.LogStatus;
public class TestRedBus
{
/*public static*/ static WebDriver driver;
private static String baseUrl;
ExtentReports report;
static ExtentTest logger;
@BeforeTest
public void beforeTest()
{
driver = new FirefoxDriver();
FirefoxProfile fxprofile=new FirefoxProfile();
fxprofile.setAssumeUntrustedCertificateIssuer(true);
fxprofile.setAcceptUntrustedCertificates(true);
baseUrl= "
https://www.redbus.in/";
driver.manage().window().maximize();
report=new ExtentReports("C:\\Program Files\\TestNG\\ExtentReports\\RedBusReport.html");
logger= report.startTest("Verify Home page for RedBus.in");
logger.log(LogStatus.INFO, "Browser is up and running");
driver.get(baseUrl);
logger.log(LogStatus.INFO, "Application is up and running");
System.out.println("Current URL is " +driver.getCurrentUrl()) ;
System.out.println(driver.getTitle());
logger.log(LogStatus.INFO, "Got the title of application home page");
driver.manage().timeouts().implicitlyWait(60,TimeUnit.SECONDS);
}
@Test
/*Enter source destination and
* click on datepicker icon and then click on next button from calendar*/
public void TestHomePage() throws InterruptedException
{
driver.findElement(By.id("txtSource")).sendKeys("Mumbai");
driver.findElement(By.id("txtDestination")).sendKeys("pune");
logger.log(LogStatus.INFO, "Entered Source and destination");
}
@Test
public static void testSelectOnwardDate() throws InterruptedException
{
System.out.println("------------------Staring with onward journey---------------");
driver.findElement(By.id("txtOnwardCalendar")).click();
driver.findElement(By.xpath(".//*[@id='rbcal_txtOnwardCalendar']/table[2]/tbody/tr[1]/td[3]/button")).click();
Thread.sleep(3000);
String date ="13-Jun 2016";
String splitter[]= date.split("-");
System.out.println(splitter);
String CheckInDay= splitter[0];
String CheckInMonth_Year= splitter[1];
System.out.println(CheckInDay);
System.out.println(CheckInMonth_Year);
//to get the month and year from Onward calendar
List<WebElement> elements = driver.findElements(By.xpath(".//div[@class='Calendar']/table/tbody/tr[@class='monthHeader']/td[@class='monthTitle']"));
for (int i=0; i<elements.size(); i++)
{
System.out.println(elements.get(i).getText());
if(elements.get(i).getText().equals(CheckInMonth_Year))
{
System.out.println("------------------------");
//selecting the date
List <WebElement> days = driver.findElements(By.xpath(".//*[@id='rbcal_txtOnwardCalendar']/table[contains(@class ,'month')][2]/tbody/tr/td[contains(@class, 'day')]"));
for(WebElement d : days)
{
System.out.println(d.getText());
if(d.getText().equals(CheckInDay))
{
d.click();
Thread.sleep(3000);
break;
}
}
logger.log(LogStatus.INFO, "Selected onward journey date");
}
}
}
@Test
public static void testSelectReturnDate() throws InterruptedException
{
//Exception e= new Exception();
System.out.println("----------Staring function for return journey--------------");
driver.findElement(By.id("txtReturnCalendar")).click();
//driver.findElement(By.xpath(".//*[@id='rbcal_txtReturnCalendar']/table[2]/tbody/tr[1]/td[3]/button")).click();
String Return_date ="14-Jun 2016";
String splitter_Date[]= Return_date.split("-");
System.out.println(splitter_Date);
String CheckOutDay= splitter_Date[0];
String CheckOutMonth_Year= splitter_Date[1];
System.out.println(CheckOutDay);
System.out.println(CheckOutMonth_Year);
try
{
//Selecting month and year from return calendar
List<WebElement> elements = driver.findElements(By.xpath(".//div[@id='rbcal_txtReturnCalendar']/table[contains(@class, 'monthTable')]/tbody/tr[@class='monthHeader']/td[@class='monthTitle']"));
System.out.println("---------------Starting calculation for date/moth/year selection from calendar-------------");
for(int j=0; j<elements.size(); j++)
{
System.out.println(elements.get(j).getText());
Thread.sleep(3000);
if(elements.get(j).getText().equals(CheckOutMonth_Year))
{
System.out.println("------------------------");
//selecting the dates from return calendar
List <WebElement> Returndays = driver.findElements(By.xpath(".//*[@id='rbcal_txtReturnCalendar']/table[contains(@class ,'month')][1]/tbody/tr/td[contains(@class, 'day')]"));
for(WebElement d : Returndays)
{
System.out.println(d.getText());
if(d.getText().equals(CheckOutDay))
{
d.click();
Thread.sleep(3000);
break;
}
}
}
}
}
catch(StaleElementReferenceException e)
{
e.printStackTrace();
e.toString();
System.out.println("Trying to recover from Stale element " +e.getMessage());
}
logger.log(LogStatus.INFO, "Selected return journey date");
driver.findElement(By.id("searchBtn")).click();
logger.log(LogStatus.INFO, "Clicked on search buses");
System.out.println(driver.getTitle());
logger.log(LogStatus.PASS, "Navigated to search buses page.");
}
@AfterTest
public void afterTest()
{
/*driver.get("C:\\Program Files\\TestNG\\Reports\\RedBusReport.html");
report.endTest(logger);
report.flush();*/
driver.close();
driver.quit();
}
}
Following error is displayed:org.testng.TestNGException:
Cannot instantiate class com.learnTestNG.TestRedBus
at org.testng.internal.ObjectFactoryImpl.newInstance(ObjectFactoryImpl.java:40)
at org.testng.internal.ClassHelper.createInstance1(ClassHelper.java:377)
at org.testng.internal.ClassHelper.createInstance(ClassHelper.java:290)
at org.testng.internal.ClassImpl.getDefaultInstance(ClassImpl.java:125)
at org.testng.internal.ClassImpl.getInstances(ClassImpl.java:190)
at org.testng.internal.TestNGClassFinder.<init>(TestNGClassFinder.java:130)
at org.testng.TestRunner.initMethods(TestRunner.java:424)
at org.testng.TestRunner.init(TestRunner.java:247)
at org.testng.TestRunner.init(TestRunner.java:217)
at org.testng.TestRunner.<init>(TestRunner.java:169)
at org.testng.remote.RemoteTestNG$1.newTestRunner(RemoteTestNG.java:144)
at org.testng.remote.RemoteTestNG$DelegatingTestRunnerFactory.newTestRunner(RemoteTestNG.java:273)
at org.testng.SuiteRunner$ProxyTestRunnerFactory.newTestRunner(SuiteRunner.java:594)
at org.testng.SuiteRunner.init(SuiteRunner.java:168)
at org.testng.SuiteRunner.<init>(SuiteRunner.java:117)
at org.testng.TestNG.createSuiteRunner(TestNG.java:1319)
at org.testng.TestNG.createSuiteRunners(TestNG.java:1306)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1160)
at org.testng.TestNG.run(TestNG.java:1064)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:113)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:206)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:177)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.testng.internal.ObjectFactoryImpl.newInstance(ObjectFactoryImpl.java:29)
... 21 more
Caused by: java.lang.Error: Unresolved compilation problems:
The import com.relevantcodes cannot be resolved
The import com.relevantcodes cannot be resolved
The import com.relevantcodes cannot be resolved
ExtentReports cannot be resolved to a type
ExtentTest cannot be resolved to a type
ExtentReports cannot be resolved to a type
ExtentReports cannot be resolved to a type
ExtentTest cannot be resolved to a type
ExtentReports cannot be resolved to a type
ExtentTest cannot be resolved to a type
LogStatus cannot be resolved to a variable
ExtentTest cannot be resolved to a type
LogStatus cannot be resolved to a variable
ExtentTest cannot be resolved to a type
LogStatus cannot be resolved to a variable
ExtentTest cannot be resolved to a type
LogStatus cannot be resolved to a variable
ExtentTest cannot be resolved to a type
LogStatus cannot be resolved to a variable
ExtentTest cannot be resolved to a type
LogStatus cannot be resolved to a variable
ExtentTest cannot be resolved to a type
LogStatus cannot be resolved to a variable
ExtentTest cannot be resolved to a type
LogStatus cannot be resolved to a variable
at com.learnTestNG.TestRedBus.<init>(TestRedBus.java:21)
... 26 more
Configuration:
System: 64 bit
OS: Windows 10
Selenium version: 2.53.0
FF version: 43.0.1
Selenium standalone server: 2.53.0
ExtentReport Jars: 2.40.0
Any help will be greatly appreciated
Thank you in advance...
Regards
Reema Shah