2016-11-09 8 views
0

셀레늄으로 자동 웹 사이트를 테스트하는 프로젝트를 진행 중입니다. 이것은 내가 실행하려면 내 주요 클래스 :다른 클래스의 클래스 호출하기

package Login; 

import static org.junit.Assert.assertTrue; 

import java.util.concurrent.TimeUnit; 

import org.openqa.selenium.By; 
import org.openqa.selenium.WebDriver; 
import org.openqa.selenium.WebElement; 
import org.openqa.selenium.chrome.ChromeDriver; 
import org.openqa.selenium.firefox.FirefoxDriver; 
import org.openqa.selenium.ie.InternetExplorerDriver; 
import org.openqa.selenium.support.ui.ExpectedConditions; 
import org.openqa.selenium.support.ui.WebDriverWait; 
import org.testng.annotations.Parameters; 
import org.testng.annotations.Test; 

public class Test{ 

WebDriver driver; 
String baseUrl; 

private StringBuffer verificationErrors = new StringBuffer(); 

@Test 
@Parameters("browser") 
public void LoginDebiteurVerkeerdPage(String browserName) { 

    if(browserName.equalsIgnoreCase("firefox")) 
    { 
     System.setProperty("webdriver.gecko.driver","C:\\Users\\cursus\\Downloads\\geckodriver.exe"); 
     driver=new FirefoxDriver(); 
    } 
    else if(browserName.equalsIgnoreCase("chrome")) 
    { 
     System.setProperty("webdriver.chrome.driver", "C:\\Users\\cursus\\Downloads\\chromedriver.exe"); 
     driver=new ChromeDriver(); 
    } 
    else if(browserName.equalsIgnoreCase("IE")) 
    { 
     System.setProperty("webdriver.ie.driver", "C:\\Users\\cursus\\Downloads\\IEDriverServer_x64_2.53.1\\IEDriverServer.exe"); 
     driver=new InternetExplorerDriver(); 
    } 

    driver.manage().window().maximize(); 
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); 
    baseUrl = "https://www.l.nl/"; 
    driver.get(baseUrl + "/"); 

    // Testscases 
    Here i wanna invoke a few testcases that are in other classes. 

    // For example: LoginLogout (class LoginLogout) 
    // For example: LoginWrongusername (class LoginWrongusername) 
    // For example: LoginWrongpassword (class Loginwrongpassword) 

    driver.close(); 
} 

} 

나는 그것이 구성 및 유지 보수됩니다 있도록 다른 클래스의을 testcases을 갖고 싶어.

"테스트"클래스에서 이러한 클래스 (테스트 사례)를 어떻게 호출 할 수 있습니까?

덕분에, 피에트

답변

0

당신은 당신이 테스트에서 실행하고 거기에 모든 시나리오를 추가 할 이러한 클래스의 내부의 정적 메서드를 정의 할 수 있습니다. 예를 들어. 테스트 클래스에서

public class LoginLogout(){ 

    public static executeScenarios(Driver driver){ 
     //your code here 
    } 
} 

:

에도
LoginLogout.executeScenarios(driver); 
LoginWrongusername.executeScenarios(driver); 
... 

당신이 시나리오의 모든 당신의 클래스는 드라이버가 초기화되는 일반적인 클래스에서 연장 할 수 있고, 당신은 단지 브라우저를 통과해야 방법에.

희망 하시겠습니까?