selenium Selenium Selenium Selenium Selenium Selenium Grid Web
自动化测试selenium
目录 ß ß ß ß Selenium特性 Selenium 作原理 Selenium定位页面元素 Selenium命令结构 Selenium Grid Web. Driver定位页面元素 Web. Driver和Selenium 1. 0的区别
Selenium特性 u u 可对多浏览器进行测试,如IE,Firefox, Safari,Chrome,Android手机浏览器等 支持多种语言,例如 : Java, C#, Pathon, Ruby, PHP等 跨平台,例如: Windows, Linux, IOS, Android等 开源免费
Selenium都有什么? u Selenium Core(JS函数集合) u Selenium IDE(仅在Firefox中使用) u Selenium Remote Control u Selenium Grid
Selenium与Test. Case的关系
定位页面元素 u u u Idenfifier identifier=login. Form name=username XPath //input[@name='username'] link=Continue dom. forms[0]. elements[3] css=form#login. Form
Selenium命令结构 Command Target (action or assertion) (element location) type p Value bananas selenium. open("http: //www. yahoo. com/”); selenium. type("p", "bananas”); selenium. click("link=Images”); selenium. wait. For. Page. To. Load(“ 30000”); Assert. assert. True(selenium. is. Text. Present(”My favorite bananas”));
Selenium Grid 作原理
Web. Driver定位页面元素 ß ß ß ß Id Name Link. Text Partial. Link. Text Class. Name Tag. Name Xpath
测试用例 public class Test. Hello. Word. Test. NG { Web. Driver driver; @Test public void hello. World() throws Exception { driver = new Firefox. Driver(); //不打开实际浏览器 //driver = new Html. Unit. Driver(); long wait. Time=3000; String login. URL="https: //www. firstp 2 p. com/user/login"; String user. Name="name 1"; String password="121212"; driver. get(login. URL); driver. manage(). window(). maximize(); Common. Tasks. wait. For. Page. To. Load(wait. Time); driver. find. Element(By. id("user")). send. Keys(user. Name); driver. find. Element(By. id("input-password")). send. Keys(password); driver. find. Element(By. class. Name("enter_btn")). click(); /*关闭浏览器*/ driver. close(); } }
Thanks!
- Slides: 21