2012-05-01 3 views

답변

0

Apache 또는 Jexcel의 POI 소프트웨어를 사용할 수 있습니다.

아래 링크를 확인해보십시오. 파라미터 설정 내용을 보려면하는 동안 어떤 직업 중 하나지만, 내가 봤 이러한 링크를 발견 한텐 POI

http://viralpatel.net/blogs/java-read-write-excel-file-apache-poi/

과 내가 희망 http://www.youtube.com/watch?v=yOGGdv8eT80

JExcel 에 대한

하는 데 도움이됩니다.

+0

https://s3.amazonaws.com/cloud.teamdev.com/downloads/jexcel/docs/JExcel에서 언급 됨). -PGuide.html # AEN66 – lionxalmb

0

나는 Webdriver에 매개 변수를 전달하려고합니다. 그 두 가지 방법을 통해 수행 할 수 있습니다 Webdriver를 확장하고 생성자을

  1. 만들기 클래스는 통과하는 데 필요한 매개 변수를 가지고.

    public class MyWebdriver extends Webdriver{ 
         private String theParameter; 
    
        public MyWebdriver(String parameter){ 
         //... initialize the Webdriver 
    
         //store the parameter 
         theParameter = parameter 
    } 
    
  2. 이 WebDriver를 예를 포함 자신의 래퍼를 확인하십시오 : 당신이 webdriver에서 모든 (필요한) 함수를 오버라이드 (override)/구현해야하기 때문에, 이것은 하드 방법이다. 그것은 쉬운 (- ier)입니다. 예를 들면 : 내 자신의 테스트에서 Webdriver에게 테스트 할 환경을 알려줘야합니다.

    public class Environment{ 
        private String baseUrl; 
        public enum NameOfEnvironment {DEV, ACC} 
        private NameOfEnvironment environment; 
    
        public Environment(NameOfEnvironment envName){ 
        environment = envName; 
        } 
    
        public String getBaseUrl(){ 
         switch (environment){ 
         case DEV: baseUrl = "https://10.10.11.12:9080/test/"; 
            break; 
         case ACC: baseUrl = "https://acceptance.our-official-site.com"; 
            break; 
         } 
        return baseUrl; 
        } 
    } 
    

후, 나는 이런 식으로 초기화 내 자신의 WebDriver 래퍼, 한 :

public class TestUI{ 
     private Webdriver driver; 
     private Environment env; 

    public TestUI(Environment e){ 
     this.env = e; 
     driver = new FirefoxDriver; 
     driver.get(env.getBaseUrl()); 
    } 
} 

그리고 테스트를 :

그래서 환경에 대한 내 자신의 클래스를 생성
public class TestCases{ 

    public static final Environment USED_ENVIRONMENT = new Environment(Environment.NameOfEnvironment.ACC); 

@Test 
public void testSomething(){ 
    testUI test = new testUI(USED_ENVIRONMENT); 
    //.. further steps 
} 
} 
0

내 제안은 매개 변수화 이외에도 많은 기능을 제공하는 테스트 프레임 워크 (TestNG 또는 Junit)를 사용하는 것입니다. 테스트 코드가 커지면 처음부터 프레임 워크를 설정하는 데 약간의 노력이 필요할 것입니다.

0
public void property(){ 
    try { 

     File file = new File("login.properties"); 
     FileInputStream fileInput = new FileInputStream(file); 
     Properties properties = new Properties(); 
     properties.load(fileInput); 
     fileInput.close(); 

     Enumeration enuKeys = properties.keys(); 
     while (enuKeys.hasMoreElements()) { 
      String key = (String) enuKeys.nextElement(); 
      String value = properties.getProperty(key); 
      driver.findElement(By.id(key)).sendKeys(value); 
      System.out.println(key + ": " + value); 
     } 
    } catch (FileNotFoundException e) { 
     e.printStackTrace(); 
    } catch (IOException e) { 
     e.printStackTrace(); 
    } 
} 

값을 전달하려면 property()를 사용하십시오. 메인 클래스. 실행

0
@Parameters({ "first-name" }) 
@Test 
public void testSingleString(String firstName) { 
    System.out.println("Invoked testString " + firstName); 
    assert "Cedric".equals(firstName); 
} 

이 코드에서는 Java 메소드의 firstName 매개 변수에 first-name이라는 XML 매개 변수 값을 수신하도록 지정합니다. 이 XML 매개 변수는 testng.xml에 정의되어 < - ... ->

더 자세한 내용은 다음 방문하시기 바랍니다 : 여기 http://testng.org/doc/documentation-main.html#parameters

+0

테스트 프레임 워크로 JUnit 또는 TestNG를 사용할 수 있습니다. 너는 무엇을 사용하고 싶니? 나는 TestNG를 선호한다. TestNG를 사용하는 경우 XML 파일을 만들어야합니다. testNG.xml 여기에서 TestNG의 @Parameters 주석을 사용하여 매개 변수화 할 데이터를 지정할 수 있습니다 (위의 코드 코드 –

0

내가 테스트 케이스를 제공하고있다을 그 도움이 될 수도 있습니다

package pac1; 
import org.openqa.selenium.By; 
import org.openqa.selenium.WebDriver; 
import org.openqa.selenium.WebElement; 
import org.openqa.selenium.support.ui.Wait; 
import java.io.File; 
import javax.xml.parsers.DocumentBuilder; 
    import javax.xml.parsers.DocumentBuilderFactory; 
import org.w3c.dom.*; 

public class test extends sut { 
static WebDriver driver; 
static Wait<WebDriver> wait; 
    public static boolean run(WebDriver driverArg, Wait<WebDriver> waitArg) 
{ 
    driver = driverArg; 
    wait = waitArg; 
    // Run all the methods and return false if any fails 
    return (test1()); 
        } 
    private static boolean test1() 
    { 



    driver.get("https://accounts.google.com"); 

    try { 
     File file = new File("emaildata.xml"); //file location should be specified correctly put your xml in the same folder of the source code. 
     // Prepare XML 
     DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); 
     DocumentBuilder db = dbf.newDocumentBuilder(); 
     Document document = db.parse(file); 
     document.getDocumentElement().normalize(); 
     NodeList emailNodeElementList = document.getElementsByTagName("test");//test is the name of the child tag 
     for(int j=0;j<emailNodeElementList.getLength(); j++)//loop for the multiple data 
    { 
     String client = "The username or password you entered is incorrect. ?"; 
     Element emailNodeElement = (Element)emailNodeElementList.item(j); 
     NodeList details = emailNodeElement.getChildNodes(); 
     String emailAddress=((Node) details.item(0)).getNodeValue(); 
     System.out.println("email :" + emailAddress);//it just prints which email is going to be parsed 
     WebElement element = driver.findElement(By.cssSelector("body")); 
      boolean feedBack = driver.findElement(By.cssSelector("body")).getText().contains(client); 
      boolean feedbackVisible = element.isDisplayed(); 


    WebElement e1 = driver.findElement(By.id("Email"));//getting the location from the web 
    e1.sendKeys(emailAddress);//sending keys to the server 
    WebElement e3 = driver.findElement(By.id("signIn")); 
    e3.click(); 


    if(feedBack==true){ 
     System.out.println(client+ "is present"); 
     if(feedbackVisible==true){ 
      System.out.println(client+ "is visible"); 
     } 
     else{ 
      System.out.println(client+ "is not visible"); 
     } 

    } 
    else{ 
     System.out.println(client+ "is not present"); 

    } 
    } 
    } 
catch (Exception e) {e.printStackTrace();} 

    return true; 
    }} 
0
/* You can pass parameters by creating two classes. 
The first class, which you can call Main Class, will be public static void. 
It will contain code such as: 
*/ 
WebDriver driver = new FirefoxDriver(); 
driver.get("https://www.google.com"); 
Parameters id = new Parameters(); //this is referring to second class 
driver.findElement(By.name("q")).sendKeys(id.x); 
//**************************************************************** 
//this is the second class [separate page] - here you can declare int or string varibale as public [so you can share them with other class while defining them] - 
//when you make this class - don't need to add public static void 

public String x = "username" 
//if you look at the first page, I'm passing this string in the main script 
관련 문제