I have an HTML video player that runs random videos. I have the following function that tests if the video is marked completed based on the video seen percentage. VideoCompletionPercentage is a global variable that is set by reading it from the database. I have to test for two conditions as follows:
- verify video is marked complete if it is seen till a VideoCompletionPercentage set from the DB.
- verify video is not marked complete if it is skipped forward and seen till 100%
I am switching between two while loops based on a skip bool variable. Is there any way to combine these two do while loops into one by manipulating the while condition or any other way? Thanks in advance for your inputs.
private void VideoPecentageCompletion(bool skip)
{
double videoSeenPercentage;
if (skip)
{
do
{
double.TryParse(Driver.FindElement(By.CssSelector("div[class=played]")).GetAttribute("aria-valuemax"), out double totalVideo);
double.TryParse(Driver.FindElement(By.CssSelector("div[class=played]")).GetAttribute("aria-valuenow"), out double videoProgress);
videoSeenPercentage = Math.Floor(videoProgress / totalVideo * 100);
} while (videoSeenPercentage < VideoCompletionPercentage);
}
else
{
do
{
double.TryParse(Driver.FindElement(By.CssSelector("div[class=played]")).GetAttribute("aria-valuemax"), out double totalVideo);
double.TryParse(Driver.FindElement(By.CssSelector("div[class=played]")).GetAttribute("aria-valuenow"), out double videoProgress);
videoSeenPercentage = Math.Floor(videoProgress / totalVideo * 100);
} while (videoSeenPercentage < 100);
}
}