我想在我的学习项目中使用 TestNg。在使用 TestNg 框架时,我得到了 NullPointer Excetion。我认为问题出在 WebDriver 对象声明部分。但我不知道如何实现相同的。任何人都可以帮助我吗?
请在下面找到代码,
package in.prolearn.testcases;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebDriver;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import in.prolearn.pages.HomePage;
import in.prolearn.pages.SearchResultPage;
import in.prolearn.utility.BrowserSelection;
public class VerifySnapDealSelection {
WebDriver driver = null;
@BeforeTest
public void preCondition(){
driver = BrowserSelection.browserSelection("Chrome");
BrowserSelection.openBrowser("https://www.snapdeal.com/");
}
HomePage hp = new HomePage(driver);
SearchResultPage srp = new SearchResultPage(driver);
@Test
public void NavigateToSearchCategoryPage() throws InterruptedException{
hp.menuSelectionGeneric("Computers & Gaming");
Thread.sleep(5000);
hp.subMenuSelectionGeneric("External Hard Drives");
Thread.sleep(5000);
}
@Test
public void SearchResultPageValidation() throws InterruptedException{
srp.FirstcapacitySelection("1 TB");
Thread.sleep(5000);
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
srp.FirstcapacitySelection("2 TB");
Thread.sleep(5000);
srp.verifySelectedItem("1 TB");
srp.verifySelectedItem("2 TB");
Thread.sleep(5000);
srp.DeleteSelectedItem("2 TB");
Thread.sleep(5000);
srp.VerifycapacitySelection("2 TB", "false");
srp.VerifyItem("1 TB", "1TB");
srp.DeleteSelectedItem("1 TB");
Thread.sleep(5000);
srp.VerifycapacitySelection("1 TB", "false");
}
}