# Page Object Initialisation is taking too much time

**URL:** <https://discuss.appium.io/t/page-object-initialisation-is-taking-too-much-time/42722>\
**Category:** Issues/Bugs\
**Created:** [June 4, 2024, 10:54am UTC](https://discuss.appium.io/t/page-object-initialisation-is-taking-too-much-time/42722 "2024-06-04T10:54:39Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![zaidakhter0080](https://discuss.appium.io/user_avatar/discuss.appium.io/zaidakhter0080/32/13159_2.png) [@zaidakhter0080](https://discuss.appium.io/u/zaidakhter0080)\
**Post date:** [June 4, 2024, 10:54am UTC](https://discuss.appium.io/t/page-object-initialisation-is-taking-too-much-time/42722/1 "2024-06-04T10:54:39Z")

</div>

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

```auto
@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.

```auto
@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.

---

<div class="post-metadata">

**Author:** ![Aleksei](https://discuss.appium.io/user_avatar/discuss.appium.io/aleksei/32/6267_2.png) [@Aleksei](https://discuss.appium.io/u/Aleksei)\
**Post date:** [June 4, 2024, 11:05am UTC](https://discuss.appium.io/t/page-object-initialisation-is-taking-too-much-time/42722/2 "2024-06-04T11:05:21Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![zaidakhter0080](https://discuss.appium.io/user_avatar/discuss.appium.io/zaidakhter0080/32/13159_2.png) [@zaidakhter0080](https://discuss.appium.io/u/zaidakhter0080)\
**Post date:** [June 4, 2024, 12:43pm UTC](https://discuss.appium.io/t/page-object-initialisation-is-taking-too-much-time/42722/3 "2024-06-04T12:43:40Z")

</div>

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.

```auto
<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>

```

---

<div class="post-metadata">

**Author:** ![Aleksei](https://discuss.appium.io/user_avatar/discuss.appium.io/aleksei/32/6267_2.png) [@Aleksei](https://discuss.appium.io/u/Aleksei)\
**Post date:** [June 4, 2024, 1:07pm UTC](https://discuss.appium.io/t/page-object-initialisation-is-taking-too-much-time/42722/4 "2024-06-04T13:07:07Z")

</div>

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](https://discuss.appium.io/t/appium-terminating-unexpectedly-not-receiving-commands/40782)

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 …

---

<div class="post-metadata">

**Author:** ![zaidakhter0080](https://discuss.appium.io/user_avatar/discuss.appium.io/zaidakhter0080/32/13159_2.png) [@zaidakhter0080](https://discuss.appium.io/u/zaidakhter0080)\
**Post date:** [June 4, 2024, 1:18pm UTC](https://discuss.appium.io/t/page-object-initialisation-is-taking-too-much-time/42722/5 "2024-06-04T13:18:29Z")

</div>

> [@Aleksei](#):
>
> an 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 …

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

 ![image](https://discuss.appium.io/uploads/default/original/2X/2/20e40a5eb43758fabfce8e62c5808e1742d29d20.png)

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

Thanks @Aleksei

---

<div class="post-metadata">

**Author:** ![zaidakhter0080](https://discuss.appium.io/user_avatar/discuss.appium.io/zaidakhter0080/32/13159_2.png) [@zaidakhter0080](https://discuss.appium.io/u/zaidakhter0080)\
**Post date:** [June 5, 2024, 6:24am UTC](https://discuss.appium.io/t/page-object-initialisation-is-taking-too-much-time/42722/6 "2024-06-05T06:24:27Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![zaidakhter0080](https://discuss.appium.io/user_avatar/discuss.appium.io/zaidakhter0080/32/13159_2.png) [@zaidakhter0080](https://discuss.appium.io/u/zaidakhter0080)\
**Post date:** [June 6, 2024, 4:28am UTC](https://discuss.appium.io/t/page-object-initialisation-is-taking-too-much-time/42722/7 "2024-06-06T04:28:56Z")

</div>

@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.

---

<div class="post-metadata">

**Author:** ![Aleksei](https://discuss.appium.io/user_avatar/discuss.appium.io/aleksei/32/6267_2.png) [@Aleksei](https://discuss.appium.io/u/Aleksei)\
**Post date:** [June 6, 2024, 7:50am UTC](https://discuss.appium.io/t/page-object-initialisation-is-taking-too-much-time/42722/8 "2024-06-06T07:50:36Z")

</div>

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

```auto
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>

```

---

<div class="post-metadata">

**Author:** ![zaidakhter0080](https://discuss.appium.io/user_avatar/discuss.appium.io/zaidakhter0080/32/13159_2.png) [@zaidakhter0080](https://discuss.appium.io/u/zaidakhter0080)\
**Post date:** [June 6, 2024, 5:03pm UTC](https://discuss.appium.io/t/page-object-initialisation-is-taking-too-much-time/42722/9 "2024-06-06T17:03:31Z")

</div>

@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](https://discuss.appium.io/uploads/short-url/hDPc2gW9EhEacGuf8b4ZISj3O5x.txt) (219.5 KB)

---

<div class="post-metadata">

**Author:** ![Aleksei](https://discuss.appium.io/user_avatar/discuss.appium.io/aleksei/32/6267_2.png) [@Aleksei](https://discuss.appium.io/u/Aleksei)\
**Post date:** [June 6, 2024, 5:34pm UTC](https://discuss.appium.io/t/page-object-initialisation-is-taking-too-much-time/42722/10 "2024-06-06T17:34:37Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![zaidakhter0080](https://discuss.appium.io/user_avatar/discuss.appium.io/zaidakhter0080/32/13159_2.png) [@zaidakhter0080](https://discuss.appium.io/u/zaidakhter0080)\
**Post date:** [June 9, 2024, 3:05pm UTC](https://discuss.appium.io/t/page-object-initialisation-is-taking-too-much-time/42722/11 "2024-06-09T15:05:27Z")

</div>

@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.
