2017-07-13 11 views
0

私は、ページオブジェクトパターンでSerenity BDDを使用して、Flickrサイトのテスト自動化と書き込みテストを学習しています。イメージホバーでオーバーレイをテストするにはどうすればよいですか?

テストケース:メインメニューの[Explore]リンクをクリックすると、ページには「photo_title by author」というラベルの写真が含まれているはずです。画像上にマウスを置くと、このラベルがオーバーレイ表示されます。

これはExplorePage.classの一部です。テストを実行すると、私はNoSuchElementExceptionを取得します。

package serenityTest.pages; 

import net.serenitybdd.core.pages.PageObject; 
import net.thucydides.core.annotations.At; 
import org.openqa.selenium.WebDriver; 
import org.openqa.selenium.WebElement; 

import org.openqa.selenium.support.FindAll; 
import org.openqa.selenium.support.FindBy; 
import org.openqa.selenium.support.ui.ExpectedConditions; 
import org.openqa.selenium.support.ui.WebDriverWait; 

import java.util.List; 

import static serenityTest.helpers.Waiter.waitForJSandJQueryToLoad; 

@At("https://www.flickr.com/explore") 
public class ExplorePage extends PageObject { 

    @FindAll({@FindBy(css = ".title")}) 
    private List<WebElement> photoTitles; 

    @FindAll({@FindBy(css = ".attribution")}) 
    private List<WebElement> photoAuthors; 

    @FindAll({@FindBy(xpath = ".//div[@class='view photo-list-photo-view awake']")}) 
    private List<WebElement> photos; 

    public ExplorePage(WebDriver driver) { 
     super(driver); 
    } 

    public ExplorePage checkPhotoLabels() { 

     waitForJSandJQueryToLoad(); 
     WebDriverWait waitForPhotos = new WebDriverWait(getDriver(), 10); 
     waitForPhotos.until(ExpectedConditions.visibilityOfAllElements(photos)); 

     for (WebElement photo : photos) { 
      for (WebElement photoTitle : photoTitles) { 
       for (WebElement photoAuthor : photoAuthors) { 
        withAction().moveToElement(photo).perform(); 
        photoTitle.isDisplayed(); 
        photoAuthor.isDisplayed(); 
       } 
      } 
     } 
     return this; 
    } 
} 

多分私は間違った方法でテキストをテストしています。または、ロケータに問題があります(私はXPathを含む多くのバリエーションを試しました)。

助けてもらえますか?事前に感謝

答えて

0

ロジックに欠陥があります。写真と著者のタイトルとの間に1対1のマッピングがあります。

入れ子になったforループが正しくありません。使用する場合:

for (WebElement photo : photos) { 
    for (WebElement photoTitle : photoTitles) { 
     for (WebElement photoAuthor : photoAuthors) { 
      withAction().moveToElement(photo).perform(); 
      photoTitle.isDisplayed(); 
      photoAuthor.isDisplayed(); 
     } 
    } 
} 

各写真のすべての写真のタイトルは、各写真のすべての写真をチェックすることが必須です。

10枚の写真のためにこのようなあなたのループ機能は... forループ

|Photo#|Title#|Author#| 
|1  |1  |1  | <-- Author for-loop starts 
|1  |1  |2  | 
|1  |1  |... | 
|1  |1  |10  | 
|1  |2  |1  | <-- Title for-loop increment, Author for-loop restarts 
|1  |2  |2  | 
|1  |2  |3  | 
|1  |... |... | 
|1  |2  |10  | 
|1  |... |... | 
|1  |10 |10  | 
|2  |... |... | <-- Photo for-loop increment 
|3  |... |... | 

正しいは次のとおりです。また、

for(WebElement photo : photos) { 
    // Get the index of the photo in the list of photos 
    int index = photos.indexOf(photo); 
    // Get the corresponding title of the photo at index from the list of titles 
    WebElement title = photoTitles.get(index); 
    // Get the corresponding author of the photo at index from the list of authors 
    WebElement author = photoAuthors.get(index); 

    // Always build() actions in order to perform() 
    withAction().moveToElement(photo).build().perform(); 
    System.out.println("Photo Title is displayed for photo #" + index + "? " + title.isDisplayed()); 
    System.out.println("Photo Author is displayed for photo #" + index + "? " + author.isDisplayed()); 

} 

Actionsを使用した場合、エンドその連鎖したアクションを確認してください、 build().perform()であり、ただperform()ではありません。

関連する問題