Selenium-appium-java-android-chrome-browser

I am doing automation to test Video on Android Chrome browser using Selenium Appium Web Driver. I have to read text from a field. The text exists on page for 5 seconds. Appium takes approx 10 sec to process the request. I am not able to read the object because of long processing time of Appium. I tried all possible options. Can you please help me to fix the issue

@TechTeam

Hey can u please let me know whether text will appear if the user touches the page? if yes ,then we can get the text

Hi Rajesh,

My script is running on Android Device -> Chrom browser.

Workflow is:

  1. Open url
  2. HTML 5 video player starts playing the video
  3. At the start of video I get Video Ad
  4. Duration of Ad is 6 seconds and appears in a text field

I have to read the text value.

xpath /hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.view.ViewGroup/android.widget.FrameLayout[1]/android.widget.FrameLayout[2]/android.webkit.WebView/android.view.View[2]/android.view.View[4]/android.view.View/android.view.View/android.view.View[5]/android.view.View

Can you please guide me to fix the issue?

Thanks,
Deepak

Hi Deepak & @TechTeam

is there possibility to pause the video while playing ad? and also send screenshot of emulator to find element which contains text…

Hi Rajesh,

Please find the screenshot attached. I have highlighted the text and pause button in RED circle.

Appium takes ~20-30 secs to click on Pause button or read the text.

Image_Read_Text

Code Snippent:
/**
* Get Video Ad Duration
* @return
*/
public String videoAdDuration(){
System.out.println("\tGet Video Ad Duration process started");
By VIDEO_AD_DURATION = By.xpath("//android.view.View/android.view.View[5]/android.view.View"); //Element Appium found
String videoDurationValue = getElementDetails(VIDEO_AD_DURATION).getText();
System.out.println("\tVideo Ad Duration: " + videoDurationValue);
System.out.println("\tProcess completed : " + new Timestamp(System.currentTimeMillis()));
return videoDurationValue;
}

/**
* Play/ Pause Video Player
*/
public static void videoPlayPause(){
System.out.println("\tPlay/ Pause video process started : " + System.currentTimeMillis());
By START_STOP_VIDEO_BUTTON = By.xpath("//android.widget.Button[@text=‘Play’]"); // Appium found
videoPlayPauseElement = getElementDetails(START_STOP_VIDEO_BUTTON);
//videoPlayPauseElement = driver.findElement(START_STOP_VIDEO_BUTTON);
videoPlayPauseElement.click();
System.out.println("\tPlay / Pause video process completed : " + System.currentTimeMillis());
}

/**
* Get Element details
* @param by
* @return
*/
private static WebElement getElementDetails(By by){
WebElement element = null;
boolean isElementExist = false;
//System.out.println("\tElement to be find: " + by.toString());
while(!(isElementExist)) {
isElementExist = isElementFound(by);
if(isElementExist){
element = driver.findElement(by);
} else {
driver.manage().timeouts().implicitlyWait(10, TimeUnit.MILLISECONDS);
}
System.out.println("\tElement visibility status: " + isElementExist);
}

    return element;
}

/**
 * Find Element
 * @param by
 * @return
 */
private static boolean isElementFound(By by) {
    boolean isExists = false;
    //driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS);
    try {
        System.out.println("\t" + System.currentTimeMillis() + " Start Find Element : " + by.toString());
        driver.findElement(by);
        isExists = true;
    } catch (NoSuchElementException e) {
        System.out.println("\t" + System.currentTimeMillis() + " - Element not found : " + by.toString());
    }

    // System.out.println("\tElement found Status : " + isExists);
    return isExists;
}

Waiting for your response.

Execution output:
Play Video method call time : 2018-09-05 18:34:43.495
Click on Play Video button process started
1536152683495 Start Find Element : By.xpath: /android.widget.Button[@text=‘Play Video’]
Element visibility status: true
Process completed : 2018-09-05 18:34:45.227
Pause Video method call time : 2018-09-05 18:34:45.227
Play/ Pause video process started : 1536152685227
1536152685227 Start Find Element : By.xpath: /android.widget.Button[@text=‘Play’]
Element visibility status: true
Play / Pause video process completed : 1536152704983
Video Logo method call time : 2018-09-05 18:35:04.983
Get Video Logo text process started : 2018-09-05 18:35:04.983
1536152704983 Start Find Element : By.xpath: /android.widget.Button[@resource-id=‘AM_skipButton’]
Element visibility status: true
Video logo text:
Process completed: 2018-09-05 18:35:06.233
VideoAd Duration method call time :
Get Video Ad Duration process started
1536152706233 Start Find Element : By.xpath: //android.view.View/android.view.View[5]/android.view.View
Element visibility status: true
Video Ad Duration: פרסומת: 00:04
Process completed : 2018-09-05 18:35:06.977

Hi Rajesh,

Any updates…

Deepak

Hey Deepak & @TechTeam

iam able to see the ad text In ur execution output? This is what u need rite??

Video Ad Duration: פרסומת: 00:04

and also please clarify, whether ad is completed by the time u click on pause button ?

Please note that , Appium Execution will be very slow in case of mobile web apps which is known issue.So, what iam trying to do is ,we need to click on pause button so that ad will pause then read the text. once u read the text then resume the video.

Thanks,
Rajesh Kumar

Hi Rajesh,

Sorry for the delay in replying to your mail.

Yes I would like to read the “Video Ad Duration: פרסומת: 00:04”. But the time I read the text or click on the Pause button the Video Ad gets over.

Click on Pause button also takes 8-10 sec. Video Ad duration is 7 sec.

Can you please share list of Appium Execution known issues?

Currently I am using Appium Desktop version for running the test script. Shall I use Appium CLI instead of Appium Desktop for better performance?

Thanks,
Deepak

@TechTeam & Deepak,

If you use CLI or desktop version then there is no difference because even desktop version also it launches node.js when u start the server.

Are you using any wait in ur method>getElementDetails(VIDEO_AD_DURATION).getText();??

But still i didnt understand , you are able to read the text and its printed on execution output…

I have to read duration and some text while Video Ad is playing. But I managed to read only text and not other texts.

Can I concurrently run multiple findElements commands?

Thanks,
Deepak

Hey Deepak /@TechTeam,

Can u please send me the the method which u have used . I Think u kept some waits in that method.

getElementDetails(VIDEO_AD_DURATION).getText();??

Thanks,
Rajesh Kumar

Hi Rajesh,

Please find method details below.

/**
* Get Element details
* @param by
* @return
*/
private static WebElement getElementDetails(By by){
WebElement element = null;
boolean isElementExist = false;
//System.out.println("\tElement to be find: " + by.toString());
while(!(isElementExist)) {
isElementExist = isElementFound(by);
if(isElementExist){
element = driver.findElement(by);
} else {
driver.manage().timeouts().implicitlyWait(100, TimeUnit.MILLISECONDS);
}
System.out.println("\tElement visibility status: " + isElementExist);
}

    return element;
}

/**
 * Find Element
 * @param by
 * @return
 */
private static boolean isElementFound(By by) {
    boolean isExists = false;
    //driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS);
    try {
        System.out.println("\t" + System.currentTimeMillis() + " Start Find Element : " + by.toString());
        driver.findElement(by);
        isExists = true;
    } catch (NoSuchElementException e) {
        System.out.println("\t" + System.currentTimeMillis() + " - Element not found : " + by.toString());
    }

    // System.out.println("\tElement found Status : " + isExists);
    return isExists;
}

Hello Deepak/@TechTeam ,

Instead of using implicit wait use webdriver wait…why becoz it will wait till all the elements loaded.

Please change the implicit wait statement to webdriver wait… Hope u know how to add webdriver wait…

Hello Rajesh,

Ok I will try with WebDriver wait. I tried with Explicit wait but it did not work.

Let me try again.

Thanks,
Deepak

Hi Rajesh,

I have changed code for waiting element

Still to click on Pause button takes 19 seconds.

WebDriverWait wait = new WebDriverWait(driver,3, TimeUnit.SECONDS.toMillis(20));

**
* Play/ Pause Video Player
*/
public void videoPlayPause(){

    startTime = new Timestamp(System.currentTimeMillis());

    System.out.println("\tPlay/ Pause video process started : " + endTime);
    By START_STOP_VIDEO_BUTTON = By.xpath("//android.widget.Button[@text='Play']"); // Appium found
    //By START_STOP_VIDEO_BUTTON = By.xpath("//android.widget.Button[@bounds='[187,824][231,858]']"); // Appium found
    //By START_STOP_VIDEO_BUTTON = By.xpath("//android.widget.Button[@instance='0']"); // Appium found
    videoPlayPauseElement = getElementDetails(START_STOP_VIDEO_BUTTON);
    videoPlayPauseElement.click();

    endTime = new Timestamp(System.currentTimeMillis());
    getProcessTime(startTime, endTime);
    System.out.println("\tPlay / Pause video process completed : " + endTime);
}

/**
* Get Element details
* @param by
* @return
*/
private static WebElement getElementDetails(By by){
WebElement element = null;
boolean isElementExist = false;
//System.out.println("\tElement to be find: " + by.toString());
while(!(isElementExist)) {
isElementExist = isElementFound(by);
if(isElementExist){
element = driver.findElement(by);
} else {
wait.until(ExpectedConditions.visibilityOfElementLocated(by));
}
System.out.println("\tElement visibility status: " + isElementExist + " Timestampe: " + new Timestamp(System.currentTimeMillis()));
}

    return element;
}

/**
 * Find Element
 * @param by
 * @return
 */
private static boolean isElementFound(By by) {
    boolean isExists = false;
    //driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS);
    try {
        //System.out.println("\tStart Find Element : " + by.toString());
        driver.findElement(by);
        isExists = true;
    } catch (NoSuchElementException e) {
        //System.out.println("\tElement not found : " + by.toString());
        e.printStackTrace();
    }

    // System.out.println("\tElement found Status : " + isExists);
    return isExists;
}

Pause Video method call time : 2018-09-11 10:22:47.195
Play/ Pause video process started : 2018-09-11 10:22:47.195
Element visibility status: true Timestampe: 2018-09-11 10:22:56.509
Processing time in seconds : 19
Play / Pause video process completed : 2018-09-11 10:23:06.775

What is wrong here?

Please help me.

Thanks,
Deepak

Hey Deepak,

Everything is correct!!! but appium driver itself takes more time to process the command which we cant do anything.

My Last trial will be remove all processing time calculation methods and try. if it does not works out then helpless.

Thanks,
Rajesh Kumar

Hi Rajesh,

Thanks a lot for going through the code. I had tried with many options but still Appium takes more time for processing.

Once again thanks a lot for all your help.

I have some more questions for which I will create new support ticket.

Thanks,
Deepak

Hi Rajesh,

I posted some more queries.

Kindly answer them

Hey Deepak,

Please Send me the links for your questions

Thanks,
Rajesh Kumar

Hi Rajesh,

Good morning …

Thanks,
Deepak