Исключение нулевого указателя при вызове класса действий объектной модели страницы
TestConfused.java: public class TestCase extends TestBase { homeDetails homePage; CarActions carsPage; Map<Object, Object> map= new HashMap<Object, Object>(); @BeforeMethod public void startdriver() { startapplication(); object= new ExcelReader(); driver.get(url); driver.manage().deleteAllCookies(); driver.manage().timeouts().implicitlyWait(50, TimeUnit.SECONDS); utility= new Utility(); } } @Test(dataProvider= "data") public void CarTest(Map<Object, Object> car ) throws IOException, Exception { carsPage= new CarActions(); System.out.println(car); carsPage.makeAndModel(car); } @DataProvider(name = "data") public static Object[][] CarTestData() throws IOException, Exception { object= new ExcelReader(); return object.getExcelData("Sheet1", fileDir); } } **CarAction.java:** public class CarActions extends TestBase { WebDriver driver; CarPage car_pg = PageFactory.initElements(driver, CarPage.class); public void makeAndModel(Map<Object, Object> map) throws IOException, Exception { String registerNumber= map.get("RegisterNo").toString(); utility.elementCheck(car_pg.registerNo); car_pg.registerNo.click(); car_pg.registerNo.sendKeys(registerNumber); car_pg.findVehicle.click(); } **carPage.java:** public class CarPage { @FindBy(how = How.XPATH, using = "//input[@id='RegistrationNumber']" ) public WebElement registerNo; ExcelReader.java: public class ExcelReader extends TestBase { <pre>public Object[][] getExcelData( String SheetName , String fileDir ) throws IOException { File srcFile = new File(fileDir); FileInputStream fis = new FileInputStream(srcFile); XSSFWorkbook wb = new XSSFWorkbook(fis); XSSFSheet sheet= wb.getSheet(SheetName); wb.close(); int lastRowNum = sheet.getLastRowNum() ; int lastCellNum = sheet.getRow(0).getLastCellNum(); Object[][] obj = new Object[lastRowNum][1]; for (int i = 0; i < lastRowNum; i++) { Map<Object, Object> datamap = new HashMap<Object, Object>(); for (int j = 0; j < lastCellNum; j++) { datamap.put(sheet.getRow(0).getCell(j).toString(), sheet.getRow(i+1).getCell(j).toString()); } obj[i][0] = datamap; } return obj; } } **TestBase.java** public class TestBase { public static WebDriver driver; public static Actions action; public static ExcelReader object; public static Utility utility; public String url= "https"; protected static String fileDir= "\\InputHMap.xlsx"; static String browserName; static String driverPath; public static Properties prop; public static WebDriverWait wait; public static void startapplication(){ String browser="CHROME"; if(browser.equals("CHROME")) { System.setProperty("Webdriver.chrome.driver","./chromedriver.exe"); driver = new ChromeDriver(); } else if(browser.equals("IE")) { System.setProperty("Webdriver.ie.driver","./geckodriver.exe"); driver = new InternetExplorerDriver(); } else { System.out.println("we do not support this browser"); } driver.manage().window().maximize(); } } **utility.java** public class Utility { protected WebDriver driver = null; public void enterText(WebElement element, String value) { if(null != value) { //element.clear(); element.sendKeys(value); } } public void elementCheck(WebElement element) throws IOException { WebDriverWait wait=new WebDriverWait(driver,20); wait.until(ExpectedConditions.visibilityOf(element)); } } My problem is whenever the carpage.makeandmodel() is invoked in the @Test of TestConfused.java, a null pointer exception is encountered.
Что я уже пробовал:
I am trying my hands on Selenium test automation using TestNG as the test framework. For this, I have used a Page Object pattern to model each of the pages of the website that I am writing the test for.