![](/img/trans.png)
[英]Should we write the testng selenium code in java test folder or main folder?
[英]How to write Selenium Java Application code in IDE through main() and TestNG
我面临以下在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/");
}
}
System.setProperty("webdriver.chrome.driver", "chromedriver");
driver = new ChromeDriver();
driver.get("http://newtours.demoaut.com/");
试试这个代码,它工作正常。 我检查了一下,它运行正常。 您需要提供http或https作为您的网址。
错误源于org.apache.bcel.verifier
您必须注意以下事项:
使用WebDriver
界面代替使用ChromeDriver
实施。 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/"); } }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.