Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.mtvi.dte.tests.player.services.videoplayer.api;
- import com.appium.driver.AppiumDriver;
- import com.common.exception.UnimplementedMethodException;
- import com.common.wait.FluentWait;
- import com.common.wait.Function;
- import com.common.wait.Sleeper;
- import com.mtvi.dte.tests.player.services.exception.PlayerToolbarException;
- import com.mtvi.dte.tests.player.services.exception.VideoNotLoadedException;
- import com.mtvi.dte.tests.player.services.videoplayer.constants.Operators;
- import com.mtvi.dte.tests.player.services.videoplayer.constants.PlayerPatternConstants;
- import com.mtvi.dte.tests.player.services.videoplayer.constants.PlayerSplitterConstants;
- import com.mtvi.dte.tests.player.services.videoplayer.constants.PlayerTimeConstants;
- import com.mtvi.dte.tests.player.services.videoplayer.element.IPlayerElement;
- import com.mtvi.dte.tests.player.services.videoplayer.util.PlayerUtils;
- import org.apache.log4j.Logger;
- import org.openqa.selenium.Dimension;
- import org.openqa.selenium.NotFoundException;
- import org.openqa.selenium.WebDriver;
- import org.openqa.selenium.WebElement;
- import java.lang.reflect.UndeclaredThrowableException;
- import java.util.concurrent.TimeUnit;
- public class MobileVideoPlayer extends AbstractPlayer {
- private static final Logger LOGGER = Logger.getLogger(MobileVideoPlayer.class);
- private IPlayerElement loadPlayerButton;
- private IPlayerElement playPauseButton;
- private IPlayerElement adView;
- private IPlayerElement closedCaptionsButton;
- private IPlayerElement fullScreenButton;
- private IPlayerElement bcVideoView;
- private IPlayerElement currentTime;
- private IPlayerElement endTime;
- private IPlayerElement spinner;
- private IPlayerElement prerollAdSpinner;
- private IPlayerElement scrubber;
- private IPlayerElement rewindButton;
- private IPlayerElement overlay;
- private IPlayerElement prepareVideoButton;
- private IPlayerElement prepareVideoField;
- private IPlayerElement configureVideoButton;
- private IPlayerElement configureVideoField;
- private IPlayerElement loadVideoButton;
- private IPlayerElement loadVideoField;
- private IPlayerElement loadVideoPlaylistButton;
- private IPlayerElement loadVideoPlaylistField;
- private IPlayerElement mediaApiTokenField;
- private IPlayerElement mrssToggle;
- private IPlayerElement chromelessAdsToggle;
- private IPlayerElement chromelessReportingToggle;
- private IPlayerElement chromelessClosedCaptonsToggle;
- private IPlayerElement chromelessPlayPauseButton;
- private IPlayerElement resetContentButton;
- private IPlayerElement saveStateButton;
- private IPlayerElement loadStateButton;
- private IPlayerElement liveStatus;
- private IPlayerElement adRemainTime;
- private IPlayerElement adPlayPauseButton;
- private IPlayerElement adFullScreenButton;
- private IPlayerElement adLearnMoreButton;
- private IPlayerElement adClosedCaptionsButton;
- public MobileVideoPlayer(WebDriver driver) {
- super(driver);
- }
- /**
- * Get current time from video
- *
- */
- @Override
- public double getCurrentTimeInSec() {
- String currentTimeValue = currentTime.getText();
- if (currentTimeValue.matches(PlayerPatternConstants.IOS_TIME_PATTERN)) {
- currentTimeValue = currentTimeValue.split(PlayerSplitterConstants.SLASH_SPLITTER)[0];
- }
- return PlayerUtils.convertStringTimeToDouble(currentTimeValue);
- }
- /**
- * Get end time from video
- *
- */
- @Override
- public double getEndTimeInSec() {
- if (null == endTime) {
- return PlayerUtils.convertStringTimeToDouble(currentTime.getText().split(PlayerSplitterConstants.SLASH_SPLITTER)[1]);
- }
- String endTimeValue = endTime.getText();
- return PlayerUtils.convertStringTimeToDouble(endTimeValue);
- }
- /**
- * Get Remain time from Ad
- *
- */
- public double getAdRemainTime() {
- String adTimeValue = adRemainTime.getText();
- return PlayerUtils.convertStringTimeToDouble(adTimeValue);
- }
- /**
- * Load player from initial screen
- *
- */
- public void loadPlayer() {
- LOGGER.info("Loading player");
- loadPlayerButton.click();
- }
- /**
- * Open player toolbar
- *
- */
- @Override
- public void openPlayerToolbar() {
- LOGGER.info("Opening toolbar");
- waitForPlayerToolbarNotVisible(PlayerTimeConstants.SHORT_TIME_OUT);
- bcVideoView.click();
- }
- /**
- * Open player toolbar for Ad
- *
- */
- public void openAdPlayerToolbar() {
- LOGGER.info("Opening toolbar");
- waitForAdPlayerToolbarNotVisible(PlayerTimeConstants.SHORT_TIME_OUT);
- bcVideoView.click();
- }
- /**
- * Play video in player
- *
- */
- @Override
- public void playVideo() {
- LOGGER.info("Playing video");
- openPlayerToolbar();
- playPauseButton.click();
- }
- /**
- * Pause video in player
- *
- */
- @Override
- public void pauseVideo() {
- LOGGER.info("Pausing video");
- openPlayerToolbar();
- playPauseButton.click();
- }
- /**
- * Toggle Closed Captions for video
- *
- */
- @Override
- public void toggleClosedCaptions() {
- LOGGER.info("Toggle Closed Captions");
- openPlayerToolbar();
- closedCaptionsButton.click();
- }
- /**
- * Open Full Screen for video
- *
- * @throws RuntimeException
- *
- */
- @Override
- public void openFullScreen() {
- if (!isFullScreen()) {
- LOGGER.info("Open full screen mode in video player...");
- openPlayerToolbar();
- fullScreenButton.click();
- }
- if (!isFullScreen()) {
- throw new RuntimeException("Fullscreen is not opened");
- }
- }
- /**
- *
- * Close Full Screen for video
- *
- * @throws RuntimeException
- */
- @Override
- public void closeFullScreen() {
- if (isFullScreen()) {
- LOGGER.info("Open full screen mode in video player...");
- openPlayerToolbar();
- fullScreenButton.click();
- }
- if (isFullScreen()) {
- throw new RuntimeException("Fullscreen is not closed");
- }
- }
- /**
- * Rewind video to start
- *
- */
- public void rewindVideo() {
- LOGGER.info("Rewinding video");
- openPlayerToolbar();
- rewindButton.click();
- }
- /**
- * Prepare video in player
- *
- */
- public void prepareVideo(String mgid) {
- LOGGER.info("Preparing video");
- prepareVideoField.clear();
- prepareVideoField.sendKeys(mgid);
- prepareVideoButton.click();
- }
- /**
- * Configure video in player
- *
- */
- public void configureVideo(String mgid) {
- LOGGER.info("Configuring video");
- configureVideoField.click();
- configureVideoField.clear();
- configureVideoField.sendKeys(mgid);
- configureVideoButton.click();
- }
- /**
- * Load video in player
- *
- */
- public void loadVideo(String mgid) {
- if (mgid.matches(PlayerPatternConstants.VIDEO_CLIP_PATTERN)) {
- LOGGER.info("Loading video clip");
- loadVideoField.click();
- loadVideoField.clear();
- loadVideoField.sendKeys(mgid);
- loadVideoButton.click();
- } else if (mgid.matches(PlayerPatternConstants.FULL_EPISODE_PATTERN) || mgid.matches(PlayerPatternConstants.PLAYLIST_PATTERN)) {
- LOGGER.info("Loading video full episode or playlist");
- loadVideoPlaylistField.click();
- loadVideoPlaylistField.clear();
- loadVideoPlaylistField.sendKeys(mgid);
- loadVideoPlaylistButton.click();
- }
- }
- /**
- * Type Media API token
- *
- */
- public void typeMediaApiToken(String apiToken) {
- LOGGER.info("Setting Media API Token ");
- mediaApiTokenField.click();
- mediaApiTokenField.clear();
- mediaApiTokenField.sendKeys(apiToken);
- }
- /**
- * Toggle MRSS/VC
- *
- */
- public void toggleMRSS() {
- LOGGER.info("Toglle MRSS/VC mode");
- mrssToggle.click();
- }
- /**
- * Toggle chromeless Ads
- *
- */
- public void toggleCromelessAds() {
- LOGGER.info("Toglle Ads through chromeless controls");
- chromelessAdsToggle.click();
- }
- /**
- * Toggle chromeless Reporting
- *
- */
- public void toggleCromelessReporting() {
- LOGGER.info("Toglle Reporting through chromeless controls");
- chromelessReportingToggle.click();
- }
- /**
- * Toggle chromeless Closed Captions
- *
- */
- public void toggleCromelessClosedCaptions() {
- LOGGER.info("Toggle Closed Caption through chromeless controls");
- chromelessClosedCaptonsToggle.click();
- }
- /**
- * Toggle chromeless Play button
- *
- */
- public void cromelessPlay() {
- LOGGER.info("Playing video through chromeless controls");
- chromelessPlayPauseButton.click();
- }
- /**
- * Toggle chromeless Pause button
- *
- */
- public void cromelessPause() {
- LOGGER.info("Pausing video through chromeless controls");
- chromelessPlayPauseButton.click();
- }
- /**
- * Reset player content
- *
- */
- public void resetContent() {
- LOGGER.info("Reset player");
- resetContentButton.click();
- }
- /**
- * Save player state
- *
- */
- public void saveState() {
- LOGGER.info("Saving player state");
- saveStateButton.click();
- }
- /**
- * Load player state
- *
- */
- public void loadState() {
- LOGGER.info("Loading player state");
- loadStateButton.click();
- }
- /**
- * Pause Ad on video
- *
- */
- public void pauseAd() {
- LOGGER.info("Pausing Ad");
- openPlayerToolbar();
- adPlayPauseButton.click();
- }
- /**
- * Play Ad on video
- *
- */
- public void playAd() {
- LOGGER.info("Playing Ad");
- openPlayerToolbar();
- adPlayPauseButton.click();
- }
- /**
- * Go to Learn more Ad
- *
- */
- public void goLearnMore() {
- LOGGER.info("Going to 'Learn More'");
- openPlayerToolbar();
- adLearnMoreButton.click();
- }
- /**
- * Toggle Ad Full Screen mode
- *
- */
- public boolean toggleAdFullScreenMode() {
- LOGGER.info("Toggle Full Screen mode");
- Dimension before = adView.getSize();
- openPlayerToolbar();
- adFullScreenButton.click();
- Dimension after = adView.getSize();
- if (after.getWidth() > before.getWidth() || after.getHeight() > before.getHeight()) {
- return true;
- }
- return false;
- }
- /**
- * Scrub video to define time
- *
- * @param pauseBeforeSeek
- * pause video before scrub
- * @param timeToScroll
- * time to scroll
- */
- @Override
- public void scrubVideo(boolean pauseBeforeSeek, double timeToScroll) {
- float[] time = getTimeCoordinates(timeToScroll);
- if (pauseBeforeSeek) {
- pauseVideo();
- dragScrubber(time);
- playVideo();
- waitForVideoTimeChanged();
- } else {
- dragScrubber(time);
- }
- Sleeper.SYSTEM_SLEEPER.sleep(5000);
- }
- /**
- * Scrub video to define time
- *
- * @param seconds
- * time to scroll
- *
- * @param adFinishTimeout
- *
- */
- @Override
- public void scrubVideo(double seconds, int adFinishTimeout) {
- throw new UnimplementedMethodException("Method scrubVideo() isn't implemented for mobile player");
- }
- /**
- * Scrub video to define time
- *
- * @param timeToScroll
- * time to scroll
- */
- @Override
- public void scrubVideo(double timeToScroll) {
- float[] time = getTimeCoordinates(timeToScroll);
- dragScrubber(time);
- Sleeper.SYSTEM_SLEEPER.sleep(5000);
- }
- /**
- * Calculate coordinates to seek
- *
- * @param timeInSec
- * time to scroll in seconds
- */
- private float[] getTimeCoordinates(double timeInSec) {
- openPlayerToolbar();
- WebElement seekBarLoaded = scrubber;
- Dimension seekBarLoadedSize = seekBarLoaded.getSize();
- int endTimeValue = 0;
- int seekBarWidth = 0;
- float[] offset = new float[2];
- endTimeValue = (int) getEndTimeInSec();
- if (endTimeValue < 0) {
- LOGGER.info("Retry getTime method...");
- endTimeValue = (int) getEndTimeInSec();
- }
- seekBarWidth = seekBarLoadedSize.width;
- LOGGER.info("SeekBar width = " + seekBarWidth);
- LOGGER.info("Calculate offset: (" + seekBarWidth + "*" + timeInSec + ")/" + endTimeValue + " ...");
- float offsetValue = seekBarWidth * ((int) timeInSec) / endTimeValue;
- LOGGER.info("Scrubber offset = " + offsetValue);
- offset[0] = (float) seekBarLoaded.getLocation().x + offsetValue;
- offset[1] = seekBarLoaded.getLocation().y;
- return offset;
- }
- /**
- * Touch to calculated coordinates for seeking
- *
- * @param offset
- * coordinates to seek
- */
- public void dragScrubber(float[] offset) {
- openPlayerToolbar();
- ((AppiumDriver) driver).touch((int) offset[0], (int) offset[1]);
- }
- /**
- * Toggle Ad Closed Captions
- */
- public void toggleAdClosedCaptions() {
- LOGGER.info("Toggle Ad Closed Captions");
- openPlayerToolbar();
- adClosedCaptionsButton.click();
- }
- /**
- * Check video on full screen state
- *
- * @return return full screen state
- */
- @Override
- public boolean isFullScreen() {
- Dimension viewDimension = bcVideoView.getSize();
- LOGGER.info("View dimension is " + viewDimension);
- Dimension deviceDimension = driver.manage().window().getSize();
- LOGGER.info("Device dimension is " + deviceDimension);
- if (deviceDimension.getWidth() > viewDimension.getWidth() || deviceDimension.getHeight() > viewDimension.getHeight()) {
- return true;
- }
- return false;
- }
- /**
- * Check Live status visibility
- *
- * @return Live status visibility
- */
- public boolean isLiveStatusVisible() {
- try {
- LOGGER.info("Checking Live Status visibility");
- return liveStatus.isDisplayed();
- } catch (NotFoundException e) {
- return false;
- }
- }
- /**
- * Check Ad visibility
- *
- * @return Ad visibility
- */
- @Override
- public boolean isAdDisplayed() {
- try {
- LOGGER.info("Checking Ad View visibility");
- return adView.isDisplayed();
- } catch (NotFoundException e) {
- return false;
- }
- }
- /**
- * Check progress bar visibility
- *
- * @return progress bar visibility
- */
- @Override
- public boolean isProgressBarVisible() {
- LOGGER.info("Checking progress bar visibility");
- try {
- return scrubber.isDisplayed();
- } catch (NotFoundException e) {
- return false;
- }
- }
- /**
- * Check Rewind button visibility
- *
- * @return Rewind button visibility
- */
- public boolean isRewindButtonVisible() {
- LOGGER.info("Checking Rewind Button visibility");
- try {
- return rewindButton.isDisplayed();
- } catch (NotFoundException e) {
- return false;
- }
- }
- /**
- * Check Spinner visibility
- *
- * @return Spinner visibility
- */
- public boolean isSpinnerDisplayed() {
- LOGGER.info("Checking Spinner visibility");
- try {
- return spinner.isDisplayed();
- } catch (NotFoundException e) {
- return false;
- }
- }
- /**
- * Check Preroll Ad Spinner visibility
- *
- * @return preroll Ad Spinner visibility
- */
- public boolean isPrerollAdSpinnerDisplayed() {
- LOGGER.info("Checking Spinner visibility");
- try {
- return prerollAdSpinner.isDisplayed();
- } catch (NotFoundException e) {
- return false;
- }
- }
- /**
- * Check Play/Pause button visibility
- *
- * @return Play/Pause button visibility
- */
- public boolean isPlayPauseButtonDisplayed() {
- LOGGER.info("Checking Play Pause Button visibility");
- try {
- return playPauseButton.isDisplayed();
- } catch (NotFoundException e) {
- return false;
- }
- }
- /**
- * Check Play button visibility
- *
- * @return Play button visibility
- */
- @Override
- public boolean isPlayButtonDisplayed() {
- return isPlayPauseButtonDisplayed();
- }
- /**
- * Check Pause button visibility
- *
- * @return Pause button visibility
- */
- @Override
- public boolean isPauseButtonDisplayed() {
- return isPlayPauseButtonDisplayed();
- }
- /**
- * Check Closed Captions button visibility
- *
- * @return Closed Captions button visibility
- */
- @Override
- public boolean isClosedCaptionsButtonDisplayed() {
- try {
- LOGGER.info("Checking Closed Captions Button visibility");
- return closedCaptionsButton.isDisplayed();
- } catch (NotFoundException e) {
- return false;
- }
- }
- /**
- * Check Full Screen button visibility
- *
- * @return Full Screen button visibility
- */
- public boolean isFullScreenButtonDisplayed() {
- try {
- LOGGER.info("Checking Full Screen Button visibility");
- return fullScreenButton.isDisplayed();
- } catch (NotFoundException e) {
- return false;
- }
- }
- @Override
- public boolean isEnterFullScreenButtonDisplayed() {
- return isFullScreenButtonDisplayed();
- }
- @Override
- public boolean isCloseFullScreenButtonDisplayed() {
- return isFullScreenButtonDisplayed();
- }
- /**
- * Check Current time visibility
- *
- * @return Current time visibility
- */
- @Override
- public boolean isCurrentTimeDisplayed() {
- try {
- LOGGER.info("Checking Current Time visibility");
- return currentTime.isDisplayed();
- } catch (NotFoundException e) {
- return false;
- }
- }
- /**
- * Check End time visibility
- *
- * @return End time visibility
- */
- @Override
- public boolean isEndTimeDisplayed() {
- try {
- LOGGER.info("Checking End Time visibility");
- return endTime.isDisplayed();
- } catch (NotFoundException e) {
- return false;
- }
- }
- /**
- * Check Ad Learn More button visibility
- *
- * @return Ad Learn More button visibility
- */
- public boolean isAdLearnMoreButtonDisplayed() {
- try {
- LOGGER.info("Checking Ad Learn More button visibility");
- return adLearnMoreButton.isDisplayed();
- } catch (NotFoundException e) {
- return false;
- }
- }
- /**
- * Check Ad Closed Captions button visibility
- *
- * @return Ad Closed Captions button visibility
- */
- public boolean isAdClosedCaptionsButtonDisplayed() {
- try {
- LOGGER.info("Checking Ad Learn More button visibility");
- return adClosedCaptionsButton.isDisplayed();
- } catch (NotFoundException e) {
- return false;
- }
- }
- /**
- * Check Ad Play/Pause button visibility
- *
- * @return Ad Play/Pause button visibility
- */
- public boolean isAdPlayPauseButtonDisplayed() {
- try {
- LOGGER.info("Checking Ad Learn More button visibility");
- return adPlayPauseButton.isDisplayed();
- } catch (NotFoundException e) {
- return false;
- }
- }
- /**
- * Check Ad Full Screen button visibility
- *
- * @return Ad Full Screen button visibility
- */
- public boolean isAdFullScreenButtonDisplayed() {
- try {
- LOGGER.info("Checking Ad Learn More button visibility");
- return adFullScreenButton.isDisplayed();
- } catch (NotFoundException e) {
- return false;
- }
- }
- /**
- * Check on Ad pause
- *
- * @param sleepTimeSec
- * time out value
- * @return Ad pause status
- */
- @Override
- public boolean isAdPaused(int sleepTimeSec) {
- int timeBefore = (int) getAdRemainTime();
- Sleeper.SYSTEM_SLEEPER.sleep(sleepTimeSec * 1000);
- int timeAfter = (int) getAdRemainTime();
- LOGGER.info("Time before pause: " + timeBefore + "\n" + "Time after 3 sec of pause: " + timeAfter);
- return timeBefore == timeAfter;
- }
- /**
- * Check on Ad play
- *
- * @param sleepTimeSec
- * time out value
- * @return Ad play status
- */
- @Override
- public boolean isAdPlaying(int sleepTimeSec) {
- int timeBefore = (int) getAdRemainTime();
- Sleeper.SYSTEM_SLEEPER.sleep(sleepTimeSec * 1000);
- int timeAfter = (int) getAdRemainTime();
- LOGGER.info("Time before pause: " + timeBefore + "\n" + "Time after 3 sec of pause: " + timeAfter);
- return timeBefore < timeAfter;
- }
- /**
- * Waiting for next video will be played
- *
- * @param prerollTime
- * preroll time value
- * @param previousVideoTime
- * previous time value
- */
- public void waitForNextVideoPlayed(int prerollTime, int previousVideoTime) {
- LOGGER.info("Check next video played");
- waitForVideoTime(10, PlayerTimeConstants.VIDEO_LOAD_TIMEOUT_SEC, Operators.LESS_EQUAL);
- if (isAdDisplayed()) {
- waitForAdStart(PlayerTimeConstants.SHORT_TIME_OUT);
- waitForAdEnded(prerollTime);
- }
- }
- /**
- * Waiting for video time or video end
- *
- * @param time
- * @param timeoutSec
- * @return real time when method stop to wait
- *
- * @throws VideoNotLoadedException
- */
- public int waitForVideoTimeOrVideoEnd(final int time, int timeoutSec) {
- LOGGER.info("Wait for Video time = " + time + " or video is ended");
- Function<WebDriver, Boolean> function = new Function<WebDriver, Boolean>() {
- int currentTime;
- @Override
- public Boolean apply(WebDriver input) {
- try {
- currentTime = (int) getCurrentTimeInSec();
- } catch (UndeclaredThrowableException e) {
- LOGGER.info("Video is ended.");
- currentTime = 0;
- return true;
- }
- int timeToWait = time - currentTime;
- LOGGER.info("Time to wait: " + timeToWait);
- return (timeToWait <= 0) || (currentTime == 0) || (timeToWait == 1);
- }
- public String toString() {
- return Integer.toString(currentTime);
- }
- };
- new FluentWait<WebDriver>(driver).withTimeout(timeoutSec, TimeUnit.SECONDS).pollingEvery(1, TimeUnit.SECONDS)
- .until(function, VideoNotLoadedException.class, "Video time still not " + time);
- int timeValue = Integer.parseInt(function.toString());
- LOGGER.info("Time: " + timeValue);
- return timeValue;
- }
- /**
- * Waiting for video time or video end
- *
- * @param time
- * @return real time when method stop to wait
- */
- public int waitForVideoTimeOrVideoEnd(final int time) {
- LOGGER.info("Wait for Video time = " + time + " or video is ended");
- int currentTime = (int) getCurrentTimeInSec();
- int timeout = PlayerUtils.calculateWaitTime(currentTime, time, PlayerTimeConstants.MULTIPLICATOR);
- return waitForVideoTimeOrVideoEnd(time, timeout);
- }
- /**
- * Waiting for video time or video end
- *
- * @param time
- * @return real time when method stop to wait
- */
- public int waitForVideoTimeFromTo(int startTime, int time) {
- LOGGER.info("Wait for Video time = " + time + " or video is ended");
- int timeout = PlayerUtils.calculateWaitTime(startTime, time, PlayerTimeConstants.MULTIPLICATOR);
- return waitForVideoTimeOrVideoEnd(time, timeout);
- }
- /**
- * Waiting for remain ad time was changed
- *
- * @param timeoutSec
- */
- public void waitForRemainTimeChanged(int timeoutSec) {
- LOGGER.info("Wait for Remain time changed");
- final String startTime = adRemainTime.getText();
- new FluentWait<WebDriver>(driver).withTimeout(timeoutSec, TimeUnit.SECONDS).pollingEvery(1, TimeUnit.SECONDS)
- .until(new Function<WebDriver, Boolean>() {
- @Override
- public Boolean apply(WebDriver input) {
- return !startTime.equals(adRemainTime.getText());
- }
- }, VideoNotLoadedException.class, "Video didn't start");
- }
- /**
- * Waiting for Ad will be started
- *
- * @param timeout
- * timeout value in seconds
- */
- @Override
- public void waitForAdStart(int timeout) {
- LOGGER.info("Wait for Ad message...");
- new FluentWait<WebDriver>(driver).withTimeout(timeout, TimeUnit.SECONDS).pollingEvery(1, TimeUnit.SECONDS)
- .until(new Function<WebDriver, Boolean>() {
- @Override
- public Boolean apply(WebDriver input) {
- return adRemainTime.isDisplayed();
- }
- });
- }
- /**
- * Waiting for Ad will be ended
- *
- * @param adTimeout
- * timeout value in seconds
- */
- @Override
- public void waitForAdEnded(int adTimeout) {
- LOGGER.info("Wait for Ad message...");
- new FluentWait<WebDriver>(driver).withTimeout(adTimeout, TimeUnit.SECONDS).pollingEvery(1, TimeUnit.SECONDS)
- .until(new Function<WebDriver, Boolean>() {
- @Override
- public Boolean apply(WebDriver input) {
- return !adRemainTime.isDisplayed();
- }
- });
- }
- /**
- * Waiting for player toolbar will be hidden
- *
- * @param timeoutSec
- * timeout value in seconds
- */
- @Override
- public void waitForPlayerToolbarNotVisible(int timeoutSec) {
- LOGGER.info("Wait for player toolbar isn't visible ...");
- new FluentWait<WebDriver>(driver).withTimeout(timeoutSec, TimeUnit.SECONDS).pollingEvery(1, TimeUnit.SECONDS)
- .until(new Function<WebDriver, Boolean>() {
- @Override
- public Boolean apply(WebDriver input) {
- return !playPauseButton.isDisplayed();
- }
- }, PlayerToolbarException.class, "ERROR! Player toolbar is not hidden");
- }
- /**
- * Waiting for player toolbar for Ad will be hidden
- *
- * @param timeoutSec
- * timeout value in seconds
- */
- public void waitForAdPlayerToolbarNotVisible(int timeoutSec) {
- LOGGER.info("Wait for player toolbar isn't visible ...");
- new FluentWait<WebDriver>(driver).withTimeout(timeoutSec, TimeUnit.SECONDS).pollingEvery(1, TimeUnit.SECONDS)
- .until(new Function<WebDriver, Boolean>() {
- @Override
- public Boolean apply(WebDriver input) {
- return !adPlayPauseButton.isDisplayed();
- }
- }, PlayerToolbarException.class, "ERROR! Player toolbar is not hidden");
- }
- /**
- * Waiting for overlay will be visible
- *
- */
- public void waitForOverlay() {
- LOGGER.info("Wait for player toolbar isn't visible ...");
- new FluentWait<WebDriver>(driver).withTimeout(PlayerTimeConstants.OVERLAY_LOAD_TIMEOUT_SEC, TimeUnit.SECONDS)
- .pollingEvery(1, TimeUnit.SECONDS).until(new Function<WebDriver, Boolean>() {
- @Override
- public Boolean apply(WebDriver input) {
- return overlay.isDisplayed();
- }
- }, RuntimeException.class, "ERROR! Overlay is hidden");
- }
- /**
- * Waiting for overlay will be hidden
- *
- * @return time when overlay hidden
- */
- public long getOverlayDisappearTime() {
- new FluentWait<WebDriver>(driver).withTimeout(PlayerTimeConstants.OVERLAY_LOAD_TIMEOUT_SEC, TimeUnit.SECONDS).until(
- new Function<WebDriver, Boolean>() {
- @Override
- public Boolean apply(WebDriver input) {
- return !overlay.isDisplayed();
- }
- }, RuntimeException.class, "Overlay not dissapeared");
- return System.currentTimeMillis();
- }
- /**
- * Waiting for spinner will be visible
- *
- * @return time when spinner visible
- */
- public void waitForSpinnerVisible(long timeoutSec) {
- LOGGER.info("Waiting for spinner visibility during " + timeoutSec);
- new FluentWait<WebDriver>(driver).withTimeout(timeoutSec, TimeUnit.SECONDS).until(new Function<WebDriver, Boolean>() {
- @Override
- public Boolean apply(WebDriver input) {
- return spinner.isDisplayed();
- }
- }, RuntimeException.class, "ERROR! Spinner is not displayed (*UNSTABLE*)");
- }
- /**
- * Waiting for spinner will be hidden
- *
- * @return time when spinner hidden
- */
- public void waitForSpinnerHidden(long timeoutSec) {
- LOGGER.info("Waiting for spinner disappearing during " + timeoutSec);
- new FluentWait<WebDriver>(driver).withTimeout(timeoutSec, TimeUnit.SECONDS).until(new Function<WebDriver, Boolean>() {
- @Override
- public Boolean apply(WebDriver input) {
- return !spinner.isDisplayed();
- }
- }, RuntimeException.class, "ERROR! Spinner is not hidden (*UNSTABLE*)");
- }
- /**
- * Waiting for preroll Ad spinner will be visible
- *
- * @return time when preroll Ad spinner visible
- */
- public void waitForPrerollAdSpinnerVisible(long timeoutSec) {
- LOGGER.info("Waiting for pre-roll Ad spinner visibility during " + timeoutSec);
- new FluentWait<WebDriver>(driver).withTimeout(timeoutSec, TimeUnit.SECONDS).until(new Function<WebDriver, Boolean>() {
- @Override
- public Boolean apply(WebDriver input) {
- return prerollAdSpinner.isDisplayed();
- }
- }, RuntimeException.class, "ERROR! Spinner is not hidden (*UNSTABLE*)");
- }
- /**
- * Waiting for preroll Ad spinner will be hidden
- *
- * @return time when preroll Ad spinner hidden
- */
- public void waitForPrerollAdSpinnerHidden(long timeoutSec) {
- LOGGER.info("Waiting for pre-roll Ad spinner disappearing during " + timeoutSec);
- new FluentWait<WebDriver>(driver).withTimeout(timeoutSec, TimeUnit.SECONDS).until(new Function<WebDriver, Boolean>() {
- @Override
- public Boolean apply(WebDriver input) {
- return !prerollAdSpinner.isDisplayed();
- }
- }, RuntimeException.class, "ERROR! Spinner is not hidden (*UNSTABLE*)");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement