我得到「顯示java.lang.NullPointerException」當我試圖執行基於POM我的測試用例。 類BrowserFactory讓我選擇瀏覽器,類Flipkart_Login基於POM商店特定頁面的所有元素,並具有Valid_Login() 最後Test_Flipkart_Login類的方法 - 要求executon的Valid_Login()方法,但是當我嘗試要執行這個類,我得到java.lang.NullPointerException。硒POM顯示java.lang.NullPointerException
請指教!
FAILED:Flipkart_Login_Test 顯示java.lang.NullPointerException 在DataProviders.ConfigDataProvider.getURL(ConfigDataProvider.java:31) 在TestCases.Test_Flipkart_Login.Flipkart_Login_Test(Test_Flipkart_Login.java:19)
公共類ConfigDataProvider { 靜態屬性pro;
public ConfigDataProvider()
{
File src = new File("C:\\Data\\Bimlesh\\Flipkart_HybridFramework\\Flipkart.Hybrid.FrameworkComplete\\Configuration\\Config.Properties");
try
{
FileInputStream fis = new FileInputStream(src);
pro = new Properties();
pro.load(fis);
} catch (Exception e)
{
System.out.println("The Config exception is :"+e.getMessage());
}
}
public static String getURL()
{
String URL = pro.getProperty("URL");
return URL;
}
public static String ChromePath()
{
String Chrome = pro.getProperty("Chromepath");
return Chrome;
}
public static String IEPath()
{
String IE = pro.getProperty("IEpath");
return IE;
}
}
公共類BrowserFactory { 靜態webdriver的驅動程序;
public static WebDriver getBrowser(String BrowserName)
{
if(BrowserName.equalsIgnoreCase("Firefox"))
{
driver = new FirefoxDriver();
}
else if(BrowserName.equalsIgnoreCase("Chrome"))
{
System.setProperty("webdriver.chrome.driver", ConfigDataProvider.ChromePath());
driver = new ChromeDriver();
}
else if(BrowserName.equalsIgnoreCase("IE"))
{
System.setProperty("webdriver.ie.driver", ConfigDataProvider.IEPath());
driver = new InternetExplorerDriver();
}
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
return driver;
}
public void ShutDown(WebDriver driver)
{
driver.quit();
}
}
公共類Flipkart_Login { 的webdriver驅動器;
public Flipkart_Login(WebDriver driver)
{
this.driver=driver;
}
@FindBy(xpath="//a[text()='Log In']") WebElement Login_Click;
@FindBy(xpath="//input[@class='_2zrpKA' and @type='text']") WebElement Enter_Email;
@FindBy(xpath="//input[@class='_2zrpKA _3v41xv' and @type='password']") WebElement Enter_Pass;
@FindBy(xpath="//button[@type='submit' and @class='_3zLR9i _1LctnI _36SmAs']") WebElement Login_Button;
public void Valid_Login()
{
Login_Click.click();
Enter_Email.sendKeys("[email protected]");
Enter_Pass.sendKeys("xxx");
Login_Button.click();
}
}
公共類Test_Flipkart_Login { 的webdriver驅動器;
@Test
public void Flipkart_Login_Test()
{
driver = BrowserFactory.getBrowser("Firefox");
driver.get(ConfigDataProvider.getURL());
Flipkart_Login page1 = PageFactory.initElements(driver, Flipkart_Login.class);
page1.Valid_Login();
}
}