Selenium webdriver WebDriver/TestNG:浏览器启动两次

Selenium webdriver WebDriver/TestNG:浏览器启动两次,selenium-webdriver,Selenium Webdriver,我是Webdriver的新手。我正在firefox浏览器中使用代理设置为我的应用程序实现一个数据驱动测试。不知何故,我的浏览器在执行时启动了两次。有人能帮我找出哪里出了问题吗 这是我的密码: import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import org.openqa.selenium.By; import org.openqa.seleni

我是Webdriver的新手。我正在firefox浏览器中使用代理设置为我的应用程序实现一个数据驱动测试。不知何故,我的浏览器在执行时启动了两次。有人能帮我找出哪里出了问题吗

这是我的密码:

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);
import java.io.FileInputStream;
导入java.io.FileNotFoundException;
导入java.io.IOException;
导入org.openqa.selenium.By;
导入org.openqa.selenium.WebDriver;
导入org.openqa.selenium.Proxy.ProxyType;
导入org.openqa.selenium.firefox.FirefoxDriver;
导入org.openqa.selenium.firefox.FirefoxProfile;
导入org.testng.Assert;
导入org.testng.annotations.AfterClass;
导入org.testng.annotations.Test;
导入org.testng.annotations.BeforeTest;
导入org.testng.annotations.postest;
进口jxl。*;
导入jxl.read.biff.BiffException;
公共类数据驱动的\u登录{
公共静态WebDriver ff=新的FirefoxDriver();
@试验
public void f()抛出biffeException、IOException、Throwable{
FileInputStream文件=新的FileInputStream(“C:\\Users\\user\\Desktop\\Datadriven.xls”);
工作簿w=Workbook.getWorkbook(文件);
表s=w.getSheet(0);

对于(int rows=1;rows,每当您实例化一个新的
WebDriver
,就会打开一个新的浏览器

因此,这一行:

publicstaticwebdriver ff=newfirefoxdriver();

这一行:

ff=新的FirefoxDriver(ffp)

两者都可以实例化它。我建议将第一行更改为:


publicstaticwebdriver ff;

您已经实例化了两次FirfoxDriver

替换

公共静态WebDriver ff=新的FirefoxDriver()

公共静态WebDriver-ff