我在参数化搜索功能方面遇到了问题,实际上我需要用不同的关键字来提供我的测试:
这是我的课:
package Distributed;
import static org.junit.Assert.assertEquals;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import org.json.JSONException;
import org.openqa.selenium.By;
import org.openqa.selenium.Platform;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
public class TSKZ63700J {
WebDriver driver ;
String BaseURL , winURL , TestURL, androidURL ;
String ApiURL = "http://frstmwarwebsrv.orsyptst.com:9000/duobject? searchString=TSK(Z63700J)(000)(Z63700JU10)(000)&filtercheck=nameSWF&p.index=0&p.size=8";
jsonobject json;
String res;
/**
* Initiate connection
*/
@BeforeTest
public void setup () throws MalformedURLException
{
TestURL = "http://frstmwarwebsrv.orsyptst.com:9000";
BaseURL = "http://10.2.128.126";
winURL = "http://10.2.128.120:5556/wd/hub";
androidURL ="http://10.2.128.120:5555/wd/hub";
DesiredCapabilities wincap = DesiredCapabilities.firefox();
wincap.setBrowserName("firefox");
wincap.setPlatform(Platform.WINDOWS);
driver = new RemoteWebDriver ( new URL ( winURL ), wincap) ;
}
@Test
public void compareresults () throws IOException, JSONException {
srch ("TSK(Z63700J)(000)(Z63700JU10)(000)");
//assertEquals(jsonobject.getresults(ApiURL), "TSK(ZRM760J)(000)(ZRM760JU00)(000)");
assertEquals(jsonobject.getresults(ApiURL), res);
}
private void srch(String keyword) {
driver.get(TestURL);
WebElement input1 = driver.findElement(By.xpath("html/body/div[1]/div/div[2]/div/form/input[1]"));
input1.sendKeys("guest");
WebElement input2 = driver.findElement(By.xpath("html/body/div[1]/div/div[2]/div/form/input[2]"));
input2.sendKeys("guest");
WebElement btn = driver.findElement(By.xpath("html/body/div[1]/div/div[2]/div/form/button"));
btn.click();
WebElement w1 = driver.findElement(By.xpath("html/body/header/nav/div[1]/form/div/input"));
w1.sendKeys( "TSK(Z63700J)(000)(Z63700JU10)(000)");
WebElement w2 = driver.findElement(By.xpath("(//button[@type='button'])[2]"));
w2.click();
WebDriverWait wait= new WebDriverWait(driver,10 );
wait.until(ExpectedConditions.visibilityOfElementLocated(By.linkText("TSK(Z63700J)(000)(Z63700JU10)(000)")));
WebElement result = driver.findElement(By.linkText("TSK(Z63700J)(000)(Z63700JU10)(000)"));
// res = (result.toString()).substring(80,100);
res =result.getText();
}
private void quitTest() {
driver.quit();
}
@AfterTest
public void aftertest ()
{
quitTest();
}
}
我想做的是:
首先参数化搜索功能,我想我必须在搜索功能内的 SendKeys 级别执行此操作,但我不确定如何使用 Testng 执行此操作。
其次,我还希望参数化 APIURL。
提前感谢您的建议。
我做了以下事情:
@Parameters({"keyword" , })
@Test
private void srch(String keyword ) {
driver.get(TestURL);
WebElement input1 = driver.findElement(By.xpath("html/body/div[1]/div/div[2]/div/form/input[1]"));
input1.sendKeys("guest");
WebElement input2 = driver.findElement(By.xpath("html/body/div[1]/div/div[2]/div/form/input[2]"));
input2.sendKeys("guest");
WebElement btn = driver.findElement(By.xpath("html/body/div[1]/div/div[2]/div/form/button"));
btn.click();
WebElement w1 = driver.findElement(By.xpath("html/body/header/nav/div[1]/form/div/input"));
w1.sendKeys(keyword);
WebElement w2 = driver.findElement(By.xpath("(//button[@type='button'])[2]"));
w2.click();
}
然后更改了testng.xml:
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<test name="Search">
<parameter name="keyword" value="tsk" />
<parameter name="keyword" value="40" />
<parameter name="keyword" value="30" />
<parameter name="keyword" value="A" />
<parameter name="keyword" value="TSK(SAW" />
<parameter name="keyword" value="TSK(TTA010ON3" />
<parameter name="keyword" value="TSK(ARS090J)(000)(ARS090JN30)(000)" />
<parameter name="keyword" value="TSK(Z63700J)(000)(Z63700JU10)(000)" />
<parameter name="keyword" value="BAQ703J" />
<parameter name="keyword" value="BAQ703" />
<parameter name="keyword" value="CPE800J" />
<parameter name="keyword" value="NOT700J" />
<parameter name="keyword" value="ZWE010JU" />
<parameter name="keyword" value="ANF010JU0" />
<parameter name="keyword" value="TTA010ON3" />
<parameter name="keyword" value="BEN700JU40" />
<parameter name="keyword" value="NOT700JNA5" />
<parameter name="keyword" value="31" />
<parameter name="keyword" value="LBEN00733_GLOBAL" />
<parameter name="keyword" value="LBEN00733" />
<parameter name="keyword" value="TSK(ZTA010OU05)(000)" />
<parameter name="keyword" value="CRM :" />
<parameter name="keyword" value="TSK(CRM025JU50)(000)" />
<parameter name="keyword" value="TSK(ARS090J)(000)(ARS090JN30)(000)" />
<parameter name="keyword" value="TSK(Z63700J)(000)(Z63700JU10)(000)" />
<parameter name="keyword" value="AFF720J" />
<parameter name="keyword" value="SSCC depuis Gold" />
<parameter name="keyword" value="CPE170JR10" />
<parameter name="keyword" value="Uproc Dist: Detection R:\\sysapp\\data\\CPE\\CPE\\wrk\\SSCC_FPLP" />
<parameter name="keyword" value="Trailer: contournement sur le pb de la TVA" />
<parameter name="keyword" value="AA" />
<parameter name="keyword" value="49" />
<parameter name="keyword" value="Internal Activities" />
<parameter name="keyword" value="().-_ @[]" />
<parameter name="keyword" value="Integration ZCRMI120 01" />
<classes>
<class name="Distributed.Search" />
</classes>
</test>
</suite>
但是,当我运行时只考虑最后一个参数:Integration ZCRMI120 01
谢谢齐德