packageavaya.browser.method;importjava.io.IOException;importjava.util.*;importorg.junit.Before;importorg.openqa.*;importcom.thoughtworks.selenium.Wait;importavaya.browser.interfac.Driver;//{attention:以Br.开头的方法,是因为Br是自己在本类还封装了一层,需要仔细看代码}publicclassBrextendsBaseclass{privateStringlocator;publicstaticStringlog(Stringinfo){System.out.println(info);returninfo;}publicstaticvoidopenbrowser(Stringurl){//driver=newFirefoxDriver();//Navigationnavitation=driver.navigate();//navitation.to(url);driver.get(url);Br.log(openbrowserandinputtestURL:+url);}//oprationthewindowsmaxpublicstaticvoidmaxwindow(){driver.manage().window().maximize();Br.log(maxwindows);}//refreshthewindowspublicstaticvoidrefresh(){driver.navigate().refresh();Br.log(refreshthewindows);}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),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.log(登陆账号为:+user++登陆密码为:+pwd);}//ifformparameterisnotnull,inputdataandusethismethod;publicstaticvoidclosebrowser(StringBrowserType){if(BrowserType!=null){if(BrowserType.equals(c)){try{Runtime.getRuntime().exec(taskkill/F/IMchrome.exe);}catch(IOExceptione){//TODOAuto-generatedcatchblocke.printStackTrace();}}elseif(BrowserType.equals(i)){try{Runtime.getRuntime().exec(taskkill/F/IMiexplorer.exe);}catch(IOExceptione){//TODOAuto-generatedcatchblocke.printStackTrace();}}elseif(BrowserType.equals(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(IOExceptione){//TODOAuto-generatedcatchblocke.printStackTrace();}}else{try{Runtime.getRuntime().exec(taskkill/F/IMfirefox.exe);}catch(IOExceptione){//TODOAuto-generatedcatchblocke.printStackTrace();}}}}//ifformparameterisnull,usethismethod;publicstaticvoidclosebrowser(){try{Runtime.getRuntime().exec(taskkill/F/IMfirefox.exe);}catch(IOExceptione){//TODOAuto-generatedcatchblocke.printStackTrace();}}publicstaticvoidswitchToIframe(Byby){driver.switchTo().frame(driver.findElement(by));//driver.switchTo().frame(driver.findElement(By.xpath(/html/body/div[4]/div[4]/div/div/iframe)));}//findelementandsetthevaluepublicstaticvoidsendkeys(Byby,Stringstr)throwsInterruptedException{Stringtext;//text=driver.findElement(by).getText();driver.findElement(by).clear();Thread.sleep(1500);driver.findElement(by).sendKeys(str);//Br.log(executeselectelementobject+text);Br.log(Set:+str);}publicstaticvoidclick(Byby)throwsInterruptedException{Stringtext;if(driver.findElement(by).getText()!=null&&!.equals(driver.findElement(by).getText())){text=driver.findElement(by).getText();Thread.sleep(3000);System.out.println(executeclickoperation);System.out.println(click++text);}else{System.out.println(thisElementisnotfoundtext);}driver.findElement(by).click();}/*doubleclick*@by*/publicstaticvoiddoubleClick(Byby){newActions(driver).doubleClick(driver.findElement(by)).doubleClick();}publicstaticvoidclear(Byby){driver.findElement(by).clear();Br.log(Emptyelementcontent,by:+by);}/*selectelementbyindex*webdriverisnonsupportselectfunction,sosuggestnot*/publicstaticvoidselectByIndex(Byby,intindex){//driver.findElement(by).click();Stringtext;Selectselect=newSelect(driver.findElement(by));try{Thread.sleep(10);}catch(InterruptedExceptione){//TODOAuto-generatedcatchblocke.printStackTrace();}select.selectByIndex(index);Br.log(Performadrop-downboxoperations,operationelement:+by);text=getWebText(by);Br.log(select+index+element+elementinfois:+text);}/*selectelementbyvalue*webdriverisnonsupportselectfunction,sosuggestnot*/publicstaticvoidselectByText(Byby,Stringtext){driver.findElement(by).click();Selectselect=newSelect(driver.findElement(by));select.selectByVisibleText(text);}//selectelementbyvalue//publicstaticvoidselectBy(Byby,Stringvalue){//driver.findElement(by).click();////Selectselect=newSelect(driver.findElement(by));//select.selectByValue(value);////}//publicstaticvoidselect(Byby0,Byby1){//driver.findElement(by0).click();//driver.findElement(by1).click();////Selectselect=newSelect(driver.findElement(by));////select.selectByValue(value);//}/*selectelementbylinktext*webdriverisnonsupportselectfunction,sosuggestnot*/publicstaticvoidselectByLinkText(Byby,StringLinkText){//driver.findElement(by).click();Selectselect=newSelect(driver.findElement(by));select.selectByValue(LinkText);Br.log(executeselectelement,theobject:+LinkText);}//获取链接元素的url值…………………………publicstaticStringgetLinkUrl(Byby){returndriver.findElement(by).getAttribute(href);}//判断某个元素是否存在publicstaticbooleanisElementExist(Byby){try{Booleanbool=driver.findElement(by).isDisplayed();Br