selenium自动化测试
来源:互联网 发布:西安理工大学知行 编辑:程序博客网 时间:2024/06/06 09:59
自动化测试主要依赖于浏览器驱动实现。这里以IE为例。
package seleniumTest;import java.io.File;import java.io.IOException;import java.util.concurrent.TimeUnit;import org.openqa.selenium.By;import org.openqa.selenium.WebDriver;import org.openqa.selenium.ie.InternetExplorerDriver;import org.openqa.selenium.remote.Augmenter;import org.apache.commons.io.FileUtils;import org.openqa.selenium.OutputType;import org.openqa.selenium.TakesScreenshot;public class Selenium {static String dir="C:\\";/** * 主程序 * * @param args * @throws InterruptedException * @throws IOException */public static void main(String[] args) throws Exception {//设置驱动System.setProperty("webdriver.ie.driver", "C:/Program Files/Internet Explorer/IEDriverServer.exe");WebDriverdriver = new InternetExplorerDriver();// 隐式等待10S(10秒内响应后直接运行,不响应报错)driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);// 窗口最大化driver.manage().window().maximize();//进入要测试的网址driver.get("http://www.cnblogs.com/tobecrazy/p/3599568.html");takeScreenShotIE(driver, "123");//点击按钮1driver.findElement(By.id("button")).click();//清空text框1driver.findElement(By.id("text")).clear();//向text框中输入值driver.findElement(By.id("text")).sendKeys("123");//切换进当前画面的frame1driver.switchTo().frame("frame1");//切换进frame1里面的frame2driver.switchTo().frame("frame2");//切换至原始画面driver.switchTo().defaultContent();//切换进当前画面的frame3driver.switchTo().frame("frame3");}//IE截图public static void takeScreenShotIE(WebDriver driver, String name){ WebDriver augmentedDriver = new Augmenter().augment(driver); File output = ((TakesScreenshot) augmentedDriver).getScreenshotAs(OutputType.FILE); File file = new File(dir, name + ".png"); try { FileUtils.copyFile(output, file); }catch (IOException e) { e.printStackTrace(); }}//谷歌和火狐截图public static void takeScreenShotChromeFirefox(WebDriver driver, String name){ File output = null; File file; output = ((TakesScreenshot) driver) .getScreenshotAs(OutputType.FILE); file = new File(dir, name + ".png"); try { FileUtils.copyFile(output, file); } catch (IOException e) { e.printStackTrace(); }}}
自动化测试获取元素和操作元素的方式和js相似。
如果有嵌套三层iframe,要回到主画面,再一个一个进。
JAVA的selenium不支持回到父画面。
资源下载地址:http://download.csdn.net/detail/qq_26508409/9925820(不包括驱动)
阅读全文
0 0
- Selenium 自动化测试工具
- Selenium 自动化测试系统
- Selenium 自动化验收测试
- python + selenium 自动化测试
- junit+selenium自动化测试
- 自动化测试:selenium
- 自动化测试--selenium-webDriver
- The Selenium 自动化测试
- selenium自动化测试
- 自动化测试selenium
- selenium java自动化测试
- selenium + python 自动化测试
- selenium java自动化测试
- 自动化测试(selenium)
- selenium 自动化web测试
- Python自动化测试-Selenium
- Selenium自动化测试在
- selenium+Junit自动化测试
- dubbo中几种protocol的理解
- Android获取滑动阈值(系统认为最低的滑动距离)
- having和where的区别
- 剑指offer-矩阵中的路径
- 第一个jquery插件(jquery插件)
- selenium自动化测试
- openjudge1807正方形题解
- 【SignalR学习系列】4. SignalR广播程序
- 利用tcpprobe思想和tracepoint利器可以做一个检测丢包工具
- 中点的规律
- AVL_WORKSPACE_SUITE_
- Access denied for user 'root'@'localhost' (using password:YES) 解决方法
- 卡片游戏
- js模块化进程