获取错误“;java.lang.reflect.InvocationTargetException“;在selenium java中
在SeleniumJava中获取错误“java.lang.reflect.InvocationTargetException”。我已经阅读了这个错误出现的原因,但不知道是在代码的哪一行导致了这些错误。我是自动化新手,所以不知道哪一行需要修改。这是我的密码:获取错误“;java.lang.reflect.InvocationTargetException“;在selenium java中,java,selenium,automation,Java,Selenium,Automation,在SeleniumJava中获取错误“java.lang.reflect.InvocationTargetException”。我已经阅读了这个错误出现的原因,但不知道是在代码的哪一行导致了这些错误。我是自动化新手,所以不知道哪一行需要修改。这是我的密码: ///////This is the class where my test case is being executed. public class LoginTestCase extends ExtentReportBaseClass
///////This is the class where my test case is being executed.
public class LoginTestCase extends ExtentReportBaseClass {
static WebDriver driver;
//Homepage login = new Homepage();
UtilityMethods util = new UtilityMethods();
configFileReader configReaderObj=new configFileReader();
String locUsernameElem;
String locPasswordelem;
String Sign_in;
String insertEmail;
String insertFirstName;
String createAccountButton;
// @Parameters("browser")
@BeforeClass
public void launchBrowser() {
driver= UtilityMethods.openBrowser(ConstantsValues.BROWSER_NAME);
UtilityMethods.launchWebsite(Utility.ConstantsValues.URL);
driver.manage().window().maximize();
//report = ExtentReportBaseClass.setUp();
}
@Test
public void registration() throws InterruptedException, IOException {
test = report.createTest("registration", "This will check status for registration of the user.");
Sign_in = Utility.UtilityLocatorz.SignUp.SIGN_IN;
reportLog("User will create a new account");
createAccountButton = Utility.UtilityLocatorz.SignUp.CREATE_ACOUNT;
util.clickElement(Sign_in);
Thread.sleep(2000);
reportLog("User will put his personal details");
driver.findElement(By.name("email_create")).sendKeys("vivek443333111@gmail.com");
//util.sendData(insertEmail);
util.clickElement(UtilityLocatorz.SignUp.CREATE_ACCOUNT);
util.clickElement(UtilityLocatorz.SignUp.USER_TITLE);
reportLog("User will add personal details for his new account");
util.sendDataById("customer_firstname", UtilityLocatorz.SignUp.FIRST_NAME);
util.sendDataById("customer_lastname", UtilityLocatorz.SignUp.LAST_NAME);
util.sendData(UtilityLocatorz.SignUp.USER_PASSWORD);
util.clickElement(UtilityLocatorz.SignUp.USER_NEWSLETTER);
Select day = new Select(driver.findElement(By.id("days")));
day.selectByValue("1");
Select month = new Select(driver.findElement(By.id("months")));
month.selectByValue("2");
Select year = new Select(driver.findElement(By.id("years")));
year.selectByValue("2014");
util.sendData(SignUp.USER_COMPANY);
util.sendData(SignUp.USER_STATE);
util.sendData(SignUp.USER_ADDRESS1);
util.sendData(SignUp.USER_MOBILENUMBER);
util.sendData(SignUp.USER_ZIPCODE);
util.sendData(SignUp.USER_ALIAS);
util.sendData(SignUp.USER_CITY);
util.clickElement(SignUp.SUBMITACCOUNT);
reportLog("After creating a new account, User will login to his new account");
boolean chkElement=driver.findElement(By.className("View my customer account")).isDisplayed();
Assert.assertTrue(chkElement);
util.clickElement(SignUp.USER_SIGN_OUT);
//test.log(Status.PASS, MarkupHelper.createLabel("PASS", ExtentColor.GREEN));
}
This is the class where my utility methods are being called.
public class UtilityMethods extends ExtentReportBaseClass{
static WebDriver driver;
public static WebDriver openBrowser(String browsers) {
System.out.println("initiated browser is " + browsers);
if (browsers.equalsIgnoreCase("firefox")) {
System.setProperty("webdriver.firefox.marionette", "");
DesiredCapabilities dc = new DesiredCapabilities();
dc.setCapability("marionatte", false);
FirefoxOptions opt = new FirefoxOptions();
opt.merge(dc);
driver = new FirefoxDriver(opt);
}
else if (browsers.equalsIgnoreCase("Chrome")) {
// String driverPath = System.getProperty("user.dir") +
// "\\src\\Drivers\\chromedriver";
// System.setProperty("webdriver.chrome.driver", driverPath);
System.setProperty("webdriver.chrome.driver", "D:\\chromedriver.exe");
driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
return driver;
}
public static void launchWebsite(String URL) {
driver.get(URL);
}
public static By locateByElement(String locator, String locatorValue) {
By by = null;
switch (locator) {
case "id":
by = By.id(locatorValue);
break;
case "name":
by = By.name(locatorValue);
break;
case "linktext":
by = By.linkText(locatorValue);
break;
case "partialLinkText":
by = By.partialLinkText(locatorValue);
break;
case "className":
by = By.className(locatorValue);
break;
case "tagName":
by = By.tagName(locatorValue);
break;
case "cssSelector":
by = By.cssSelector(locatorValue);
break;
case "xpath":
by = By.xpath(locatorValue);
break;
}
System.out.println("value of by is" + by);
return by;
}
public void sendDataById(String locatorValue, String userData) {
driver.findElement(By.id(locatorValue)).sendKeys(userData);
}
public void sendData(String element) {
String[] var = element.split("###");
String loctype = var[0];
String locval = var[1];
// System.out.println(locval);
String uservalue = var[2];
// System.out.println(locval);
// System.out.println(uservalue);
By locator = locateByElement(loctype, locval);
System.out.println(loctype);
System.out.println(locval);
driver.findElement(locator).sendKeys(uservalue);
}
public WebDriver getdriver() {
if (driver == null) {
driver = new FirefoxDriver();
return driver;
} else {
return driver;
}
}
public void clickElement(String locElem) throws IOException {
try {
System.out.println(locElem);
String[] var = locElem.split("###");
String loctype = var[0];
String locval = var[1];
System.out.println(loctype);
System.out.println(locval);
By locator = locateByElement(loctype, locval);
driver.findElement(locator).click();
}
catch (Exception e) {
System.out.println("Catched Exception, Element not clicked is" + locElem);
}
}
////////堆栈跟踪
Cannot instantiate class TestCases.LoginTestCase
at org.testng.internal.ObjectFactoryImpl.newInstance(ObjectFactoryImpl.java:30)
at org.testng.internal.ClassHelper.createInstance1(ClassHelper.java:423)
at org.testng.internal.ClassHelper.createInstance(ClassHelper.java:336)
at org.testng.internal.ClassImpl.getDefaultInstance(ClassImpl.java:125)
at org.testng.internal.ClassImpl.getInstances(ClassImpl.java:190)
at org.testng.TestClass.getInstances(TestClass.java:95)
at org.testng.TestClass.initTestClassesAndInstances(TestClass.java:81)
at org.testng.TestClass.init(TestClass.java:73)
at org.testng.TestClass.<init>(TestClass.java:38)
at org.testng.TestRunner.initMethods(TestRunner.java:389)
at org.testng.TestRunner.init(TestRunner.java:271)
at org.testng.TestRunner.init(TestRunner.java:241)
at org.testng.TestRunner.<init>(TestRunner.java:192)
at org.testng.remote.support.RemoteTestNG6_12$1.newTestRunner(RemoteTestNG6_12.java:33)
at org.testng.remote.support.RemoteTestNG6_12$DelegatingTestRunnerFactory.newTestRunner(RemoteTestNG6_12.java:66)
at org.testng.SuiteRunner$ProxyTestRunnerFactory.newTestRunner(SuiteRunner.java:713)
at org.testng.SuiteRunner.init(SuiteRunner.java:260)
at org.testng.SuiteRunner.<init>(SuiteRunner.java:198)
at org.testng.TestNG.createSuiteRunner(TestNG.java:1295)
at org.testng.TestNG.createSuiteRunners(TestNG.java:1273)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1128)
at org.testng.TestNG.runSuites(TestNG.java:1049)
at org.testng.TestNG.run(TestNG.java:1017)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
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:24)
... 25 more
Caused by: java.lang.StackOverflowError
at Utility.UtilityMethods.<init>(UtilityMethods.java:19)
at Utility.ExtentReportBaseClass.<init>(ExtentReportBaseClass.java:25)
at Utility.UtilityMethods.<init>(UtilityMethods.java:19)
at Utility.ExtentReportBaseClass.<init>(ExtentReportBaseClass.java:25)
at Utility.UtilityMethods.<init>(UtilityMethods.java:19)
at Utility.ExtentReportBaseClass.<init>(ExtentReportBaseClass.java:25)
at Utility.UtilityMethods.<init>(UtilityMethods.java:19)
at Utility.ExtentReportBaseClass.<init>(ExtentReportBaseClass.java:25)
at Utility.UtilityMethods.<init>(UtilityMethods.java:19)
at Utility.ExtentReportBaseClass.<init>(ExtentReportBaseClass.java:25)
无法实例化类TestCases.LoginTestCase
位于org.testng.internal.ObjectFactoryImpl.newInstance(ObjectFactoryImpl.java:30)
位于org.testng.internal.ClassHelper.createInstance1(ClassHelper.java:423)
位于org.testng.internal.ClassHelper.createInstance(ClassHelper.java:336)
位于org.testng.internal.ClassImpl.getDefaultInstance(ClassImpl.java:125)
位于org.testng.internal.ClassImpl.getInstances(ClassImpl.java:190)
位于org.testng.TestClass.getInstances(TestClass.java:95)
位于org.testng.TestClass.initTestClassesAndInstances(TestClass.java:81)
位于org.testng.TestClass.init(TestClass.java:73)
位于org.testng.TestClass.(TestClass.java:38)
位于org.testng.TestRunner.initMethods(TestRunner.java:389)
位于org.testng.TestRunner.init(TestRunner.java:271)
位于org.testng.TestRunner.init(TestRunner.java:241)
位于org.testng.TestRunner.(TestRunner.java:192)
位于org.testng.remote.support.RemoteTestNG6_12$1.newTestRunner(RemoteTestNG6_12.java:33)
位于org.testng.remote.support.RemoteTestNG6_12$delegatingestrunnerfactory.newestrunner(RemoteTestNG6_12.java:66)
位于org.testng.SuiteRunner$ProxyTestRunnerFactory.newTestRunner(SuiteRunner.java:713)
位于org.testng.SuiteRunner.init(SuiteRunner.java:260)
位于org.testng.SuiteRunner(SuiteRunner.java:198)
位于org.testng.testng.createSuiteRunner(testng.java:1295)
位于org.testng.testng.createSuiteRunners(testng.java:1273)
位于org.testng.testng.runSuitesLocally(testng.java:1128)
位于org.testng.testng.runSuites(testng.java:1049)
位于org.testng.testng.run(testng.java:1017)
位于org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114)
位于org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
位于org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
原因:java.lang.reflect.InvocationTargetException
位于sun.reflect.NativeConstructorAccessorImpl.newInstance0(本机方法)
位于sun.reflect.NativeConstructorAccessorImpl.newInstance(未知源)
位于sun.reflect.delegatingConstructor或AccessorImpl.newInstance(未知源)
位于java.lang.reflect.Constructor.newInstance(未知源)
位于org.testng.internal.ObjectFactoryImpl.newInstance(ObjectFactoryImpl.java:24)
... 25多
原因:java.lang.StackOverflower错误
在Utility.UtilityMethods.(UtilityMethods.java:19)
位于Utility.ExtentReportBaseClass。(ExtentReportBaseClass.java:25)
在Utility.UtilityMethods.(UtilityMethods.java:19)
位于Utility.ExtentReportBaseClass。(ExtentReportBaseClass.java:25)
在Utility.UtilityMethods.(UtilityMethods.java:19)
位于Utility.ExtentReportBaseClass。(ExtentReportBaseClass.java:25)
在Utility.UtilityMethods.(UtilityMethods.java:19)
位于Utility.ExtentReportBaseClass。(ExtentReportBaseClass.java:25)
在Utility.UtilityMethods.(UtilityMethods.java:19)
位于Utility.ExtentReportBaseClass。(ExtentReportBaseClass.java:25)
这是一个输入错误:“marionatte”
?不,它是geckodriver附带的一个单独的Web驱动程序,用于解决兼容性问题。不知道代码中的哪一行导致了这些错误:很简单,只需查看stacktrace即可。在那里,您将看到相关的类名和行号。我已经看到,但没有在这些行中找到错误发生的原因。两个方法相互调用会导致堆栈溢出。(实用方法:19
和扩展报告基类:25
)。只要在任意一个地方设置断点,看看他们为什么这样做。