webtest01.jar 是打包好的jar包,与Selenium Webdriver 的jar包一起使用即可。(本人只用过2.48.2 和2.53.0这两个版本)
注:实际中myFirefoxDriver不仅可以在本地用,用RemoteWebdriver远程调用也是可以用的,反正是只需要那两个参数就可以。
反正我自己用是可以的。仅供参考,不提供技术支持,呃,后果自负。
代码样例:
-------------TestCase 1--------
import org.openqa.selenium.By
import org.openqa.selenium.WebDriver
import org.openqa.selenium.WebElement
import org.openqa.selenium.firefox.FirefoxDriver
import org.openqa.selenium.support.ui.ExpectedCondition
import org.openqa.selenium.support.ui.WebDriverWait
import org.openqa.selenium.OutputType
import org.apache.commons.io.FileUtils
import org.openqa.selenium.Keys
WebDriver driver = new FirefoxDriver()
try
{
driver.get("https://learnsoapui.wordpress.com") // Url to be opened
//下面两行将所需的地址和SessionID 保存起来。样例因为是在SoapUI中的两个Step,所以保存为了用例级别的属性,具体请根据自己的使用环境保存为系统参数或其他地方
testRunner.testCase.setPropertyValue( "DriverServer", driver.getCommandExecutor().getAddressOfRemoteServer().toString() )
testRunner.testCase.setPropertyValue( "CaseSession", driver.getSessionId().toString() )
log.info driver.getSessionId().toString()
WebElement element = driver.findElement(By.id("s"))
element.sendKeys("Assertion")
File f1 = driver.getScreenshotAs(OutputType.FILE)
FileUtils.copyFile(f1, new File("c:\\screenshot1.png")); // Location to save screenshot
element.submit()
}
catch(Exception e)
{
log.info "Exception encountered : " + e.message
}
-----------TestCase 2--------------
import webtest.myFirefoxDriver;
import org.openqa.selenium.By
import org.openqa.selenium.WebDriver
import org.openqa.selenium.WebElement
import org.openqa.selenium.firefox.FirefoxDriver
import org.openqa.selenium.JavascriptExecutor
//下面三行,取出保存的可用的浏览器的Webdriver Server的地址和SessionID,new一个Webdriver。
def driverserver = testRunner.testCase.getPropertyValue( "DriverServer" )
def caseSession = testRunner.testCase.getPropertyValue( "CaseSession" )
WebDriver driver = new myFirefoxDriver(driverserver,caseSession)
log.info (driver.getCommandExecutor().getAddressOfRemoteServer())
try
{
driver.findElement(By.linkText("Home")).click()// Url to be opened
driver.findElement(By.linkText("About Author")).click()// Url to be opened
log.info driver.getSessionId().toString()
log.info driver.getCapabilities()
((JavascriptExecutor)driver).executeScript("alert(\"hello,this is a alert!\")");
//driver.quit()
}
catch(Exception e)
{
log.info "Exception encountered : " + e.message
}
在SoapUI中使用的话:SoapUI中具体使用说名请参考:
http://blog.csdn.net/wwwqjpcom/article/details/51174664
http://blog.csdn.net/wwwqjpcom/article/details/51232302
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
Selenium Webdriver使用已打开的浏览器.zip (3个子文件)
webtest01.jar 3KB
myFirefoxDriver.java 5KB
readme.txt 3KB
共 3 条
- 1
wwwqjpcom
- 粉丝: 23
- 资源: 8
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
- 5
- 6
前往页