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
- 1
- 2
- 3
- 4
- 5
- 6
前往页