Closed Aman782739 closed 3 months ago
This does not seem to be issue with Appium but rather your handling of driver in code. Ensure that driver is properly initialised at the start of test.
Also Please update to latest Appium Java Client and use Driver specific options classes to initiate driver session instead of Desired Capabilities, and there is no need to pass /wd/hub if you are running Appium Server 2+. See the migration guide:- https://github.com/appium/java-client/blob/master/docs/v7-to-v8-migration-guide.md https://github.com/appium/java-client/blob/master/docs/v8-to-v9-migration-guide.md
Description
Create a maven project by using testng framework, try to run two test scripts together, first test case run successfully but when the second test case runs it gives error message.
Code To Reproduce Issue [ Good To Have ]
Base class - package com.Serviceapp.Testcase;
import java.awt.SplashScreen; import java.net.MalformedURLException; import java.net.URL;
import org.apache.log4j.Logger; import org.apache.log4j.PropertyConfigurator; import org.junit.runners.Parameterized.BeforeParam; import org.openqa.selenium.remote.DesiredCapabilities; import org.testng.annotations.AfterClass; import org.testng.annotations.AfterSuite; import org.testng.annotations.AfterTest; import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeMethod; import org.testng.annotations.BeforeSuite; import org.testng.annotations.BeforeTest; import org.testng.annotations.Optional; import org.testng.annotations.Parameters;
import com.Serviceapp.Utilities.Readconfiguration;
import io.appium.java_client.android.AndroidDriver; import io.appium.java_client.remote.MobileCapabilityType;
public class BaseClass {
// URL url = new URL("http://127.0.0.1:4723/wd/hub");
}
Test case 1
package com.Serviceapp.Testcase;
import java.io.IOException; import java.io.IOException; import java.time.Duration;
import org.openqa.selenium.By; import org.openqa.selenium.WebElement; import org.openqa.selenium.remote.HttpCommandExecutor; import org.openqa.selenium.support.ui.ExpectedCondition; import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.WebDriverWait; import org.testng.Assert; import org.testng.annotations.Test;
import com.Serviceapp.Pageobjects.Login_Page;
import com.Serviceapp.Utilities.Readconfiguration;
import io.appium.java_client.AppiumDriver; import io.appium.java_client.android.AndroidDriver;
public class TC_001_Login extends BaseClass {
}
Test case 2
package com.Serviceapp.Testcase;
import java.io.IOException; import java.io.IOException; import java.time.Duration;
import org.openqa.selenium.By; import org.openqa.selenium.WebElement; import org.openqa.selenium.remote.HttpCommandExecutor; import org.openqa.selenium.support.ui.ExpectedCondition; import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.WebDriverWait; import org.testng.Assert; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test;
import com.Serviceapp.Pageobjects.Login_Page; import com.Serviceapp.Pageobjects.Verify_OTP_Page; import com.Serviceapp.Utilities.Readconfiguration;
import io.appium.java_client.AppiumDriver; import io.appium.java_client.android.AndroidDriver;
public class TC_002_VerifyOTP extends BaseClass {
// vp.Change_number(); // logger.info("User click on number change option"); // lp.setmobilenumberfield(number2); // logger.info("user has enter number successfully"); // lp.setsubmitbuttononlogin(); // logger.info("User click on submit button successfully"); // //Thread.sleep(10000); // lp.VerifyOTPPage(); // logger.info("User redirect on verify OTP page successfully"); } catch (Exception e) { System.out.println("Exception is " + e.getMessage()); } }
}
Testng.xml
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
Exception Stacktraces
[RemoteTestNG] detected TestNG version 7.7.1 SLF4J: No SLF4J providers were found. SLF4J: Defaulting to no-operation (NOP) logger implementation SLF4J: See https://www.slf4j.org/codes.html#noProviders for further details. Driver start 2024-07-10 23:49:02 INFO class:54 - Build has been run successfully Test1 2024-07-10 23:49:18 INFO class:37 - user comes in login page 2024-07-10 23:49:18 INFO class:40 - user has enter number successfully 2024-07-10 23:49:19 INFO class:42 - User click on submit button successfully 2024-07-10 23:49:43 INFO class:45 - User redirect on verify OTP page successfully Test2 Exception is Cannot invoke "io.appium.java_client.android.AndroidDriver.navigate()" because "this.driver" is null driver close
=============================================== Suite Total tests run: 2, Passes: 2, Failures: 0, Skips: 0