2014-04-08 4 views
1

Webdriver를 처음 사용했습니다. 파이어 폭스 브라우저에서 프록시 설정을 사용하여 애플리케이션에 대한 데이터 테스트를 구현했다. 어떻게 든 내 브라우저는 실행하는 동안 두 번 실행됩니다. 사람이 무엇이 잘못되었는지에 좀 도와 주실 래요 여기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); 

감사합니다!

답변

1

WebDriver을 인스턴스화 할 때마다 새 브라우저가 열립니다. 따라서

이 라인 :

public static WebDriver ff = new FirefoxDriver();

이 라인 : ff = new FirefoxDriver(ffp)

모두 인스턴스화. 나는에 첫 번째 라인을 변경하는 것이 좋습니다 : 당신은 두 번 FirfoxDriver를 인스턴스화 한

public static WebDriver ff;

0

.

) (

공용 static WebDriver의 FF = 새로운 FirefoxDriver 바꾸기;

공용 static WebDriver의 FF와;

관련 문제