我面临以下问题 在Google中搜索无法找到明确答案如何解决此问题。
错误:
org.apache.bcel.verifier.exc.AssertionViolatedException.main(AssertionViolatedException.java:102)
代码
import org.openqa.selenium.chrome.ChromeDriver;
public class Newtours
{
public static ChromeDriver driver;
public void chrome()
{
System.setProperty("webdriver.chrome.driver","C:\\Users\\imper\\Downloads\\chromedriver_win32\\chromedriver.exe"); // objects and variables instantiation
driver = new ChromeDriver();
driver.get("newtours.demoaut.com/");
}
}
答案 0 :(得分:0)
group by
试试这段代码,它运作正常。 我查了一遍,它运行正常。 您需要为您的网址提供 http 或 https 。
答案 1 :(得分:0)
错误源自 org.apache.bcel.verifier
你必须按照以下方式处理某些事情:
不使用 ChromeDriver
实施,而是使用 WebDriver
界面。
chrome
是保留关键字。为方法使用其他一些用户定义的名称,例如my_function() {}
只需定义 public void chrome(),就无法执行Test
。您必须将 public void chrome()转换为以下任一项:
转换为main()
函数,如下所示:
public class Newtours
{
public static void main(String[] args)
{
System.setProperty("webdriver.chrome.driver", "C:\\path\\to\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("http://newtours.demoaut.com/");
}
}
整合TestNG
并添加 @Test
注释,如下所示:
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.Test;
public class Newtours
{
@Test
public void my_function()
{
System.setProperty("webdriver.chrome.driver", "C:\\path\\to\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("http://newtours.demoaut.com/");
}
}