我是Webdriver的新手。我使用代理設置在Firefox瀏覽器中爲我的應用程序實施數據驅動測試。不知怎的,我的瀏覽器在執行時啓動了兩次。是否有人可以幫助我在什麼地方出了錯WebDriver/TestNG:瀏覽器啓動兩次
這裏是我的代碼:
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.Proxy.ProxyType;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.AfterTest;
import jxl.*;
import jxl.read.biff.BiffException;
public class Datadriven_login {
public static WebDriver ff = new FirefoxDriver();
@Test
public void f() throws BiffException, IOException, Throwable {
FileInputStream file = new FileInputStream ("C:\\Users\\user\\Desktop\\Datadriven.xls");
Workbook w = Workbook.getWorkbook(file);
Sheet s = w.getSheet(0);
for(int rows =1 ; rows <= s.getRows(); rows++)
{
FirefoxProfile ffp = new FirefoxProfile();
ffp.setPreference("network.proxy.type", ProxyType.AUTODETECT.ordinal());
ff = new FirefoxDriver(ffp);
ff.get("https://xyz.do");
String username = s.getCell(0, rows).getContents();
ff.findElement(By.xpath("//*[@id='TableMain']/tbody/tr/td/form/table/tbody/tr[4]/td/table/tbody/tr/td/table/tbody/tr[1]/td[2]/input")).sendKeys(username);
String password = s.getCell(1, rows).getContents();
System.out.println(rows + "-" + "-" + username + "/"+ password);
ff.findElement(By.xpath("//*[@id='TableMain']/tbody/tr/td/form/table/tbody/tr[4]/td/table/tbody/tr/td/table/tbody/tr[2]/td[2]/input")).sendKeys(password);
感謝您的幫助!