Selenium 2 (WebDriver)에서 매개 변수화하는 방법은 무엇입니까? 나는 Maven 플러그인으로 Eclipse를 사용하고 Selenium Webdriver에 대한 이전 경험이 없다. 그 때 나는 모든 것을 testNG와 JUnit에 대해 보여줍니다. Webdriver를 매개 변수화 할 수있는 방법이 있습니까?Selenium Webdriver에서 매개 변수화를 수행하는 방법은 무엇입니까?
답변
Apache 또는 Jexcel의 POI 소프트웨어를 사용할 수 있습니다.
아래 링크를 확인해보십시오. 파라미터 설정 내용을 보려면하는 동안 어떤 직업 중 하나지만, 내가 봤 이러한 링크를 발견 한텐 POI
http://viralpatel.net/blogs/java-read-write-excel-file-apache-poi/
과 내가 희망 http://www.youtube.com/watch?v=yOGGdv8eT80
JExcel 에 대한
는하는 데 도움이됩니다.
나는 Webdriver에 매개 변수를 전달하려고합니다. 그 두 가지 방법을 통해 수행 할 수 있습니다 Webdriver를 확장하고 생성자을
만들기 클래스는 통과하는 데 필요한 매개 변수를 가지고.
public class MyWebdriver extends Webdriver{ private String theParameter; public MyWebdriver(String parameter){ //... initialize the Webdriver //store the parameter theParameter = parameter }
이 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
}
}
내 제안은 매개 변수화 이외에도 많은 기능을 제공하는 테스트 프레임 워크 (TestNG 또는 Junit)를 사용하는 것입니다. 테스트 코드가 커지면 처음부터 프레임 워크를 설정하는 데 약간의 노력이 필요할 것입니다.
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()를 사용하십시오. 메인 클래스. 실행
@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
테스트 프레임 워크로 JUnit 또는 TestNG를 사용할 수 있습니다. 너는 무엇을 사용하고 싶니? 나는 TestNG를 선호한다. TestNG를 사용하는 경우 XML 파일을 만들어야합니다. testNG.xml 여기에서 TestNG의 @Parameters 주석을 사용하여 매개 변수화 할 데이터를 지정할 수 있습니다 (위의 코드 코드 –
내가 테스트 케이스를 제공하고있다을 그 도움이 될 수도 있습니다
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;
}}
/* 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
- 1. Selenium WebDriver에서 execute_async_script 사용하기
- 2. Selenium WebDriver에서 '.hover'Javascript 실행
- 3. C#을 사용하는 Selenium Webdriver에서 Excel을 사용하여 매개 변수화
- 4. WebDriver에서 Selenium setTimeout 명령이 무시됩니까?
- 5. Selenium Webdriver에서 속성 값 찾기
- 6. Selenium Webdriver에서 여러 창 처리하기
- 7. Selenium WebDriver에서 sendKeys()를 사용합니다.
- 8. WebDriver에서 Selenium 2.0 RC -htmlSuite를 실행하는 방법은 무엇입니까?
- 9. Selenium Webdriver에서 특정 Firefox 버전을 설정하는 방법은 무엇입니까?
- 10. Selenium/Webdriver에서 플랫폼 특정 키를 처리하는 가장 좋은 방법은 무엇입니까?
- 11. Selenium WebDriver에서 페이지 객체 (PageFactory)의 배열을 사용하는 방법은 무엇입니까?
- 12. Python 바인딩을 사용하여 Selenium WebDriver에서 데이터 기반 프레임 작업을 수행하는 방법은 무엇입니까?
- 13. 특정 유형의 매개 변수화를 허용하지 않는 스칼라
- 14. selenium webdriver에서 컨트롤을 새 창에 전달하는 방법
- 15. Selenium webdriver에서 파일의 입력을받는 방법 C#
- 16. Selenium Webdriver에서 명시 적으로 페이지로드 차단을 실행합니다.
- 17. PHP-Webdriver에서 Selenium 2의 프레임 간 전환
- 18. PHP를 사용하여 Selenium WebDriver에서 원격으로 파일 업로드하기
- 19. Selenium WebDriver에서 원시 로거를 얻는 방법
- 20. Selenium Webdriver에서 iframe을 찾을 수 없습니다. (java)
- 21. WebDriver에서 사용되는 AlertOverride 클래스는 무엇입니까?
- 22. Java를 사용하여 Selenium WebDriver에서 요소를 포커스하는 올바른 방법
- 23. 두 클래스의 매개 변수화를 한 클래스의 매개 변수화로 변환
- 24. WebDriver에서 브라우저 속도를 제어하는 Java가있는 메소드가 있습니까?
- 25. 파이썬에서 webdriver에서 Firefox 쿠키를 삭제하는 방법은 무엇입니까?
- 26. 셀레늄 webdriver에서 동적 프레임을 감지하는 방법은 무엇입니까?
- 27. Webdriver에서 selenium.isElementPresent의 대안은 무엇입니까
- 28. matplotlib : 데이터의 자연 시간 매개 변수화를 캡처하는 선의 색상 변경
- 29. Selenium WebDriver에서 브라우저 상태 표시 줄 텍스트를 읽는 방법
- 30. JUnit4를 사용하여 Selenium Webdriver에서 테스트 실패를 잡는 방법?
https://s3.amazonaws.com/cloud.teamdev.com/downloads/jexcel/docs/JExcel에서 언급 됨). -PGuide.html # AEN66 – lionxalmb