Hello, I was able to run the appium test execution with testNG however when I executed it with mvn test it return the
Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
Caused by: org.openqa.selenium.WebDriverException:
Connection refused
this is how I initialize the driver
private static final ThreadLocal<AppiumDriver> driver = new ThreadLocal<>();
public static AppiumDriver getDriver() {
return driver.get();
}
public static void setDriver(AppiumDriver driver1) {
driver.set(driver1);
}
public static void initializeDriver() throws MalformedURLException, FileNotFoundException {
AppiumDriver driver = null;
MutableCapabilities capabilities = new UiAutomator2Options();
capabilities.setCapability("unicodeKeyboard", "true");
capabilities.setCapability("resetKeyboard", "true");
if (str[0].contains("platformName=ios")) {
capabilities = new XCUITestOptions();
}
URL url = new URL("http://127.0.0.1:4723/wd/hub");
String platformName = capabilities.getCapability("platformName").toString();
setPlatform(platformName);
System.out.println(platformName.equals("IOS"));
if (platformName.equals("IOS")) {
driver = new IOSDriver(url, capabilities);
}
if (platformName.equals("ANDROID")) {
driver = new AndroidDriver(url, capabilities);
}
setDriver(driver);
}
I cant share the details about the appium as im using the browserstack but when I ran it using the testNG or the run button in intellij my script is working fine. just the issue with the maven test with profile
I double the check the testng file path and they are pointed to correct path.
I did ran the sample project from browserstack with maven test -P sample-test and they are working fine.
here is my pom.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>ProjectName</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>ProjectName</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<surefire.version>2.19.1</surefire.version>
<surefire.plugin.version>3.0.0-M5</surefire.plugin.version>
<config.file>default</config.file>
<java.version>11</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
</properties>
<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.3.0</version>
<executions>
<execution>
<id>getClasspathFilenames</id>
<goals>
<goal>properties</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<skipTests>false</skipTests>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
<!-- <argLine>-javaagent:${com.browserstack:browserstack-java-sdk:jar}</argLine>-->
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
<profiles>
<profile>
<id>sample-test</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.5</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.appium/java-client -->
<!--dependency>
<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
<version>8.3.0</version>
</dependency-->
<!-- https://mvnrepository.com/artifact/io.appium/java-client -->
<dependency>
<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
<version>8.6.0</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.11.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.13.0</version>
</dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>com.browserstack</groupId>
<artifactId>browserstack-java-sdk</artifactId>
<version>LATEST</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.aventstack/extentreports -->
<dependency>
<groupId>com.aventstack</groupId>
<artifactId>extentreports</artifactId>
<version>5.0.9</version>
</dependency>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>6.1.0.jre8</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>2.0.5</version>
</dependency>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire</artifactId>
<version>3.2.5</version>
<type>pom</type>
</dependency>
<!-- https://mvnrepository.com/artifact/io.netty/netty-codec -->
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-codec</artifactId>
<version>4.1.106.Final</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.28</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>31.0.1-jre</version>
</dependency>
</dependencies>
</project>
Iâm also using the browserstack SDK.
So why im getting the connection refused pointed to http://127.0.0.1:4723/wd/hub?
Thanks