2016-05-22 61 views
1

我計劃使用Array來測試Gmail登錄。您可能已經注意到,Gmail登錄首次驗證用戶名。我要聲明,我想保持數組變量使用Java在Selenium WebDriver中實現數組

{ 「#[email protected]」, 「[email protected]」, 「[email protected]」}

我很困惑的一些事情是如何一次發送1個名稱並驗證它。

例子:

f.findElement(By.id("EMail")).sendKeys("[email protected]"); 
    //code below to get sendKeys value 
    WebElement w= f.findElement(By.id("Email")); 
    String emailID= w.getAttribute("value"); 
    System.out.println("Email id used " + emailID); 
    if((emailID).contains(" # $")){ 
     System.out.println("Invalid character"); 
    } 

混亂:如何實現一次發送1名和驗證無效字符和它匹配時[email protected]然後打印正確的電子郵件地址?

回答

1

我會建議使用Data Provider如果你沿着testng或者用於junit線工作給予一個嘗試junit-dataprovider

從例如從鏈接引用:

@Test(dataProvider = "<nameYourData>") 
public void yourMethod(<Data returned from dataProvider>) { 
....// do whatever you want to test (in your case the method stated) 
} 

@DataProvider 
public Object[][] getData() 
{ 
    //Rows - Number of times your test has to be repeated. 
    //Columns - Number of parameters in test data. 
    Object[][] data = new Object[3][2]; 
    // 1st row 
    data[0][0] ="sampleuser1"; 
    // 2nd row 
    data[1][0] ="testuser2"; 
    return data; 
} 
相關問題