【发布时间】:2017-12-19 23:04:59
【问题描述】:
我是使用 selenium 的 Java 新手。如何根据以下要求编写更通用的代码?
测试用例:使用关键字搜索医生
- 访问 www.medinfi.com
- 选择地区 AECS,班加罗尔(地区输入应该是动态的,即它应该能够随时更改测试数据)
- 在第二个搜索框中输入搜索关键字“shai”,搜索医生/医院名称。 (搜索关键字应该是动态的)
- 根据预期输出数据集验证下拉列表中的输出
包 com.medinfi.code;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
public class MedinfiChallenge {
private WebDriver driver;
@BeforeClass(alwaysRun = true)
public void setUp() throws Exception
{
System.setProperty("webdriver.chrome.driver", "F:\\SeleniumProject\\Medinfi\\Driver\\chromedriver.exe");
driver = new ChromeDriver();
driver.get("http://www.medinfi.com/");
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
@Test
public void testMedinfi() throws Exception
{
driver.findElement(By.xpath("//*[@id='city-locality1']")).sendKeys("AECS Layout, Bengaluru");
driver.findElement(By.xpath("//*[@id='ip1_text1']")).sendKeys("Hospitals");
driver.findElement(By.xpath("//*[@id=\"searchIcon\"]")).click();
}
@AfterClass(alwaysRun = true)
public void tearDown() throws Exception
{
driver.quit();
}
}
【问题讨论】: