Hello, Mykola. I have exactly the same problem, but nothing helps. That is, without changing anything in the code, my tests stopped passing. Out of 10 tests, one, the very last one, passes, the rest go to ‘garbage collected’.
I updated testng, appium java client, and selenium support to the latest versions (after that I started struggling with ‘garbage’ problem), then rolled back, and then tried to update one at a time, it didn’t help.
Now the pom file doesn’t list the latest versions, but it still doesn’t work.
When I run each of these tests individually, each one passes successfully.
I will give examples of code for one of the tests (the rest look about the same), a page object class, a pom file, and an XML file. And also the error that is displayed.
Could you please share your thoughts, any assumptions will be much appreciated. TYA.
This is the result of a test run (from Eclipse via Rin as > Testng suite).
For each failed test this is what is displayed:
java.lang.IllegalStateException: The element By.id: usernameParentField is not locatable anymore because its context has been garbage collected
at io.appium.java_client.pagefactory.AppiumElementLocator.lambda$findElement$0(AppiumElementLocator.java:154)
at java.base/java.util.Optional.orElseThrow(Optional.java:403)
at io.appium.java_client.pagefactory.AppiumElementLocator.findElement(AppiumElementLocator.java:153)
at io.appium.java_client.pagefactory.interceptors.InterceptorOfASingleElement.call(InterceptorOfASingleElement.java:64)
at io.appium.java_client.proxy.Interceptor.intercept(Interceptor.java:78)
at org.openqa.selenium.remote.RemoteWebElement$ByteBuddy$9yldCNC4.click(Unknown Source)
at dbp_TA_Mobile.pageObjects.android.LoginPageForm.setUsername(LoginPageForm.java:52)
at dbp_TA_Mobile.ASB_AppMobileTesting.Mobile_Smoke_ChangeContactInfoAndVerify.ChangeContactInfoAndVerifyTest(Mobile_Smoke_ChangeContactInfoAndVerify.java:21)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at org.testng.internal.invokers.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:139)
at org.testng.internal.invokers.TestInvoker.invokeMethod(TestInvoker.java:664)
at org.testng.internal.invokers.TestInvoker.invokeTestMethod(TestInvoker.java:227)
at org.testng.internal.invokers.MethodRunner.runInSequence(MethodRunner.java:50)
at org.testng.internal.invokers.TestInvoker$MethodInvocationAgent.invoke(TestInvoker.java:957)
at org.testng.internal.invokers.TestInvoker.invokeTestMethods(TestInvoker.java:200)
at org.testng.internal.invokers.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:148)
at org.testng.internal.invokers.TestMethodWorker.run(TestMethodWorker.java:128)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
at org.testng.TestRunner.privateRun(TestRunner.java:848)
at org.testng.TestRunner.run(TestRunner.java:621)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:443)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:437)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:397)
at org.testng.SuiteRunner.run(SuiteRunner.java:336)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:95)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1280)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1200)
at org.testng.TestNG.runSuites(TestNG.java:1114)
at org.testng.TestNG.run(TestNG.java:1082)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:115)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
This is my test class:
public class Mobile_Smoke_LoginAppASB extends AppiumConfTest {
@Test
public void LoginTest() throws MalformedURLException, InterruptedException {
LoginPageForm loginPageForm = new LoginPageForm(driver);
loginPageForm.setUsername("testerpro1");
loginPageForm.setPassword("Pa$$word8");
InstantBalScrForm instantBalScrForm = new InstantBalScrForm(driver);
instantBalScrForm.skipScreen();
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(80));
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("(//*[@text='Accounts'])")));
Assert.assertTrue(
driver.findElement(By.id("com.lorem.ipsum.integrationtwo:id/webViewTitleTextView"))
.isDisplayed());
}
@AfterClass
public void LogOutAsb() throws InterruptedException {
ProfileIconTooltip profileIconTooltip = new ProfileIconTooltip(driver);
profileIconTooltip.signOutAction();
}
}
This is my page object class:
public class LoginPageForm extends AndroidActions{
AndroidDriver driver;
public LoginPageForm(AndroidDriver driver)
{
super(driver);
this.driver = driver;
PageFactory.initElements(new AppiumFieldDecorator(driver), this);
}
@AndroidFindBy(xpath="//android.widget.RelativeLayout")
//@AndroidFindBy(id="com.lorem.ipsum.integrationtwo:id/text_input_layout")
private WebElement usernameParentField;
@AndroidFindBy(id="com.lorem.ipsum.integrationtwo:id/edit_text")
private WebElement usernameEditField;
@AndroidFindBy(id="com.lorem.ipsum.integrationtwo:id/text_input_layout")
private WebElement usernameInputField;
@AndroidFindBy(xpath="//*[@text='Enter your username']")
private WebElement usernameTextLocation;
@AndroidFindBy(xpath="//*[@text='Enter password']")
private WebElement passwordTextLocation;
@AndroidFindBy(id="com.lorem.ipsum.integrationtwo:id/button_action")
private WebElement submitButton;
@AndroidFindBy(id="com.lorem.ipsum.integrationtwo:id/logo")
private WebElement logoImage;
public void setUsername(String username)
{
usernameParentField.click();
usernameEditField.click();
usernameInputField.click();
usernameTextLocation.sendKeys(username);
}
public void setPassword(String password) throws InterruptedException
{
passwordTextLocation.sendKeys(password);
driver.hideKeyboard();
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(60));
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("com.lorem.ipsum.integrationtwo:id/button_action")));
submitButton.click();
}
}
Configuration (base) class:
public class AppiumConfTest extends AppiumUtils {
public AndroidDriver driver;
public AppiumDriverLocalService service;
@BeforeSuite (alwaysRun=true)
public void setUpAppium() throws IOException {
Properties prop = new Properties();
FileInputStream fis = new FileInputStream(System.getProperty("user.dir")+"//src//main//java//resources//data.properties");
prop.load(fis);
String ipAddress = System.getProperty("ipAddress");
String port = prop.getProperty("port");
service = startAppiumServer(ipAddress,Integer.parseInt(port));
UiAutomator2Options options = new UiAutomator2Options();
options.setDeviceName(prop.getProperty("AndroidDeviceName")); //emulator
options.setApp(System.getProperty("user.dir")+"//src//test//java//resources//app-qa.apk");
options.setCapability("autoGrantPermissions", "true");
driver = new AndroidDriver(service.getUrl(), options);
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(80));
}
@AfterSuite (alwaysRun=true)
public void tearDown() {
driver.quit();
service.stop();
}
}
Here is pom:
4.0.0
TA_Mobile
ASB_AppMobileTesting
0.0.1-SNAPSHOT
ASB_AppMobileTesting
http://www.example.com
UTF-8
17
io.appium
java-client
8.6.0
org.testng
testng
7.8.0
test
org.seleniumhq.selenium
selenium-support
4.11.0
org.apache.maven.plugins
maven-dependency-plugin
3.6.1
org.seleniumhq.selenium
selenium-remote-driver
4.13.0
com.aventstack
extentreports
5.1.0
commons-io
commons-io
2.13.0
maven-clean-plugin
3.3.1
maven-resources-plugin
3.3.1
maven-compiler-plugin
3.11.0
maven-surefire-plugin
3.1.2
testng.xml
maven-jar-plugin
3.3.0
maven-install-plugin
3.1.1
maven-deploy-plugin
3.1.1
maven-site-plugin
4.0.0-M10
maven-project-info-reports-plugin
3.4.5
Here is testng.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite name="Suite">
<test name="Mobile_Smoke_LoginAppASB">
<classes>
<class name="TA_Mobile.ASB_AppMobileTesting.Mobile_Smoke_LoginAppASB"/>
</classes>
</test>
<!-- Test -->
<test name="Mobile_Smoke_ViewTransfersScreen">
<classes>
<class name="TA_Mobile.ASB_AppMobileTesting.Mobile_Smoke_ViewTransfersScreen"/>
</classes>
</test>
<!-- Test -->
<test name="Mobile_Smoke_ChangeContactInfoAndVerify">
<classes>
<class name="TA_Mobile.ASB_AppMobileTesting.Mobile_Smoke_ChangeContactInfoAndVerify"/>
</classes>
</test>
<!-- Test -->
<test name="Mobile_Smoke_ViewMoneyMonitorScreen">
<classes>
<class name="TA_Mobile.ASB_AppMobileTesting.Mobile_Smoke_ViewMoneyMonitorScreen"/>
</classes>
</test>
<!-- Test -->
<test name="Mobile_Smoke_SignOutCheck">
<classes>
<class name="TA_Mobile.ASB_AppMobileTesting.Mobile_Smoke_SignOutCheck"/>
</classes>
</test>
<!-- Test -->
<test name="Mobile_Smoke_SetUpCustomAlertAndVerify">
<classes>
<class name="TA_Mobile.ASB_AppMobileTesting.Mobile_Smoke_SetUpCustomAlertAndVerify"/>
</classes>
</test>
<!-- Test -->
<test name="Mobile_Smoke_ViewDepositCheckScreen">
<classes>
<class name="TA_Mobile.ASB_AppMobileTesting.Mobile_Smoke_ViewDepositCheckScreen"/>
</classes>
</test>
<!-- Test -->
<test name="Mobile_Smoke_ViewCheckingAccount">
<classes>
<class name="TA_Mobile.ASB_AppMobileTesting.Mobile_Smoke_ViewCheckingAccount"/>
</classes>
</test>
<!-- Test -->
</suite>
<!-- Suite -->