一、现有eclipse配置TestNG
安装TestNG插件有两种方式,一种是离线一种是在线。
1、离线
(1)下载testng安装包,进入http://beust.com/eclipse下载。

(2)下载zipped文件后,在eclipse菜单栏中点击“help”,选择下拉菜单的“Install New Software”。出现如下界面
(3)点击Add按钮

(4)在项目上右键可以看见如下图,说明安装成功

2、在线安装
(1)直接上图片,进入Marktplace后搜索TestNG,直接安装即可

3、安装会出现问
不管是离线还是在线都会出现安装过程卡住的现象
注意:安装卡住解决办法https://blog.csdn.net/qq_27009225/article/details/103743824
二、配置Selenium
1、下载地址
https://selenium.dev/downloads/
下载对应的java版本

2、将下载的文件解压
出现如下文件

注意:必须把三个文件都导入项目,只导入外面两个jar包会出现问题报错信息:java.lang.NoClassDefFoundError: com/google/common/collect/ImmutableMap
3、导入文件

三、下载对应浏览器驱动
安装三大浏览器驱动driver
- Chrome驱动chromedriver 下载地址:chromedriver
- Firefox驱动geckodriver 下载地址:geckodriver
- IE驱动IEdriver 下载地址:IEdriver
- Edge驱动edgedriver下载地址:edgedriver
- IEDriverServer的版本号和Selenium的版本号一定要一致
Python查看selenium版本
1、Chrome驱动
-
Chrome驱动每个版本都有各自对应的浏览器版本,下面网页中信息可供参考。
http://chromedriver.storage.googleapis.com/2.43/notes.txt -
下载驱动网址https://chromedriver.chromium.org/downloads
注意:驱动和浏览器版本不对应会报错: -
如果找不到浏览器对应的驱动,可以下载旧版本Chrome:Chrome历史版本
Caused by: org.openqa.selenium.net.UrlChecker$TimeoutException: Timed out waiting for [http://localhost:25606/status] to be available after 20012 ms
at org.openqa.selenium.net.UrlChecker.waitUntilAvailable(UrlChecker.java:107)
at org.openqa.selenium.remote.service.DriverService.waitUntilAvailable(DriverService.java:190)
... 10 more
Caused by: com.google.common.util.concurrent.UncheckedTimeoutException: java.util.concurrent.TimeoutException
at com.google.common.util.concurrent.SimpleTimeLimiter.callWithTimeout(SimpleTimeLimiter.java:140)
at org.openqa.selenium.net.UrlChecker.waitUntilAvailable(UrlChecker.java:80)
... 11 mor
2、配置ChromeDriver环境变量
- 将webdriver复制到Chrome浏览器安装目录的Application文件下
当然,配置环境变量不是必选项,但是会省一点事情吧!要是配置环境变量了driver放在那里就无所谓了,如果配置环境变量不生效可以试着注销或者重启

四、调用实例
- 如果你配置了webdriver的环境变量,就不用下面这行代码
System.setProperty("webdriver.chrome.driver","C:\\Program Files (x86)\\Google\\Chrome Beta\\Application\\chromedriver.exe");
System.setProperty("webdriver.chrome.driver",
// "C:\\Program Files (x86)\\Google\\Chrome Beta\\Application\\chromedriver.exe");
WebDriver wd = new ChromeDriver();
wd.get("https://www.baidu.com");
Thread.sleep(1000);
wd.findElement(By.id("kw")).sendKeys("I Love You!");
Thread.sleep(1000);
wd.findElement(By.id("su")).click();
Thread.sleep(1000);
wd.quit();
四、IE启动报错
1、Unexpected error launching Internet Explorer
selenium.common.exceptions.SessionNotCreatedException: Message: Unexpected error launching Internet Explorer. Browser zoom level was set to 250%. It should be set to 100%
2、解决

3、第二种方法
五、启动Edge报错
报错信息:urllib3.exceptions.ProtocolError
urllib3.exceptions.ProtocolError: ('Connection aborted.', ConnectionResetError(10054, '远程主机强迫关闭了一个现有的连接。', None, 10054, None))
1、查看edge版本
在最下面


方式一:Edge18之前的版本
下载对应版本的MicrosoftWebDriver

方式二:Edge18之后的版本
在命令行中输入
DISM.exe /Online /Add-Capability /CapabilityName:Microsoft.WebDriver~~~~0.0.1.0
切记:此时确保Python的安装目录没有之前版本的MicrosoftWebDriver,否则Python会默认先找到Python安装目录下的MicrosoftWebDriver,一直报错

六、启动Firefox报错
1、Service geckodriver unexpectedly exited
Message: Service geckodriver unexpectedly exited. Status code was: 2
2、下载对应的driver




被折叠的 条评论
为什么被折叠?



