Page Object Initialisation is taking too much time

I am running parallel execution on Browserstack.
I have done some debugging, I added some logs in Test file that executes in the starting. Here is the code for this and logs

@BeforeClass(alwaysRun = true,dependsOnMethods = { "initialise" })
public void beforeClass() throws IOException, ParseException {
  log(Status.INFO, "Before initialization");
  this.driver=getDriver();
  log(Status.INFO, "before login page initialization");
  this.loginPage = new LoginPage(this.driver);
  log(Status.INFO, "before home page initialization");
  this.homePage = new HomePage(this.driver);
  log(Status.INFO, "before welcomeToTLifePage page initialization");
  this.welcomeToTLifePage = new WelcomeToTLifePage(this.driver);
  log(Status.INFO, "before allowNotificationPage page initialization");
  data = new ExcelReaderDataClass();
  allowNotificationPage = new AllowNotificationPage(this.driver);
  log(Status.INFO, "before allowLocationAccessPage page initialization");
  allowLocationAccessPage = new AllowLocationAccessPage(this.driver);
  log(Status.INFO, "after allowLocationAccessPage page initialization");
}
2024-06-04 14:15:51,532 [TestNG-tests-2] INFO  com.tlife.core.homeTest.LoginTest - Before initialization
2024-06-04 14:15:51,534 [TestNG-tests-2] INFO  com.tlife.core.homeTest.LoginTest - before login page initialization
2024-06-04 14:15:51,683 [TestNG-tests-1] INFO  com.tlife.pageObject.core.WelcomeToTLifePage - Clicking on Skip button
2024-06-04 14:15:54,095 [TestNG-tests-2] INFO  com.tlife.core.homeTest.LoginTest - before home page initialization
2024-06-04 14:15:54,325 [TestNG-tests-5] INFO  com.tlife.pageObject.core.WelcomeToTLifePage - Clicking on Skip button
2024-06-04 14:15:55,228 [TestNG-tests-2] INFO  com.tlife.core.homeTest.LoginTest - before welcomeToTLifePage page initialization
2024-06-04 14:15:55,425 [TestNG-tests-2] INFO  com.tlife.core.homeTest.LoginTest - before allowNotificationPage page initialization
2024-06-04 14:15:55,635 [TestNG-tests-2] INFO  com.tlife.core.homeTest.LoginTest - before allowLocationAccessPage page initialization
2024-06-04 14:15:55,922 [TestNG-tests-2] INFO  com.tlife.core.homeTest.LoginTest - after allowLocationAccessPage page initialization

If you notice all these object creation takes only few seconds or millieseconds.

Now after running some test suites there is more class in which I have added the loggers, here is the class and their loggers.

@BeforeClass(alwaysRun = true)
public void beforeClass() throws IOException, ParseException, InterruptedException {
    System.out.println("Starting before class in ConnectWatch on " + Thread.currentThread().getName());
    logThreadState("Before initializing driver");
    this.driver=getDriver();
    logThreadState("Before initializing loginPage");
    LoginPage loginPage = new LoginPage(this.driver);
    logThreadState("Before initializing welcomeToTLifePage");
    WelcomeToTLifePage welcomeToTLifePage = new WelcomeToTLifePage(this.driver);
    logThreadState("Before initializing HomePage");
    this.homePage = new HomePage(driver);
    logThreadState("Before initializing KidsWatchPage");
    this.kidsWatchPage = new KidsWatchPage(driver);
    logThreadState("Before initializing ConnectPage");
    this.connectPage = new ConnectPage(driver);
    logThreadState("After initializing some classes class");
    AllowNotificationPage allowNotificationPage = new AllowNotificationPage(this.driver);
    AllowLocationAccessPage allowLocationAccessPage = new AllowLocationAccessPage(this.driver);
    System.out.println("Starting before clicking skip in ConnectWatch on " + Thread.currentThread().getName());
    logThreadState("Before clicking skip in ConnectWatch");
    welcomeToTLifePage.clickSkipButton();
    System.out.println("Starting after clicking skip in ConnectWatch on " + Thread.currentThread().getName());
    logThreadState("after clicking skip in ConnectWatch");
    welcomeToTLifePage.clickOnLogInWithTMobileIDButton();
    loginPage.login(Configuration.getProperty("login_email2"), Configuration.getProperty("login_password"));
    if (getDevice("platformName").equalsIgnoreCase("ios")) {
        allowNotificationPage.notificationPermissionScreen();
        allowLocationAccessPage.locationPermissionScreen();
    } else {
        log(Status.INFO, "Not getting the expected Platform");
    }
    this.homePage.clickOnHomeTab();
    System.out.println("Completing before class in ConnectWatch on " + Thread.currentThread().getName());
    logThreadState("After completing before class");
}
2024-06-04 14:35:44,754 [TestNG-tests-2] INFO  com.tlife.connect.ConnectWatchTest - Before initializing driver - State of the thread: RUNNABLE
2024-06-04 14:35:44,755 [TestNG-tests-2] INFO  com.tlife.connect.ConnectWatchTest - Before initializing loginPage - State of the thread: RUNNABLE
2024-06-04 14:36:24,944 [TestNG-tests-2] INFO  com.tlife.connect.ConnectWatchTest - Before initializing welcomeToTLifePage - State of the thread: RUNNABLE
2024-06-04 14:36:30,447 [TestNG-tests-1] INFO  com.tlife.connect.ConnectPlacesTest - after loading login driver ConnectPlace - State of the thread: RUNNABLE
2024-06-04 14:36:32,179 [TestNG-tests-2] INFO  com.tlife.connect.ConnectWatchTest - Before initializing HomePage - State of the thread: RUNNABLE
2024-06-04 14:36:58,398 [TestNG-tests-2] INFO  com.tlife.connect.ConnectWatchTest - Before initializing KidsWatchPage - State of the thread: RUNNABLE
2024-06-04 14:37:06,122 [TestNG-tests-2] INFO  com.tlife.connect.ConnectWatchTest - Before initializing ConnectPage - State of the thread: RUNNABLE
2024-06-04 14:37:11,553 [TestNG-tests-2] INFO  com.tlife.connect.ConnectWatchTest - After initializing some classes class - State of the thread: RUNNABLE
2024-06-04 14:37:21,217 [TestNG-tests-2] INFO  com.tlife.connect.ConnectWatchTest - Before clicking skip in ConnectWatch - State of the thread: RUNNABLE
2024-06-04 14:37:23,031 [TestNG-tests-2] INFO  com.tlife.connect.ConnectWatchTest - after clicking skip in ConnectWatch - State of the thread: RUNNABLE
2024-06-04 14:38:16,314 [TestNG-tests-2] INFO  com.tlife.connect.ConnectWatchTest - After completing before class - State of the thread: RUNNABLE

Now if you see there are classes which are taking around 30-40 seconds to create the object, I am unable to understand what could be possible issues here?
Now because of this time my tests case are throwing idle timeout on BrowserStack, while checking the Appium logs, I did not see any commands coming.

What is your java-client version? Add more details…

My java client version is 8.6.0.
I am not sure but It feels Appium is get hanged after running certain suites, When I ran the code in debug mode, In the object creation I was getting “Collecting Data” for the variables that were there in the page. and They were just keep loading.

And one more we are able to run suites individually without any issue but whenever we are running all suites together then we are getting this issue.

For example: This is my XML file, I am running these all together then I am getting this issue but If I am running these individually or may 2 suites together then I am not getting this issue.

<suite-files>
   <suite-file path="testXML/core/parallelTest/HomeTestsParallel.xml" />
   <suite-file path="testXML/core/parallelTest/MeTestsParallel.xml" />
   <suite-file path="testXML/core/parallelTest/HsiRgaTestsParallel.xml" />
   <suite-file path="testXML/core/parallelTest/ConnectTestsParallel.xml" />
</suite-files>

It was some issue with running in parallel which was introduced in 8.5.1 and fixed in 9.2.0

see for details Appium Terminating Unexpectedly/Not Receiving Commands

To check you can change to version 8.5.0 (no much difference with 8.6.0). While with 9.2.0 you possibly need to update your code quite lot …

1 Like

Let me check first 8.5, on 8.6 I could also see memory usage is 3.6 gb just after 10 minutes.

if 8.5 doesn’t worked then will try to move to 9.2.0

Thanks @Aleksei

@Aleksei it worked on 8.5 as well as 9.2. Thank you so much.

@Aleksei Three questions:

  1. When I updated my 9.2.2, In some parallel sessions app is getting opened and as soon as it opened it got closed. Not happening with all the sessions. It was working fine with java client 8.6.0.

  2. I have migrated my code to UIAutomator2Options and XCuiTestOptions but even without these it was working fine like with normal capabilities. Would there be any issue now or in future if we don’t use Options instead of normal DesiredCapabilities.

  3. For 8.5.0, It is working fine with directly running from testng. But if we are running from maven command then session got created on Browserstack but it is not going inside Test classes.

Thanks in Advance.

  1. add more logs to see why app closes. ios/android/both happens?
  2. i think old way will also work. new way just look a bit more comfortable.
  3. add logs in all after/before annotations. check what suite you running with mvn command
mvn test -DsuiteName=suites/smoke/_Any_userChanges.xml
// check in pom
<plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>3.0.0</version>
                <configuration>
                    <suiteXmlFiles>
                        <suiteXmlFile>${suiteName}</suiteXmlFile>
                    </suiteXmlFiles>

@Aleksei Here are the Appium logs. We are on java client 9.2.2 and selenium is 4.20.0.
This is only happening in android, iOS is working fine.
App launched and closed in some sessions as soon as the session starts.
Appium logs (1).txt (219.5 KB)

We see in logs you trying to find element within 30 sec without luck (per your issue description app already closed at this time). But reason of app close looks like in logcat logs. Try to get them.

1 Like

@Aleksei Thank you very much, We checked our device logs, found some exceptions, raised it to the dev team, I think they will get it fixed.