Overview
I have a code repository for automated (web and mobile app) UI testing using the following tools:
- Java 1.8 (w/ Maven)
- Selenium WebDriver
- Appium
- TestNG
Note: I am running the latest version of macOS as my operating system
The issue I am about to describe only applies for my iOS test suite and none of the other ones contained in my repository.
Here are the ways in which I am currently able to successfully run the test suite:
- I open up Eclipse or IntelliJ and run my code via the TestNG
.xml
file containing the included@Test
methods. This will kick off the test suite. (works) - I open up a terminal and navigate to the local repository on my machine and kick off the suite via Maven. I am using
maven-surefire-plugin
v2.22.1 to do this, and I pass in the name of the test suite as a flag to the maven command. Here is what that looks like.
pom.xml
:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
<inherited>true</inherited>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>${TestSuite.Name}</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
Then, for example, in terminal I could run any of these:
$ mvn clean test -DTestSuite.Name=RegressionIos.xml
$ mvn clean test -DTestSuite.Name=RegressionAndroid.xml
Problem
So since I can use either of the previously described methods to kick off the test suite, I would like to set up a Jenkins job using Maven to do basically what I described before. The problem I am having is this:
When I setup the Maven job in Jenkins and configure it with the appropriate parameters and environment variables, every test fails.
I get the following error message in the Jenkins console:
TestCases.I3002_RegisterUser_PasswordShouldHaveAtleastOneDigit:13453 Could not find a connected IOS device. org.openqa.selenium.WebDriverException: It is impossible to create a new session because 'createSession' which takes HttpClient, InputStream and long was not found or it is not accessible
Essentially, this happens in a method where I try to set the mobile driver to use. The method returns an object of type IOSDriver<MobileElement>
I have included a snippet below of this method where the error message comes from:
try {
Reporter.log("strAppiumPort"+strDeviceAppiumPort);
iosdriver = new IOSDriver<MobileElement>(new URL("http://127.0.0.1:"+strDeviceAppiumPort+"/wd/hub"), capabilities);
try {
if(iosdriver.findElement(By.id("Allow While Using App")).isDisplayed()) {
iosdriver.findElement(By.name("Allow While Using App")).click();
}
iosdriver.switchTo().alert().accept();
} catch (Exception a) {
iosdriver.switchTo().alert().accept();
}
try {
iosdriver.switchTo().alert().accept();
} catch (Exception e) {}
Reporter.log("Mobile App was loaded correctly on IOS Device");
} catch (Exception e) {
UpdateErrorMessageWithPivotalData(objDictionary, null, "Could not find a connected IOS device. " +e+ "-" + strMethodName);
}
The code may help you see more clearly what is going on, but the main question here is why is running Maven through Jenkins behaving differently than running it locally via IntelliJ or Eclipse? Please let me know if I am missing something crucial. Any and all help is appreciated.
In case I forgot to mention something or left out information you need to help answer this, please kindly let me know and I will do my best to provide that for you.