- 浏览: 187744 次
- 性别:
- 来自: 上海
文章分类
- 全部博客 (83)
- J2EE/Core Java (24)
- J2EE/Portal (2)
- J2EE/UI (4)
- J2EE/ATG (1)
- J2EE/Report (1)
- J2EE/Web Service/Rest API (2)
- Design Pattern (2)
- Arithmetic (4)
- Linux (12)
- Ruby&Rails (17)
- Database (5)
- J2EE/Payment (1)
- J2EE/JVM (1)
- Encryption/Decryption (3)
- J2EE/Multi Threading (4)
- SQL (1)
- https://community.teamviewer.com/t5/Knowledge-Base/Where-can-I-download-older-TeamViewer-versions-nbsp/ta-p/7729 (0)
最新评论
1 What is Selenium?
2 Selenium Web Driver Maven pom
3 give a sample for test upload file, below is the simplest jsp for springmvc file upload
4 Junit Tester
5 Selenium helper class
5 attached test project(selenium) and springmvc project(repository)
引用
Selenium automates browsers. That's it. What you do with that power is entirely up to you. Primarily it is for automating web applications for testing purposes, but is certainly not limited to just that. Boring web-based administration tasks can (and should!) also be automated as well.
Selenium has the support of some of the largest browser vendors who have taken (or are taking) steps to make Selenium a native part of their browser. It is also the core technology in countless other browser automation tools, APIs and frameworks.
Selenium has the support of some of the largest browser vendors who have taken (or are taking) steps to make Selenium a native part of their browser. It is also the core technology in countless other browser automation tools, APIs and frameworks.
2 Selenium Web Driver Maven pom
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.wilson</groupId> <artifactId>selenium</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>selenium</name> <url>http://maven.apache.org</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.10</version> <type>jar</type> <scope>compile</scope> </dependency> <dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-java</artifactId> <version>2.21.0</version> <type>jar</type> <scope>compile</scope> </dependency> </dependencies> </project>
3 give a sample for test upload file, below is the simplest jsp for springmvc file upload
<html> <head> <title>file upload test</title> </head> <body> <form method="post" action="uploader" enctype="multipart/form-data"> <input type="text" name="name" value="file"/> <input type="file" name="file" /> <input id="submit" type="submit" /> </form> </body> </html>
4 Junit Tester
package com.wilson.selenium; import org.junit.BeforeClass; import org.junit.Test; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.ie.InternetExplorerDriver; import org.openqa.selenium.remote.DesiredCapabilities; public class FileUploadTest { protected static String baseUrl = "http://localhost"; protected static Selenium2 s; @BeforeClass public static void beforeClass() throws Exception { createSeleniumOnce(); } /** * 创建Selenium. */ protected static void createSeleniumOnce() throws Exception { if (s == null) { // 根据配置创建Selenium driver. // WebDriver driver = WebDriverFactory.createDriver("ie"); DesiredCapabilities ieCapabilities = DesiredCapabilities .internetExplorer(); ieCapabilities .setCapability( InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true); WebDriver driver = new InternetExplorerDriver(ieCapabilities); s = new Selenium2(driver, baseUrl); // WebDriver driver = new FirefoxDriver(); // s = new Selenium2(driver, baseUrl); s.setStopAtShutdown(); } } @Test public void test() { s.open("/upload.jsp"); s.type(By.name("name"), "11"); // s.type(By.name("file"), "D:/wubi.exe"); s.findElement(By.name("file")).sendKeys("D:\\21.xls"); s.click(By.id("submit")); } }
5 Selenium helper class
/** * Copyright (c) 2005-2012 springside.org.cn * * Licensed under the Apache License, Version 2.0 (the "License"); */ package com.wilson.selenium; import java.util.List; import java.util.concurrent.TimeUnit; import org.openqa.selenium.By; import org.openqa.selenium.NoSuchElementException; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.support.ui.ExpectedCondition; import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.Select; import org.openqa.selenium.support.ui.WebDriverWait; /** * 融合了Selenium 1.0 API与Selenium 2.0的By选择器的API. * * @author calvin */ public class Selenium2 { public static final int DEFAULT_WAIT_TIME = 20; private WebDriver driver; private String baseUrl; public Selenium2(WebDriver driver, String baseUrl) { this.driver = driver; this.baseUrl = baseUrl; setTimeout(DEFAULT_WAIT_TIME); } /** * 不设置baseUrl的构造函数, 调用open函数时必须使用绝对路径. */ public Selenium2(WebDriver driver) { this(driver, ""); } /** * 注册在JVM退出时关闭Selenium的钩子。 */ public void setStopAtShutdown() { Runtime.getRuntime().addShutdownHook(new Thread("Selenium Quit Hook") { @Override public void run() { quit(); } }); } // Driver 函數 // /** * 打开地址,如果url为相对地址, 自动添加baseUrl. */ public void open(String url) { final String urlToOpen = url.indexOf("://") == -1 ? baseUrl + (!url.startsWith("/") ? "/" : "") + url : url; driver.get(urlToOpen); } /** * 获取当前页面. */ public String getLocation() { return driver.getCurrentUrl(); } /** * 回退历史页面。 */ public void back() { driver.navigate().back(); } /** * 刷新页面。 */ public void refresh() { driver.navigate().refresh(); } /** * 获取页面标题. */ public String getTitle() { return driver.getTitle(); } /** * 退出Selenium. */ public void quit() { try { driver.quit(); } catch (Exception e) { System.err.println("Error happen while quit selenium :" + e.getMessage()); } } /** * 设置如果查找不到Element时的默认最大等待时间。 */ public void setTimeout(int seconds) { driver.manage().timeouts().implicitlyWait(seconds, TimeUnit.SECONDS); } /** * 获取WebDriver实例, 调用未封装的函数. */ public WebDriver getDriver() { return driver; } //Element 函數// /** * 查找Element. */ public WebElement findElement(By by) { return driver.findElement(by); } /** * 查找所有符合条件的Element. */ public List<WebElement> findElements(By by) { return driver.findElements(by); } /** * 判断页面内是否存在Element. */ public boolean isElementPresent(By by) { try { driver.findElement(by); return true; } catch (NoSuchElementException e) { return false; } } /** * 判断Element是否可见. */ public boolean isVisible(By by) { return driver.findElement(by).isDisplayed(); } /** * 在Element中输入文本内容. */ public void type(By by, String text) { WebElement element = driver.findElement(by); element.clear(); element.sendKeys(text); } /** * 点击Element. */ public void click(By by) { driver.findElement(by).click(); } /** * 选中Element. */ public void check(By by) { WebElement element = driver.findElement(by); check(element); } /** * 选中Element. */ public void check(WebElement element) { if (!element.isSelected()) { element.click(); } } /** * 取消Element的选中. */ public void uncheck(By by) { WebElement element = driver.findElement(by); uncheck(element); } /** * 取消Element的选中. */ public void uncheck(WebElement element) { if (element.isSelected()) { element.click(); } } /** * 判断Element有否被选中. */ public boolean isChecked(By by) { WebElement element = driver.findElement(by); return isChecked(element); } /** * 判断Element有否被选中. */ public boolean isChecked(WebElement element) { return element.isSelected(); } /** * 返回Select Element,可搭配多种后续的Select操作. * eg. s.getSelect(by).selectByValue(value); */ public Select getSelect(By by) { return new Select(driver.findElement(by)); } /** * 获取Element的文本. */ public String getText(By by) { return driver.findElement(by).getText(); } /** * 获取Input框的value. */ public String getValue(By by) { return getValue(driver.findElement(by)); } /** * 获取Input框的value. */ public String getValue(WebElement element) { return element.getAttribute("value"); } // WaitFor 函數 // /** * 等待Element的内容可见, timeout单位为秒. */ public void waitForVisible(By by, int timeout) { waitForCondition(ExpectedConditions.visibilityOfElementLocated(by), timeout); } /** * 等待Element的内容为text, timeout单位为秒. */ public void waitForTextPresent(By by, String text, int timeout) { waitForCondition(ExpectedConditions.textToBePresentInElement(by, text), timeout); } /** * 等待Element的value值为value, timeout单位为秒. */ public void waitForValuePresent(By by, String value, int timeout) { waitForCondition(ExpectedConditions.textToBePresentInElementValue(by, value), timeout); } /** * 等待其他Conditions, timeout单位为秒. * * @see #waitForTextPresent(By, String, int) * @see ExpectedConditions */ public void waitForCondition(ExpectedCondition conditon, int timeout) { (new WebDriverWait(driver, timeout)).until(conditon); } // Selenium1.0 函數 // /** * 简单判断页面内是否存在文本内容. */ public boolean isTextPresent(String text) { String bodyText = driver.findElement(By.tagName("body")).getText(); return bodyText.contains(text); } /** * 取得单元格的内容, 序列从0开始, Selnium1.0的常用函数. */ public String getTable(WebElement table, int rowIndex, int columnIndex) { return table.findElement(By.xpath("//tr[" + (rowIndex + 1) + "]//td[" + (columnIndex + 1) + "]")).getText(); } /** * 取得单元格的内容, 序列从0开始, Selnium1.0的常用函数. */ public String getTable(By by, int rowIndex, int columnIndex) { return getTable(driver.findElement(by), rowIndex, columnIndex); } }
5 attached test project(selenium) and springmvc project(repository)
- selenium.zip (44.9 KB)
- 下载次数: 32
- repository.zip (162.4 KB)
- 下载次数: 18
- springside-4.0.0.GA.zip (1 MB)
- 下载次数: 9
发表评论
-
Start tomcat with port 80 without Linux root user-Use iptables mapping
2016-05-25 17:39 833引用In linux system. only root us ... -
Format XML in JAVA
2016-01-11 12:23 605public static String format ... -
HttpURLConnection下载文件
2015-08-07 11:25 797public class HttpDownloadUtilit ... -
Ehcache RMI Replicated Cluster(RMI集群)
2013-04-25 23:39 1075引用本文是ehcache RMI集群的例子,导入附件中的jav ... -
Integrete unitils for database(dao) testing
2013-02-01 18:39 1695引用Database testing Unit tests f ... -
JAXB入门
2012-10-16 11:59 791引用jaxb是一个读写xml的工具,还可以提供验证,不需要额外 ... -
Freemarker使用入门
2012-10-16 11:54 1023引用freemarker是一种模板标记工具,可以做页面静态化, ... -
perforce java api使用
2012-10-16 11:43 1258引用perforce是种版本管理软件,提供啦完整的java a ... -
XPath 入门
2012-10-16 11:29 884引用xpath可以快速定位获取XML文件中指定属性和值,jdk ... -
Java File Diff-diffutils
2012-09-27 17:35 74671. Maven Dependency <depende ... -
XSD 入门使用
2012-09-18 23:20 780<?xml version="1.0" ... -
nexus-2.1.1安装及使用入门
2012-08-13 22:52 14501. 安装 地址http://www.sonatype.org ... -
File Demo
2012-06-25 22:55 1312package org.springside.examples ... -
Java 访问sharepoint webservice(NTLM & SSL)
2012-06-12 09:47 3775引用遇到需要使用java访问微软的sharepoint的web ... -
HttpClient4.1.2 & HtmlUnit2.9 处理文件下载
2012-01-09 18:18 1030TestCode import java.io.Fi ... -
HttpClient4.1.2 & HtmlUnit2.9 NTLM 验证 和 Httpclient4.1.2 https/SSL
2012-01-09 18:13 15981. HttpClient4.1.2 & HtmlUn ... -
HttpClient4登陆ITeye
2012-01-08 23:33 1901import java.io.IOException; im ... -
Spring2集成测试
2011-08-25 22:21 766Spring2测试类继承层次 集成测试例子 public ... -
Learning EasyMock3.0 By Official Example
2011-08-24 16:48 1378Maven Installation+ add followi ... -
Maven+jetty+jrebel+m2eclipse+eclipse搭建struts2开发环境
2011-08-11 11:18 4129引用Maven:项目构建工具,通过pom.xml可以自动维护j ...
相关推荐
Selenium Web Driver for automated web test
python库。 资源全名:selenium_driver_updater-3.9.0.tar.gz
selenium谷歌driver与IEdriver selenium谷歌driver与IEdriver selenium谷歌driver与IEdriver selenium谷歌driver与IEdriver
selenium driver chrome opera selenium driver chrome opera selenium driver chrome opera
最新版 selenium chrome driver 2.34,最新版 selenium chrome driver 2.34
简单的Java+selenium初级入门知识,自己自学记录的,仅供参考。
整体包括了selenium常用的浏览器driver,有谷歌、火狐、opera、EDGE还有htmlunit,各个系统和版本都有
Selenium Chrome Driver2.3.4 ,完美支持61-63版本Chrome
selenium WEB 测试工具,开源工具。 主要是做保存,可以在公司下载。
selenium geckodriver版本为v0.21.0 以及chromdriver 版本v0.24
pythonselenium自动化入门
适合最新chrome62 的 自动测试工具:robot framework 的 selenium chrome driver 2.33版本 。
基于Python+Selenium Web自动化实现的东方网期货交易所数据爬取及存储源码.zip基于Python+Selenium Web自动化实现的东方网期货交易所数据爬取及存储源码.zip基于Python+Selenium Web自动化实现的东方网期货交易所...
selenium chrome driver 100.0.4896.60