org.testng.TestNGException:无法实例化类 [英] org.testng.TestNGException: Cannot instantiate class

查看:78
本文介绍了org.testng.TestNGException:无法实例化类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在尝试运行脚本时收到以下错误

I am receiving the following errors when I am trying to run my script

org.testng.TestNGException: 无法实例化类导致:java.lang.reflect.InvocationTargetException 引起的:java.lang.IllegalStateException:驱动程序可执行文件的路径必须由 webdriver.ie.driver 系统属性设置;

org.testng.TestNGException: Cannot instantiate class Caused by: java.lang.reflect.InvocationTargetException Caused by: java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.ie.driver system property;

package EDRTermsPackge;

import org.testng.annotations.Test;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;

public class ContactInformationTesting {

 //For use of IE only; Please enable for IE Browser
 WebDriver driver = new InternetExplorerDriver();

 @BeforeMethod
 public void beforeMethod() {
  //Using or Launching Internet Explorer
  String exePath = "\\Users\\jj85274\\Desktop\\IEDriverServer.exe";

  //For use of IE only; Please enable for IE Browser
  System.setProperty("webdriver.ie.driver", exePath);
 }

 @Test
 public void OpenPage_Login() {
  driver.get("http://cp-qa.harriscomputer.com/");
 }
}

推荐答案

你应该先设置你的路径到driver然后实例化IEDriver,你不能在new InternetExplorerDriver();>System.setProperty("webdriver.ie.driver", exePath);

You should set your path to driver first and then instantiate IEDriver, you can't use new InternetExplorerDriver(); before System.setProperty("webdriver.ie.driver", exePath);

在你的情况下,你可以做这样的事情(不需要@BeforeMethod 来做这个简单的属性设置):

In your case you could do something like this (No need for @BeforeMethod to do just this simple property setup):

public class ContactInformationTesting {

  //Using or Launching Internet Explorer
  String exePath = "\\Users\\jj85274\\Desktop\\IEDriverServer.exe";

  //For use of IE only; Please enable for IE Browser
  System.setProperty("webdriver.ie.driver", exePath);

  //For use of IE only; Please enable for IE Browser
  WebDriver driver = new InternetExplorerDriver();

 @Test
 public void OpenPage_Login() {
  driver.get("http://cp-qa.harriscomputer.com/");
 }

这篇关于org.testng.TestNGException:无法实例化类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆