|
3#
楼主 |
发表于 2017-7-18 14:27:10
|
只看该作者
- public String[] getAllWindowIds() {
- System.out.println("不能实现!");
- returnnull;
- }
- public String[] getAllWindowNames() {
- System.out.println("不能实现!");
- returnnull;
- }
- public String[] getAllWindowTitles() {
- Set<String> handles = driver.getWindowHandles();
- Set<String> titles = new HashSet<String>();
- for(String handle : handles){
- titles.add(driver.switchTo().window(handle).getTitle());
- }
- return titles.toArray(new String[titles.size()]);
- }
- public String getHtmlSource() {
- return driver.getPageSource();
- }
- publicvoid setCursorPosition(String locator,String position) {
- System.out.println("没能实现!");
- }
- public Number getElementIndex(String locator) {
- System.out.println("没能实现!");
- returnnull;
- }
- public Object isOrdered(By by1,By by2) {
- System.out.println("没能实现!");
- returnnull;
- }
- public Number getElementPositionLeft(By by) {
- return driver.findElement(by).getLocation().getX();
- }
- public Number getElementPositionTop(By by) {
- return driver.findElement(by).getLocation().getY();
- }
- public Number getElementWidth(By by) {
- return driver.findElement(by).getSize().getWidth();
- }
- public Number getElementHeight(By by) {
- return driver.findElement(by).getSize().getHeight();
- }
- public Number getCursorPosition(String locator) {
- System.out.println("没能实现!");
- returnnull;
- }
- public String getExpression(String expression) {
- System.out.println("没能实现!");
- returnnull;
- }
- public Number getXpathCount(By xpath) {
- return driver.findElements(xpath).size();
- }
- publicvoid assignId(By by,String identifier) {
- System.out.println("不想实现!");
- }
- /*publicvoid allowNativeXpath(String allow) {
- commandProcessor.doCommand("allowNativeXpath",new String[] {allow,});
- }*/
- /*public void ignoreAttributesWithoutValue(String ignore) {
- commandProcessor.doCommand("ignoreAttributesWithoutValue", new String[] {ignore,});
- }*/
- publicvoid waitForCondition(String script,String timeout,Object... args) {
- Boolean b = false;
- int time =0;
- while(time <= Integer.parseInt(timeout)){
- b = (Boolean) ((JavascriptExecutor)driver).executeScript(script,args);
- if(b==true)break;
- try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- time += 1000;
- }
- }
- publicvoid setTimeout(String timeout) {
- driver.manage().timeouts().implicitlyWait(Integer.parseInt(timeout), TimeUnit.SECONDS);
- }
- publicvoid waitForPageToLoad(String timeout) {
- driver.manage().timeouts().pageLoadTimeout(Integer.parseInt(timeout), TimeUnit.SECONDS);
- }
- publicvoid waitForFrameToLoad(String frameAddress,String timeout) {
- /*driver.switchTo().frame(frameAddress)
- .manage()
- .timeouts()
- .pageLoadTimeout(Integer.parseInt(timeout), TimeUnit.SECONDS);*/
- }
- public String getCookie() {
- String cookies = "";
- Set<Cookie> cookiesSet = driver.manage().getCookies();
- for(Cookie c : cookiesSet){
- cookies += c.getName()+"="+c.getValue()+";";
- }
- return cookies;
- }
- public String getCookieByName(String name) {
- return driver.manage().getCookieNamed(name).getValue();
- }
- publicboolean isCookiePresent(String name) {
- boolean b =false ;
- if(driver.manage().getCookieNamed(name) !=null || driver.manage().getCookieNamed(name).equals(null))
- b = true;
- return b;
- }
- publicvoid createCookie(Cookie c) {
- driver.manage().addCookie(c);
- }
- publicvoid deleteCookie(Cookie c) {
- driver.manage().deleteCookie(c);
- }
- publicvoid deleteAllVisibleCookies() {
- driver.manage().getCookieNamed("fs").isSecure();
- }
- /*public void setBrowserLogLevel(String logLevel) {
- }*/
- /*public void runScript(String script) {
- commandProcessor.doCommand("runScript", new String[] {script,});
- }*/
- /*public void addLocationStrategy(String strategyName,String functionDefinition) {
- commandProcessor.doCommand("addLocationStrategy", new String[] {strategyName,functionDefinition,});
- }*/
- publicvoid captureEntirePageScreenshot(String filename) {
- File screenShotFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
- try {
- FileUtils.copyFile(screenShotFile,new File(filename));
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- /*public void rollup(String rollupName,String kwargs) {
- commandProcessor.doCommand("rollup", new String[] {rollupName,kwargs,});
- }
- public void addScript(String scriptContent,String scriptTagId) {
- commandProcessor.doCommand("addScript", new String[] {scriptContent,scriptTagId,});
- }
- public void removeScript(String scriptTagId) {
- commandProcessor.doCommand("removeScript", new String[] {scriptTagId,});
- }
- public void useXpathLibrary(String libraryName) {
- commandProcessor.doCommand("useXpathLibrary", new String[] {libraryName,});
- }
- public void setContext(String context) {
- commandProcessor.doCommand("setContext", new String[] {context,});
- }*/
- /*public void attachFile(String fieldLocator,String fileLocator) {
- commandProcessor.doCommand("attachFile", new String[] {fieldLocator,fileLocator,});
- }*/
- /*public void captureScreenshot(String filename) {
- commandProcessor.doCommand("captureScreenshot", new String[] {filename,});
- }*/
- public String captureScreenshotToString() {
- String screen = ((TakesScreenshot)driver).getScreenshotAs(OutputType.BASE64);
- return screen;
- }
- /* public String captureNetworkTraffic(String type) {
- return commandProcessor.getString("captureNetworkTraffic", new String[] {type});
- }
- */
- /*public void addCustomRequestHeader(String key, String value) {
- commandProcessor.getString("addCustomRequestHeader", new String[] {key, value});
- }*/
- /*public String captureEntirePageScreenshotToString(String kwargs) {
- return commandProcessor.getString("captureEntirePageScreenshotToString", new String[] {kwargs,});
- }*/
- publicvoid shutDown() {
- driver.quit();
- }
- /*public String retrieveLastRemoteControlLogs() {
- return commandProcessor.getString("retrieveLastRemoteControlLogs", new String[] {});
- }*/
- publicvoid keyDownNative(Keys keycode) {
- new Actions(driver).keyDown(keycode).perform();
- }
- publicvoid keyUpNative(Keys keycode) {
- new Actions(driver).keyUp(keycode).perform();
- }
- publicvoid keyPressNative(String keycode) {
- new Actions(driver).click().perform();
- }
- publicvoid waitForElementPresent(By by) {
- for(int i=0; i<60; i++) {
- if (isElementPresent(by)) {
- break;
- } else {
- try {
- driver.wait(1000);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- }
- }
- publicvoid clickAndWaitForElementPresent(By by, By waitElement) {
- click(by);
- waitForElementPresent(waitElement);
- }
- public Boolean VeryTitle(String exception,String actual){
- if(exception.equals(actual))returntrue;
- elsereturnfalse;
- }
- }
复制代码 PS:有什么建议,欢迎评论,一起交流!
|
|