2016-11-09 14 views
0

私はセレンで自動ウェブサイトをテストするプロジェクトに取り組んでいます。これは私が実行したい私のメインクラスです:別のクラスのInvokeクラス

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(); 
} 

} 

私はそれを構造化し、保守しますので、他のクラスのテストケースを持っていると思います。

"テスト"クラスでどのようにこれらのクラス(私のテストケース)を呼び出すことができますか?

おかげで、 ピエト

答えて

0

あなたがテストで実行し、その上で全てのシナリオを追加したいこれらのクラスのいずれかの内部でいくつかの静的メソッドを定義することができます。例えば。あなたのテストクラスで

public class LoginLogout(){ 

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

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

でもあなたがシナリオを持つすべてのあなたのクラスは、ドライバが初期化され、共通のクラスから拡張し、あなただけのブラウザを渡すために持っていることを作ることができます方法に。

希望すると助かります