java 测试selenium脚本报ClassnotFound:org.openqa.selenium.remote.ProtocolHandshake

weixin_40226368 2018-12-14 03:08:28

在测试selenium的脚本时,eclipse中总是报这个错误,一天了,在网上查的也没有原因.
...全文
1586 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
知识的行走者 2021-02-22
  • 打赏
  • 举报
回复
我也出现了同样的问题 java.lang.NoClassDefFoundError: org/openqa/selenium/remote/ProtocolHandshake at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:98) at io.appium.java_client.android.AndroidDriver.<init>(AndroidDriver.java:96) at com.testing.appui.AppiumDemo.test(AppiumDemo.java:39) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124) at org.testng.internal.Invoker.invokeMethod(Invoker.java:583) at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:719) at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:989) at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125) at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109) at org.testng.TestRunner.privateRun(TestRunner.java:648) at org.testng.TestRunner.run(TestRunner.java:505) at org.testng.SuiteRunner.runTest(SuiteRunner.java:455) at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:450) at org.testng.SuiteRunner.privateRun(SuiteRunner.java:415) at org.testng.SuiteRunner.run(SuiteRunner.java:364) at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52) at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84) at org.testng.TestNG.runSuitesSequentially(TestNG.java:1208) at org.testng.TestNG.runSuitesLocally(TestNG.java:1137) at org.testng.TestNG.runSuites(TestNG.java:1049) at org.testng.TestNG.run(TestNG.java:1017) at org.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:73) at org.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:123) Caused by: java.lang.ClassNotFoundException: org.openqa.selenium.remote.ProtocolHandshake at java.net.URLClassLoader.findClass(URLClassLoader.java:381) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ... 27 more <dependency> <groupId>io.appium</groupId> <artifactId>java-client</artifactId> <version>6.0.0-BETA3</version> <scope>test</scope> </dependency> <dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-java</artifactId> <version>3.3.1</version> </dependency>
¥ⁿ 2020-03-17
  • 打赏
  • 举报
回复
Starting ChromeDriver 79.0.3945.36 (3582db32b33893869b8c1339e8f4d9ed1816f143-refs/branch-heads/3945@{#614}) on port 4558 Only local connections are allowed. Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code. [1584413617.489][WARNING]: Timed out connecting to Chrome, retrying... 三月 17, 2020 10:53:38 上午 org.openqa.selenium.remote.ProtocolHandshake createSession 信息: Detected dialect: W3C 跑selenium 这报错是什么意思
¥ⁿ 2020-03-17
  • 打赏
  • 举报
回复
Starting ChromeDriver 79.0.3945.36 (3582db32b33893869b8c1339e8f4d9ed1816f143-refs/branch-heads/3945@{#614}) on port 4558 Only local connections are allowed. Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code. [1584413617.489][WARNING]: Timed out connecting to Chrome, retrying... 三月 17, 2020 10:53:38 上午 org.openqa.selenium.remote.ProtocolHandshake createSession 信息: Detected dialect: W3C
weixin_40226368 2018-12-24
  • 打赏
  • 举报
回复
原因是,当时创建的maven 项目,但是是添加下载下来的jar包,文件,而不是直接放在pom.xml文件中的,所以导致一直找不到这个依赖中的ProtocolHandshake.
现在这个问题已解决,另外就是NoSuchElement,可能是因为在测试前端页面的时候,默认的入口不是首页,而是从其他页面跳转过去的,就会导致这样的问题.
还有can not create a new session ,需要添加 appWaitActivity,但是添加之后又报版本的问题,这个时候看了下pom文件中java-client是5.4的版本,所以将版本改为最新的6.1.
总之这个弄得好坎坷,而最坎坷的不是代码,而是因为环境没弄好,懊悔,下次把问题想的简单点,把细节做的仔细点,
Estrally 2021-11-19
  • 举报
回复
@weixin_40226368 能讲讲怎么解决的吗
本文将step by step的讲述第一个selenium实例: step1:下载selenium-remote-control.下载地址:http://www.openqa.org/selenium-rc/download.action step2:打开eclipse 新建java project. step3:将junit.jar,selenium-remote-control-0.9.0/selenium-java-client-driver 以及selenium-remote-control-0.9.0/server/selenium-server添加至新建项目的编译路径下. step4:新建Testgoogle.java,代码如下. package test; import junit.framework.TestCase; import com.thoughtworks.selenium.DefaultSelenium; import com.thoughtworks.selenium.Selenium; public class TestGoogle extends TestCase { private Selenium selenium; public void setUp() throws Exception{ String url="http://www.google.cn"; selenium=new DefaultSelenium("localhost",4444, "*firefox", url); System.out.println("init selenium"); selenium.start(); System.out.println("start successfully"); } public void tearDown() throws Exception{ selenium.stop(); } public void testGoogleTestSearch() throws Throwable { System.out.println("enter testGoogleTestSearch"); selenium.open("/"); System.out.println("open the google.com"); selenium.type("q", "selenium"); System.out.println("input type condition"); selenium.click("btnG"); System.out.println("begin search"); selenium.waitForPageToLoad("30000"); assertTrue(selenium.isTextPresent("s")); System.out.println("finsh assert"); } } step5:右键选择testGoogle.java,选择run as junit. 看到junit的绿色通过提示条. remark:1.firefox的安装路径为默认路径,如果为非默认路径安装,需要把firefox.exe的路径写入环境变量path中. 2 出现location.href权限不足错误,在url路径后加"/",另外要确保你的浏览器能够打开www.google.com. 本文代码中用了www.google.cn,因为本人浏览器中会自动跳转到cn,而不是com.selenium在录制时候, 这种跳转对应关系录制不到.
.确认(verifation)和断言(assert)有什么区别? 确认:当测试中的一个用例存在错误时,系统将会继续运行这些测试 断言:当测试中的一个用例存在错误时,系统将会退出当前用例 总而言之,确认和断言的不同在于,当出现错误情况之后,系统将会如何处理。 .test case 和testsuite的区别? test case是一个用例 test suite是一组用例 7.selenium IDE, selenium core, selenium core hta, selenium rc四者的概念以及它们之间的区别? selenium IDE(集成开发环境)。它是一个firefox的插件,可以录制、回放并编辑测试selenium Core(核心)。这是符合断言机制,由测试套件执行的平台。它是整个测试机制的核心部分,由纯javaScript代码组成 selenium Core Hta.这是针对IE设计的执行平台,运行于IE的最高字全级别之上。 selenium Remote Control(远程控制):它是一个代理与控制端,可代替selenium core/selenium DIE的客户端,并支持多语言 8.能不能在IE中录制本吗? 不能,只能在firefox中安装selenium IDE,而只有selenium IDE才存在录制的功能。 如果想测试一些,不能在firefox中正常显示的程序,则只有安装selenium RC,然后自己编写测试本,只有这样,本才能在ie中运行。 12.怎样安装多窗口模型? (1)启动selenium-server时,输入以下的命令:java-jar selenium-server.jar -multiwindow。则会在两个窗口中显示运行结果 (2)启动selenium-server时,输入以下的命令:java -jar selenium-server.jar -singlewindow。则会在一个窗口中显示运行结果 15.怎样访问变量? ${变量名} 16.在录制的过程中,遇到了提示框的话,要怎样处理才能在正常的回放? 17.录制到邮件的时候,不能正常录制,要如何处理呢? 录制的时候,首先要指定要框架,然后再输入文本。 例如:邮件通过firebug定位为: 在selenium ide中则需要手动的输入以下的内容: 再输入一条以下的命令:selectFrame relative=top 则,此时的本就能正常的运行了。 18.录制到组件的时候,不能正常录制,要怎样处理? 例如:上传附件(以及其它一些要上传的东西),刚发现附件并不是不能录制,而是你在界面中的定位不是很清楚,selenium不能识别。 19.录制时,会跳出多个窗口,此时要怎样处理? 存在四种解决方法,可以参考http://www.boobooke.com/bbs/viewthread.php?tid=41824&highlight=selenium中的第七集 具体方法如下:(1)java中可用如下的代码:String[] titles =selenium.getAllWindowTitles(); //得到所有窗口的标题 selenium.selectWindow("title="+titles[titles.length-1]); //选择最后打开的一个窗口 selenium.close(); //关闭最后打开的一个窗口 selenium.selectWindow("null"); //重新聚集在最开始的一个窗口(只有两个窗口的时候) (2)java中可用如下的代码:selenium.click("link=????"); 换成如下的两行代码 String url = selenium.getAttribute(link=????@href); selenium.open(url); 注:此方法也存在一定的缺陷,就是不能验证click点击事件是否正确。 (3)利用javascript去掉原代码中的target="_blank"的属性(目前为止还不清楚) (4)这种方法不清楚,看的不是很懂 20.什么是window

5,177

社区成员

发帖
与我相关
我的任务
社区描述
软件工程/管理 质量管理/软件测试
功能测试压力测试安全性测试 个人社区 湖南省·长沙市
社区管理员
  • 软件测试
  • 虫无涯
  • 小博测试成长之路
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

欢迎大家加入到软件测试的社区,在这里,希望大家勇于发表自己的看法,欢迎大家分享自己在软件测试工作过程中遇到的问题以及工作经验分享。

1.想转行的小伙伴,遇到问题没有及时回复的,可以私聊小博进行反馈

2.大家对社区有好的建议,都可以在社区发帖进行反馈

推荐大家学习的软件测试入门笔记:软件测试入门学习笔记

试试用AI创作助手写篇文章吧