初次使用selenium时遇到的问题

安装firebug,selenium IDE ,查看元素时firefinder可以验证XPath和CSS定位表达式是否正确
学习中遇到的错误:
1. java.lang.NoClassDefFoundError: com/google/common/base/Function,添加server-standlone jar即可解决

3. UnixProcess$SeleniumWatchDog destroyHarder--解决方案-删除安装文件夹的
C:\Program Files\Mozilla Firefox\plugin-container.exe.

4. org.openqa.selenium.ElementNotVisibleException: Element is not currently visible and so may not be interacted with
Command duration or timeout: 140 milliseconds--解决方案-设置等待时间

5. 83和84页有保存cookies和读取cookies信息的方法讲解

6. selenium中的文件操作:Filehandler/takeScreenshot/getScreenshotAs, 压缩目录操作对远程机器上的大量日志和截图适合

7. Junit4中的@Test执行顺序随机执行--解决方法:
①.  由于@Test的执行顺序是根据反射API返回的顺序执行的,可以通过@Test前添加@FixMethodOrder(MethodSorters.NAME_ASCENDING).Junit4.11以上版本支持
三种执行顺序可供选择:
默认(MethodSorters.DEFAULT)
按方法名(MethodSorters.NAME_ASCENDING)
JVM(MethodSorters.JVM) 

②. 使用public static Test Suit(){
suite.addTest();}
③. 使用TestNG

8. 书写xpath时需要多个属性条件时使用 and连接,如://div[@class='in' and @style='top: 10%;']/div/a[@title='关闭']

9. 配置TestNG
①. install softwear  http://beust.com/eclipse
②. 需要安装JDK1.7以上的版本

10.  junit3与junit4的区别还是比较明显的,在junit3中,如果某个类是测试类,必须将其继承类TestCase,如果某个方法是测试方法,必须让这个方法以testXX开头,如果希望指定某个测试方法运行之前运行某个初始化方法,这个方法的名称必须是setUp,如果希望在某个测试方法运行之后运行某个释放资源的方法,这个方法的名称必须是tearDown。
在junit4中,一个POJO类就是一个测试类,测试方法通过@Test来标识,初始化方法通过@Before来标识,释放资源的方法通过@After来标识,但是为了让junit4的测试类在junit3中也可以使用,习惯于把初始化方法命名为setUp,释放资源的方法命名为tearDown。Test中的测试方法一般以Test来开始。其中标识为Before注解的方法,每次运行测试类,都会执行标识为@After与@Before的方法。

11. 在线安装TestNG 后重启Eclipse,新建测试类时没有testNG 选择--解决方案:--安装1.7以上的JDK版本

12. 测试 类中只能有一个构造方法

13. 运行时,有部分操作未执行,但是junit运行通过。不知道为什么?
--有遇到过并且知道原因的欢迎评论

14.  org.testng.TestNGException: Parameter 'Username' is required by @Test on method loginTest but has not been marked @Optional or defined in C:\\AppData\Local\Temp\testng-eclipse--1466657283\testng-customsuite.xml
解决方法①: When you run as suite, that particular xml is used. But when you select a single test and run it, testng creates a custom testng file (with bare minimums - no parameters, no listeners - you can take a look at the file on the path that you mention).
You need to specify your xml as a template xml in eclipse if that is a standard xml that you use.  Go to project properties -> testng -> Set the xml as a template xml.
上面设置XML template失败,有待研究【欢迎大家评论给予答案】

解决方法②:配置下运行条件:右键-run in configuration-- suite-选择bin目录下自定义的xml文件

15. build失败和 Unsupported major.minor version 52.0
JDK版本不同导致运行失败
1. JDK中有jre和JDK的区别
解决方法:更新 JRE设置到1.8版本

16.   org.openqa.selenium.os.UnixProcess$SeleniumWatchDog destroyHarder
原因:尝试关闭浏览器驱动时,页面还在loading
解决方法:每次提示,但是能正常运行

你可能感兴趣的:(Java学习,Selenium学习笔记)