Java 如何在 selenium Web 驱动程序中自动化 SOAP UI
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30732190/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to automate SOAP UI in selenium Web driver
提问by prem
We have an application where we have a customer Module. Here it will displayed below Field Customer Name Address 1 Address 2 City State
我们有一个应用程序,其中有一个客户模块。在这里,它将显示在字段客户名称地址 1 地址 2 城市状态下方
To Fetch the records in customer module in a Web page, We need to give the input data in soap UI, once after execute from soap UI, A new customer will created and display in the UI Web page. How can we automate this process through selenium Web driver.
要在网页中获取客户模块中的记录,我们需要在soap UI 中提供输入数据,一旦从soap UI 执行后,将创建一个新客户并显示在UI 网页中。我们如何通过 selenium Web 驱动程序自动化这个过程。
回答by SiKing
So the most obvious, and perhaps the easiest way, to get Selenium and SoapUI to cooperate is:
因此,让 Selenium 和 SoapUI 合作的最明显,也许也是最简单的方法是:
- Install SoapUI.
- Download Selenium (you need the selenium-server-standalone-2.*.jar)
and drop it into your SoapUI installation (into
%SOAPUI_HOME%\bin\ext
). - Fire up SoapUI; start a new Project; create a new test case; add a
new Groovy step; copy-paste the sample codeinto the step. I made a
few modification: drop the
package
line, drop theclass Selenium2Example
andvoid main
lines along with the closing brackets, and change theSystem.out.println
tolog.info
. My final (full) test code is below. - Click Play. You should see Firefox starting up, navigating to Google, and afterwards you should see the SoapUI log entries.
- 安装 SoapUI。
- 下载 Selenium(您需要 selenium-server-standalone-2.*.jar)并将其放入您的 SoapUI 安装(进入
%SOAPUI_HOME%\bin\ext
)。 - 启动 SoapUI;开始一个新项目;创建一个新的测试用例;添加一个新的 Groovy 步骤;将示例代码复制粘贴到步骤中。我做了一些修改:删除
package
线时,放置class Selenium2Example
并void main
线,或与右括号一起,并更改System.out.println
到log.info
。我的最终(完整)测试代码如下。 - 单击播放。您应该会看到 Firefox 启动,导航到 Google,然后您应该会看到 SoapUI 日志条目。
sample code:
示例代码:
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
// Create a new instance of the Firefox driver
// Notice that the remainder of the code relies on the interface,
// not the implementation.
WebDriver driver = new FirefoxDriver()
// And now use this to visit Google
driver.get("http://www.google.com")
// Find the text input element by its name
WebElement element = driver.findElement(By.name("q"))
// Enter something to search for
element.sendKeys("Cheese!")
// Now submit the form. WebDriver will find the form for us from the element
element.submit()
// Check the title of the page
log.info("Page title is: " + driver.getTitle())
// Google's search is rendered dynamically with JavaScript.
// Wait for the page to load, timeout after 10 seconds
(new WebDriverWait(driver, 10)).until(new ExpectedCondition() {
public Boolean apply(WebDriver d) {
return d.getTitle().toLowerCase().startsWith("cheese!")
}
});
// Should see: "cheese! - Google Search"
log.info("Page title is: " + driver.getTitle())
//Close the browser
driver.quit()
This answer is a copy-paste from my blog.
这个答案是从我的博客复制粘贴的。