【发布时间】:2015-06-19 11:51:32
【问题描述】:
我在 Selenium 上进行了自动测试。这个测试我将从 JMeter 开始,为 10、20、50 多个用户进行负载测试。我该做什么。我创建了一个属性文件(配置文件)并将 URL、登录名、密码放在那里。 所以我做了一个循环,把这段代码放在那里我将启动我的浏览器、登录、访问链接、注销和退出。 这是我在属性文件中的内容:
URL:http://barracuda-qa.ko.kodak.com/d2l/faces/Login.jsp
Login:Test1, Test2, Tesr3
Password:Abc123
这是我的 Java 代码:
public class TestMultiply extends TestCase {
File file = new File("C:/barracuda/prop.properties");
private FileInputStream fileInput = null;
private WebDriver driver;
public FirefoxProfile profile = new FirefoxProfile();
public int index=0;
public TestMultiply(){}
public TestMultiply(String testName){
super(testName);
}
@Before
public void setUp() throws Exception {
super.setUp();
}
@Test
public void testTestLoad() throws InterruptedException {
try {
fileInput = new FileInputStream(file);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
Properties prop = new Properties();
try {
prop.load(fileInput);
} catch (IOException e) {
e.printStackTrace();
}
driver = new FirefoxDriver();
for (int i= 0; i<prop.getProperty("Login").length(); i++){
//String login = prop.getProperty("Login"+i);
Thread t1 = new Thread(new Runnable() {
@Override
public void run() {
driver = new FirefoxDriver();
driver.get(prop.getProperty("URL"));
driver.findElement(By.id("loginForm:authLogin")).sendKeys(login);
driver.findElement(By.id("loginForm:authPassword")).sendKeys(prop.getProperty(key));
driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
driver.findElement(By.id("loginForm:btnLogin")).click();
driver.manage().timeouts().implicitlyWait(2000, TimeUnit.SECONDS);
driver.findElement(By.id("settingsLink"));
driver.manage().timeouts().implicitlyWait(2000, TimeUnit.SECONDS);
driver.findElement(By.xpath("//a[@class='logout']")).click();
driver.quit();
}
}); t1.start(); Thread.sleep(10000);
}
}
@After
public void tearDown() throws Exception {
super.tearDown();
}
}
我需要为多登录创建一个循环。它应该在登录字段中循环粘贴我的属性文件中的一个登录名,所有用户使用相同的密码。 例如我的属性文件有结构:
URL:http://barracuda-qa.ko.kodak.com/d2l/faces/Login.jsp
Login:Test1, Test2
Password:Abc123
所以我们应该启动浏览器 2 次,它会以 Test1 - Abc123 和 Test2 - Abc123 登录。
【问题讨论】:
标签: java selenium junit webdriver automated-tests