Advertisement
fhumayun

Appium MobileDriver Selenium

Apr 10th, 2015
610
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.51 KB | None | 0 0
  1. package com.nativeapp.mobiledriver.page.mtv;
  2.  
  3. import java.util.List;
  4.  
  5. import org.apache.log4j.Logger;
  6. import org.openqa.selenium.By;
  7. import org.openqa.selenium.WebDriver;
  8. import org.openqa.selenium.WebElement;
  9.  
  10. import com.appium.driver.AppiumDriver;
  11. import com.appium.driver.annotation.AndroidFindBy;
  12. import com.appium.driver.annotation.IOSFindBy;
  13. import com.google.inject.Inject;
  14. import com.nativeapp.mobiledriver.page.PageWithProxy;
  15. import com.nativeapp.mobiledriver.page.exception.ViewNotFoundException;
  16. import com.nativeapp.mobiledriver.page.mtv.interf.IMTVSearchPage;
  17. import com.nativeapp.mobiledriver.wait.MobileWait;
  18. import com.nativeapp.tests.utils.ExpectedConditions;
  19. import com.selenium.element.impl.AppiumElement;
  20.  
  21. public class MTVHomePage extends PageWithProxy {
  22.  
  23. @IOSFindBy(xpath = "//UIAApplication[1]/UIAWindow[1]/UIACollectionView[1]")
  24. @AndroidFindBy(id = "content")
  25. private AppiumElement collectionView;
  26.  
  27. @IOSFindBy(xpath = "//UIAApplication[1]/UIAWindow[1]/UIAButton[2]")
  28. @AndroidFindBy(id = "search_button")
  29. private AppiumElement searchButton;
  30.  
  31. @IOSFindBy(xpath = "//UIAApplication[1]/UIAWindow[1]/UIAStaticText[@name='browse' or @name='BROWSE']")
  32. @AndroidFindBy(xpath = "//")
  33. private AppiumElement browseButton;
  34.  
  35. @IOSFindBy(xpath = "//UIAApplication[1]/UIAWindow[1]/UIACollectionView[1]/UIACollectionCell/UIAStaticText[contains(@name, 'live') or contains(@name, 'LIVE')]")
  36. @AndroidFindBy(xpath = "//")
  37. private AppiumElement liveVideo;
  38.  
  39. @IOSFindBy(xpath = "//UIAApplication[1]/UIAWindow[1]/UIAButton[1]")
  40. @AndroidFindBy(xpath = "//")
  41. private AppiumElement closePromoBtn;
  42.  
  43. @IOSFindBy(xpath = "//UIAApplication[1]/UIAWindow[1]/UIAImage[1]")
  44. @AndroidFindBy(xpath = "//")
  45. private AppiumElement promoImage;
  46.  
  47. private By settingsButton = By.xpath("//UIAApplication[1]/UIAWindow[1]/UIAButton");
  48.  
  49. private static final Logger LOGGER = Logger.getLogger(MTVHomePage.class);
  50.  
  51. private WebDriver driver;
  52.  
  53. @Inject
  54. private MTVLoginPage loginPage;
  55.  
  56. @Inject
  57. private IMTVSearchPage searchPage;
  58.  
  59. @Inject
  60. private MTVBrowsePage browsePage;
  61.  
  62. public MTVHomePage(WebDriver driver) {
  63. this.driver = driver;
  64. }
  65.  
  66. @Override
  67. public void checkPage() {
  68. new MobileWait(driver, 30).until(ExpectedConditions.isVisible(collectionView), ViewNotFoundException.class,
  69. "Home page is not loaded.");
  70. }
  71.  
  72. public MTVLoginPage openSettings() {
  73. List<WebElement> buttons = driver.findElements(settingsButton);
  74. buttons.get(buttons.size() - 1).click();
  75. loginPage.checkPage();
  76. return loginPage;
  77. }
  78.  
  79. public IMTVSearchPage openSearch() {
  80. searchPage.openSearchPage();
  81. return searchPage;
  82. }
  83.  
  84. public MTVBrowsePage openBrowsePage() {
  85. browseButton.click();
  86. return browsePage;
  87. }
  88. //.cells().staticText.withPredicate(\"name=='watch live'\")"
  89. public void openLiveVideo() {
  90. ((AppiumDriver)driver).findElement("target.frontMostApp().mainWindow().collectionViews()[0].cells().withPredicate(\"name=='2015 movie awards'\")");
  91. ((AppiumDriver)driver).findElement("target.frontMostApp().mainWindow().collectionViews()[0].cells()[\"watch live\"]").click();
  92. ((AppiumDriver)driver).findElements(".collectionViews()[0].cells()");
  93. ((AppiumDriver)driver).findElements("target.frontMostApp().mainWindow().collectionViews()[0].staticTexts()");
  94. System.out.println(driver.getPageSource());
  95. // liveVideo.click();
  96. }
  97.  
  98. public void closePromotionPopup() {
  99. if (promoImage.isDisplayed()) {
  100. LOGGER.info("Close promotion popup");
  101. closePromoBtn.click();
  102. }
  103. }
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement