欢迎来到天天文库
浏览记录
ID:6380080
大小:132.05 KB
页数:10页
时间:2018-01-12
《selenium常用的方法》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、packageavaya.browser.method;importjava.io.IOException;importjava.util.*;importorg.junit.Before;importorg.openqa.*;importcom.thoughtworks.selenium.Wait;importavaya.browser.interfac.Driver;//{attention:以Br.开头的方法,是因为Br是自己在本类还封装了一层,需要仔细看代码}publicclassBrext
2、endsBaseclass{privateStringlocator;publicstaticStringlog(Stringinfo){System.out.println(info);returninfo;}publicstaticvoidopenbrowser(Stringurl){//driver=newFirefoxDriver();//Navigationnavitation=driver.navigate();//navitation.to(url);driver.get(url);B
3、r.log("openbrowserandinputtestURL:"+url);}//oprationthewindowsmaxpublicstaticvoidmaxwindow(){driver.manage().window().maximize();Br.log("maxwindows");}//refreshthewindowspublicstaticvoidrefresh(){driver.navigate().refresh();Br.log("refreshthewindows");
4、}publicstaticvoidlogin(Stringurl,Stringuser,Stringpwd)throwsInterruptedException{driver.get(url);Br.clear(By.id("Br.logrm:username"));Br.sendkeys(By.id("Br.logrm:username"),user);Br.clear(By.id("Br.logrm:password"));Br.sendkeys(By.id("Br.logrm:password
5、"),pwd);Br.getWebText(By.id("Br.logrm:submitText"));driver.findElement(By.id("Br.logrm:submitText")).click();try{Thread.sleep(5000);}catch(InterruptedExceptione){//TODOAuto-generatedcatchblocke.printStackTrace();}Op.refresh();Br.log(",input:"+url);Br.l
6、og("登陆账号为:"+user+""+"登陆密码为:"+pwd);}//ifformparameterisnotnull,inputdataandusethismethod;publicstaticvoidclosebrowser(StringBrowserType){if(BrowserType!=null){if(BrowserType.equals("c")){try{Runtime.getRuntime().exec("taskkill/F/IMchrome.exe");}catch(IO
7、Exceptione){//TODOAuto-generatedcatchblocke.printStackTrace();}}elseif(BrowserType.equals("i")){try{Runtime.getRuntime().exec("taskkill/F/IMiexplorer.exe");}catch(IOExceptione){//TODOAuto-generatedcatchblocke.printStackTrace();}}elseif(BrowserType.equa
8、ls("o")){try{Runtime.getRuntime().exec("taskkill/F/IMopera.exe");}catch(IOExceptione){//TODOAuto-generatedcatchblocke.printStackTrace();}}elseif(BrowserType.equals("s")){try{Runtime.getRuntime().exec("taskkill/F/IMsafari.exe");}catch(IO
此文档下载收益归作者所有