Powemockito constructor testing problems - java

Hej I have some problems with TestNG and powerMockito 1.5.x I tried with 1.5.5 and 1.5.6. The problem is when I try to verify a constructor that is not empty.
I've check quite some examples around about extending from PowerMockTestCase and so on but they do not seem to work for me.
package com.cdev.common;
public class TestSubject {
String data;
String context;
public TestSubject()
{
this.data = "Mock!!";
this.context = "PowerMockito";
}
public TestSubject(String data)
{
this.data = data;
this.context = "PowerMockito";
}
public TestSubject(String data,String context)
{
this.data = data;
this.context = context;
}
public String getData()
{
throw new UnsupportedOperationException();
}
public String getContext()
{
throw new UnsupportedOperationException();
}
public boolean isNew()
{
throw new UnsupportedOperationException();
}
}
This is the testNG test:
package com.cdev.common.test;
import com.cdev.common.*;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.testng.Assert;
import org.testng.annotations.Test;
#PrepareForTest({TestSubject.class})
public class TestSubjectTest{
#Test
public void TestSubject() throws Exception
{
System.out.println("======== Test ==================");
TestSubject mockTestSubject = PowerMockito.mock(TestSubject.class);
PowerMockito.whenNew(TestSubject.class).withArguments("A", "B").thenReturn(mockTestSubject);
PowerMockito.when(mockTestSubject.getData()).thenReturn("A");
PowerMockito.when(mockTestSubject.getContext()).thenReturn("B");
PowerMockito.when(mockTestSubject.isNew()).thenReturn(true);
PowerMockito.verifyNew(TestSubject.class).withArguments("A", "B");
TestSubject lala = new TestSubject("A","B");
System.out.println(lala.getData());
System.out.println(lala.isNew());
Assert.assertTrue(lala.getData().equals("A"), "Not equal");
}
}
This gives me this output:
[TestNG] Running:
/tmp/testng-eclipse--2099806353/testng-customsuite.xml
======== Test ==================
FAILED: TestSubject
java.lang.AssertionError: Wanted but not invoked com.cdev.common.TestSubject(
"A",
"B"
);
Actually, there were zero interactions with this mock.
at org.powermock.api.mockito.internal.invocation.InvocationControlAssertionError.throwAssertionErrorForNewSubstitutionFailure(InvocationControlAssertionError.java:93)
at org.powermock.api.mockito.internal.verification.DefaultConstructorArgumentsVerfication.invokeSubstitute(DefaultConstructorArgumentsVerfication.java:51)
at org.powermock.api.mockito.internal.verification.DefaultConstructorArgumentsVerfication.withArguments(DefaultConstructorArgumentsVerfication.java:44)
at com.cdev.common.test.TestSubjectTest.TestSubject(TestSubjectTest.java:32)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:714)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
at org.testng.TestRunner.privateRun(TestRunner.java:767)
at org.testng.TestRunner.run(TestRunner.java:617)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
at org.testng.SuiteRunner.run(SuiteRunner.java:240)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
at org.testng.TestNG.run(TestNG.java:1057)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)
===============================================
Default test
Tests run: 1, Failures: 1, Skips: 0
===============================================
===============================================
Default suite
Total tests run: 1, Failures: 1, Skips: 0
===============================================
[TestNG] Time taken by org.testng.reporters.SuiteHTMLReporter#6d9c638: 18 ms
[TestNG] Time taken by org.testng.reporters.EmailableReporter2#2401f4c3: 6 ms
[TestNG] Time taken by org.testng.reporters.JUnitReportReporter#5d22bbb7: 3 ms
[TestNG] Time taken by org.testng.reporters.jq.Main#3d012ddd: 31 ms
[TestNG] Time taken by [FailedReporter passed=0 failed=0 skipped=0]: 2 ms
[TestNG] Time taken by org.testng.reporters.XMLReporter#1175e2db: 5 ms

You need to move the verifyNew call to after the invocation has been made:
TestSubject lala = new TestSubject("A","B");
PowerMockito.verifyNew(TestSubject.class).withArguments("A", "B");

Following your instructions:
#Test
public void TestSubject() throws Exception
{
System.out.println("======== Test ==================");
TestSubject mockTestSubject = PowerMockito.mock(TestSubject.class);
PowerMockito.whenNew(TestSubject.class).withArguments("A", "B").thenReturn(mockTestSubject);
PowerMockito.when(mockTestSubject.getData()).thenReturn("A");
PowerMockito.when(mockTestSubject.getContext()).thenReturn("B");
PowerMockito.when(mockTestSubject.isNew()).thenReturn(true);
**TestSubject lala = new TestSubject("A","B");
PowerMockito.verifyNew(TestSubject.class).withArguments("A", "B");**
System.out.println(lala.getData());
System.out.println(lala.isNew());
Assert.assertTrue(lala.getData().equals("A"), "Not equal");
}
The output:
[TestNG] Running:
/tmp/testng-eclipse--349458877/testng-customsuite.xml
======== Test ==================
FAILED: TestSubject
java.lang.AssertionError: Wanted but not invoked com.cdev.common.TestSubject(
"A",
"B"
);
Actually, there were zero interactions with this mock.
at org.powermock.api.mockito.internal.invocation.InvocationControlAssertionError.throwAssertionErrorForNewSubstitutionFailure(InvocationControlAssertionError.java:93)
at org.powermock.api.mockito.internal.verification.DefaultConstructorArgumentsVerfication.invokeSubstitute(DefaultConstructorArgumentsVerfication.java:51)
at org.powermock.api.mockito.internal.verification.DefaultConstructorArgumentsVerfication.withArguments(DefaultConstructorArgumentsVerfication.java:44)
at com.cdev.common.test.TestSubjectTest.TestSubject(TestSubjectTest.java:28)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:714)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
at org.testng.TestRunner.privateRun(TestRunner.java:767)
at org.testng.TestRunner.run(TestRunner.java:617)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
at org.testng.SuiteRunner.run(SuiteRunner.java:240)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
at org.testng.TestNG.run(TestNG.java:1057)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)
===============================================
Default test
Tests run: 1, Failures: 1, Skips: 0
===============================================
===============================================
Default suite
Total tests run: 1, Failures: 1, Skips: 0
===============================================
[TestNG] Time taken by org.testng.reporters.SuiteHTMLReporter#6d9c638: 36 ms
[TestNG] Time taken by org.testng.reporters.EmailableReporter2#2401f4c3: 8 ms
[TestNG] Time taken by org.testng.reporters.JUnitReportReporter#5d22bbb7: 13 ms
[TestNG] Time taken by org.testng.reporters.jq.Main#3d012ddd: 45 ms
[TestNG] Time taken by [FailedReporter passed=0 failed=0 skipped=0]: 4 ms
[TestNG] Time taken by org.testng.reporters.XMLReporter#1175e2db: 5 ms

Related

java.net.ConnectException: Failed to connect to localhost/0:0:0:0:0:0:0:1:3000

I build a http server with http://sparkjava.com/ that validate files, if it is valid or not.
The code is very simple:
post("/pdf", (req, res) -> {
if (req.headers("application/pdf") == null) {
res.status(400);
PdfState state = new PdfState();
state.SetIsValid(false);
return JsonUtil.toJson(state);
}
InputStream stream = new ByteArrayInputStream(req.bodyAsBytes());
PdfState state = pdf.validate(stream);
res.type("application/json");
return JsonUtil.toJson(state);
});
Then I want to write a unit test and choose the http client library http://square.github.io/okhttp/.
The test function looks as follow:
public void IsPdfContentRequestValid_StreamValidPdfContent_ExpectJsonSuccess() throws Exception {
File file = new File("/Volumes/Dev/java/inspector/files/pass.pdf");
Request request = new Request.Builder()
.url("http://127.0.0.1:3000/pdf")
.addHeader("Content-type", "application/pdf")
.post(RequestBody.create(MEDIA_TYPE_MARKDOWN, file))
.build();
Response response = client.newCall(request).execute();
if (!response.isSuccessful()) throw new IOException("Unexpected code " + response);
System.out.println(response.body().string());
}
When I run the test, it complains:
java.net.ConnectException: Failed to connect to /127.0.0.1:3000
What is wrong with OKClient?
Update
That is the whole error:
[TestNG] Running:
/Users/developer/Library/Caches/IntelliJIdea2016.2/temp-testng-customsuite.xml
0 [Thread-1] INFO org.eclipse.jetty.util.log - Logging initialized #1554ms
java.net.ConnectException: Failed to connect to /127.0.0.1:3000
at okhttp3.internal.connection.RealConnection.connectSocket(RealConnection.java:189)
at okhttp3.internal.connection.RealConnection.buildConnection(RealConnection.java:173)
at okhttp3.internal.connection.RealConnection.connect(RealConnection.java:114)
at okhttp3.internal.connection.StreamAllocation.findConnection(StreamAllocation.java:193)
at okhttp3.internal.connection.StreamAllocation.findHealthyConnection(StreamAllocation.java:129)
at okhttp3.internal.connection.StreamAllocation.newStream(StreamAllocation.java:98)
at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:42)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:109)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:124)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:170)
at okhttp3.RealCall.execute(RealCall.java:60)
at com.cloudfirmation.inspector.controller.PdfControllerTest.IsPdfContentRequestValid_StreamValidPdfContent_ExpectJsonSuccess(PdfControllerTest.java:36)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:100)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:646)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:811)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1129)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:129)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:112)
at org.testng.TestRunner.privateRun(TestRunner.java:746)
at org.testng.TestRunner.run(TestRunner.java:600)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:366)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:361)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:319)
at org.testng.SuiteRunner.run(SuiteRunner.java:268)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1264)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1189)
at org.testng.TestNG.runSuites(TestNG.java:1104)
at org.testng.TestNG.run(TestNG.java:1076)
at org.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:72)
at org.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:124)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
56 [main] INFO spark.embeddedserver.jetty.EmbeddedJettyServer - >>> Spark shutting down ...
56 [main] INFO spark.embeddedserver.jetty.EmbeddedJettyServer - done
===============================================
Default Suite
Total tests run: 1, Failures: 1, Skips: 0
===============================================
I think the server is running when start the test.

java.lang.ExceptionInInitializerError while running testng selenium testcase

This is my testng class
/**
*
*/
package com.igate.test;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import com.igate.framework.BaseTestCase;
import com.igate.framework.ExecutionObject;
import com.igate.framework.GalenTestLayout;
import com.igate.framework.Reporter;
import com.igate.framework.WebDriver;
#Test
public class FleetBooking extends BaseTestCase {
public FleetBooking() {
super();
}
public ExecutionObject exeObj;
#BeforeClass
public void createDoc() throws Exception {
Reporter.createDoc(deviceDetail);
exeObj = new ExecutionObject();
}
public void test_case1() throws Exception {
WebDriver oWD = null;
if (runType.contains("mobile")) {
oWD = new WebDriver(ObjMap, caps, deviceDetail);
} else if (runType.contains("desktop")) {
oWD = new WebDriver(ObjMap, caps);
}
try {
oWD.startTestCase("test_casen1", exeObj);
oWD.launchURL("https://fleet.igate.com/fleet/Login.htm");
oWD.wait("MW");
oWD.setPage("LoginPage");
oWD.enterText("username", "831457");
RemoteWebDriver driver = oWD.getDriver();
System.out.println(" returned driver "+driver);
GalenTestLayout layout = new GalenTestLayout();
layout.testLayout(driver, "fleet");
//oWD.layoutTest("fleet");
/*try {
System.out.println("layout under process");
LayoutReport layoutReport = Galen.checkLayout(driver, "gspecs/fleet.gspec",
Arrays.asList("mobile","desktop"));
// Creating a list of tests
List<GalenTestInfo> tests = new LinkedList<GalenTestInfo>();
// Creating an object that will contain the information about the
// test
GalenTestInfo test = GalenTestInfo
.fromString("Login page on mobile device test");
// Adding layout report to the test report
test.getReport().layout(layoutReport,
"check layout on mobile device");
tests.add(test);
System.out.println("report created in reports folder");
// Exporting all test reports to html
new HtmlReportBuilder().build(tests,
"reports");
} catch (IOException e) {
System.out.println("error 1"+e.getMessage());
e.printStackTrace();
}*/
oWD.endTestCase();
} catch (Exception e) {
System.out.println("SYSOUT - exception : " + e);
oWD.endTestCase();
}
}
}
Here is my GalenTestLayout class
package com.igate.framework;
import java.io.IOException;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.Test;
import com.galenframework.api.Galen;
import com.galenframework.reports.GalenTestInfo;
import com.galenframework.reports.HtmlReportBuilder;
import com.galenframework.reports.model.LayoutReport;
import com.galenframework.testng.GalenTestNgTestBase;
public class GalenTestLayout {
public RemoteWebDriver driver;
#Test
public void testLayout(RemoteWebDriver driver,String gspec) {
System.out.println("driver in layout method "+driver);
LayoutReport layoutReport;
try {
System.out.println("layout under process");
layoutReport = Galen.checkLayout(driver, "gspecs/fleet.gspec",
Arrays.asList("mobile","desktop"));
// Creating a list of tests
List<GalenTestInfo> tests = new LinkedList<GalenTestInfo>();
// Creating an object that will contain the information about the
// test
GalenTestInfo test = GalenTestInfo
.fromString("Login page on mobile device test");
// Adding layout report to the test report
test.getReport().layout(layoutReport,
"check layout on mobile device");
tests.add(test);
System.out.println("report created in reports folder");
// Exporting all test reports to html
new HtmlReportBuilder().build(tests,
"reports");
} catch (IOException e) {
System.out.println("error in layout method "+e.getMessage());
e.printStackTrace();
}
}
}
I am getting error in My FleetBooking Class at
**GalenTestLayout layout = new GalenTestLayout();
layout.testLayout(driver, "fleet");**
These are my error logs
[TestNG] Running:
C:\Users\pmadge\AppData\Local\Temp\testng-eclipse-1054887367\testng-customsuite.xml
bin compiled version 1.1
2016-04-26 20:14:08 INFO BaseTestCase:134 - Framework assigned in Internal Path : - Successfull
device size :3
*************taken device*********** 0
increasing count :1
looped i :0
Starting ChromeDriver 2.20.353145 (343b531d31eeb933ec778dbcf7081628a1396067) on port 20891
Only local connections are allowed.
2016-04-26 20:14:10 INFO WebDriver:739 - StartTestCase - test_casen1 - Successfull
2016-04-26 20:14:10 INFO WebDriver:181 - Launch URL - : https://fleet.igate.com/fleet/Login.htm - Successfull
########$$$$$$$$$$%%%%%%%%%%%%%% ::::::::::::: null
2016-04-26 20:14:15 INFO WebDriver:155 - SetPage - : LoginPage - Successfull
2016-04-26 20:14:17 INFO WebDriver:610 - GetControl - Action Performed : username - Successfull
2016-04-26 20:14:17 INFO WebDriver:622 - FetchControl - Action Performed - Successfull
2016-04-26 20:14:19 INFO WebDriver:612 - GetControl - WebElement - Successfull
2016-04-26 20:14:19 INFO WebDriver:206 - enterText - in: username value: 831457 - Successfull
returned driver ChromeDriver: chrome on XP (92edabdf1bacb26c65c50ac893f7da3f)
driver in layout method ChromeDriver: chrome on XP (92edabdf1bacb26c65c50ac893f7da3f)
layout under process
FAILED: test_case1
java.lang.ExceptionInInitializerError
at com.galenframework.rainbow4j.Rainbow4J.loadImage(Rainbow4J.java:286)
at com.galenframework.utils.GalenUtils.takeScreenshot(GalenUtils.java:314)
at com.galenframework.browser.SeleniumBrowser.makeSimpleScreenshot(SeleniumBrowser.java:97)
at com.galenframework.browser.SeleniumBrowser.createScreenshot(SeleniumBrowser.java:90)
at com.galenframework.page.selenium.SeleniumPage.createScreenshot(SeleniumPage.java:161)
at com.galenframework.api.Galen.checkLayoutForPage(Galen.java:100)
at com.galenframework.api.Galen.checkLayout(Galen.java:86)
at com.galenframework.api.Galen.checkLayout(Galen.java:69)
at com.galenframework.api.Galen.checkLayout(Galen.java:59)
at com.galenframework.api.Galen.checkLayout(Galen.java:154)
at com.galenframework.api.Galen.checkLayout(Galen.java:128)
at com.igate.framework.GalenTestLayout.testLayout(GalenTestLayout.java:31)
at com.igate.test.FleetBooking.test_case1(FleetBooking.java:63)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:714)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
at org.testng.TestRunner.privateRun(TestRunner.java:767)
at org.testng.TestRunner.run(TestRunner.java:617)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
at org.testng.SuiteRunner.run(SuiteRunner.java:240)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
at org.testng.TestNG.run(TestNG.java:1057)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)
Caused by: java.lang.SecurityException: sealing violation: can't seal package com.sun.media.imageioimpl.plugins.jpeg2000: already loaded
at java.net.URLClassLoader.getAndVerifyPackage(Unknown Source)
at java.net.URLClassLoader.definePackageInternal(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at java.util.ServiceLoader$LazyIterator.nextService(Unknown Source)
at java.util.ServiceLoader$LazyIterator.next(Unknown Source)
at java.util.ServiceLoader$1.next(Unknown Source)
at javax.imageio.spi.IIORegistry.registerApplicationClasspathSpis(Unknown Source)
at javax.imageio.spi.IIORegistry.<init>(Unknown Source)
at javax.imageio.spi.IIORegistry.getDefaultInstance(Unknown Source)
at javax.imageio.ImageIO.<clinit>(Unknown Source)
... 37 more
===============================================
Default test
Tests run: 1, Failures: 1, Skips: 0
===============================================
===============================================
Default suite
Total tests run: 1, Failures: 1, Skips: 0
===============================================
[TestNG] Time taken by org.testng.reporters.jq.Main#1ed3c8d: 21 ms
[TestNG] Time taken by org.testng.reporters.SuiteHTMLReporter#2efe5d: 76 ms
[TestNG] Time taken by [FailedReporter passed=0 failed=0 skipped=0]: 4 ms
[TestNG] Time taken by org.testng.reporters.JUnitReportReporter#1f95c5d: 36 ms
[TestNG] Time taken by org.testng.reporters.XMLReporter#a570f: 4 ms
[TestNG] Time taken by org.testng.reporters.EmailableReporter2#81f4dc: 3 ms
My chrome driver is initialized properly as u can see in my output logs.
When I run the functionality layout.testLayout(driver, "fleet"); as a independent class its running , but when I calling this method from testng class I am getting exception . I tried many alternatives but still it is giving me error
The error is:
Caused by: java.lang.SecurityException: sealing violation: can't seal package com.sun.media.imageioimpl.plugins.jpeg2000: already loaded
at java.net.URLClassLoader.getAndVerifyPackage(Unknown Source)
So that means you try to seal already loaded package. That package is in a file like jai_imageio-*.jar. Check if you have two similar jars and remove one of them.

TestNG and Powermockito - cannot mock static void

I can't get Powermock work with TestNG. The same code adjusted to JUnit works fine, but somehow in TestNG it fails.
TestNG version is 6.8.21
Powermockito version is 1.6.1
package p;
import org.mockito.MockitoAnnotations;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import org.testng.Assert;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import static org.powermock.api.mockito.PowerMockito.mockStatic;
#PrepareForTest({FooTest.class})
public class FooTest {
#BeforeTest
public void setup() {
mockStatic(FooTest.class);
MockitoAnnotations.initMocks(this);
}
#Test
public void test() throws Exception {
PowerMockito.doNothing().when(FooTest.class,"foo");
FooTest.foo();
Assert.assertEquals(1, 1);
}
public static void foo() throws Exception {
throw new Exception("huh?");
}
}
The exception I get is on the when method:
java.lang.Exception: huh?
at p.FooTest.foo(FooTest.java:32)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.powermock.reflect.internal.WhiteboxImpl.performMethodInvocation(WhiteboxImpl.java:1873)
at org.powermock.reflect.internal.WhiteboxImpl.doInvokeMethod(WhiteboxImpl.java:773)
at org.powermock.reflect.internal.WhiteboxImpl.invokeMethod(WhiteboxImpl.java:753)
at org.powermock.reflect.Whitebox.invokeMethod(Whitebox.java:466)
at org.powermock.api.mockito.internal.expectation.PowerMockitoStubberImpl.when(PowerMockitoStubberImpl.java:106)
at p.FooTest.test(FooTest.java:25)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:85)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:696)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:882)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1189)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:124)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:108)
at org.testng.TestRunner.privateRun(TestRunner.java:767)
at org.testng.TestRunner.run(TestRunner.java:617)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:348)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:343)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:305)
at org.testng.SuiteRunner.run(SuiteRunner.java:254)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
at org.testng.TestNG.run(TestNG.java:1057)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)
at org.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:125)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.intellij.rt.execution.CommandLineWrapper.main(CommandLineWrapper.java:130)
===============================================
Custom suite
Total tests run: 1, Failures: 1, Skips: 0
===============================================
So what am I missing here?
I suspect this may be the same issue and solution as this question. In other words make sure you are using the org.powermock.modules.testng.PowerMockObjectFactory. But as #fge says, you should #PrepareForTest the class containing the static method(s) to mock, which should not be the test class itself...

alwaysRun parameter in TestNG

Can someone please explain me when #AfterMethod(alwaysRun = true) should execute. Will it execute when #test method is skipped. In documentation is written so, but I have observed different behavior.
Example:
Code:
public class testing{
#Test
public void testCase2(){
System.out.println("in test case 2");
Assert.assertEquals(1,2);
}
#Test(dependsOnMethods = { "testCase2" })
public void testcase3(){
System.out.println("OK");
}
#AfterMethod(alwaysRun = true)
public void afterMethod2() {
System.out.println("in afterMethod");
}
}
Output:
in test case 2
in afterMethod
FAILED: testCase2
java.lang.AssertionError: expected [2] but found [1]
at org.testng.Assert.fail(Assert.java:94)
at org.testng.Assert.failNotEquals(Assert.java:494)
at org.testng.Assert.assertEquals(Assert.java:123)
at org.testng.Assert.assertEquals(Assert.java:370)
at org.testng.Assert.assertEquals(Assert.java:380)
at app.testing.testCase2(testing.java:22)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:714)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
at org.testng.TestRunner.privateRun(TestRunner.java:767)
at org.testng.TestRunner.run(TestRunner.java:617)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
at org.testng.SuiteRunner.run(SuiteRunner.java:240)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
at org.testng.TestNG.run(TestNG.java:1057)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)
SKIPPED: testcase3
===============================================
Default test
Tests run: 2, Failures: 1, Skips: 1
===============================================
===============================================
Default suite
Total tests run: 2, Failures: 1, Skips: 1
===============================================
Shouldn't #After method be executed twice, also after skipped #Test?
Thanks for answer in advance :)
The documentation says
For after methods (afterSuite, afterClass, ...): If set to true, this
configuration method will be run even if one or more methods invoked
previously failed or was skipped.
So I think it should execute after skipped test method.
Even though the documentation has stated that
For after methods (afterSuite, afterClass, ...): If set to true, this
configuration method will be run even if one or more methods invoked
previously failed or was skipped.
However, in configfailurepolicy annotations, the following is stated when there's any test failures
configfailurepolicy: Whether TestNG should continue to execute the
remaining tests in the suite or skip them if an #before* method fails.
Default behavior is skip.
BTW, #AfterMethod is not a test method but a configuration one.
alwaysRun on #Test: A method (say method2) having this testng attribute willalways run even if the method on which it depends (dependsOnMethods="Method1") failed and it is referred as soft dependency in testNG terminology.
alwaysRun on #Before or #After annotated methods: if #BeforeSuite fails and #BeforeClass has alwaysRun = true then it won't be skipped. (although test case may get skipped)
public class TestAlwaysRun{
#BeforeSuite
public void toFailBeforeSuite() {
System.out.println("I'm beforeSuite, I will fail");
throw new RuntimeException();
}
#BeforeTest(alwaysRun = true)
public void toFailBeforeTest() {
System.out.println("BUG: I'm beforeTest, I will fail");
throw new RuntimeException();
}
#BeforeClass
public void toFailBeforeClass() {
System.out.println("BUG: I'm beforeClass, I will fail");
throw new RuntimeException();
}
#BeforeMethod(alwaysRun = true)
public void toFailBeforeMethod() {
System.out.println("BUG: I'm beforeMethod, I will fail");
//throw new RuntimeException();
}
#Test
public void tetsCase() {
System.out.println("I'm a Test Case");
}
}
[RemoteTestNG] detected TestNG version 7.4.0
I'm beforeSuite, I will fail
BUG: I'm beforeTest, I will fail
BUG: I'm beforeMethod, I will fail
FAILED CONFIGURATION: #BeforeTest toFailBeforeTest
java.lang.RuntimeException
at testngTutorial.ABC.toFailBeforeTest(ABC.java:20)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:133)
at org.testng.internal.MethodInvocationHelper.invokeMethodConsideringTimeout(MethodInvocationHelper.java:62)
at org.testng.internal.ConfigInvoker.invokeConfigurationMethod(ConfigInvoker.java:385)
at org.testng.internal.ConfigInvoker.invokeConfigurations(ConfigInvoker.java:321)
at org.testng.TestRunner.invokeTestConfigurations(TestRunner.java:637)
at org.testng.TestRunner.beforeRun(TestRunner.java:627)
at org.testng.TestRunner.run(TestRunner.java:589)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:377)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:371)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:332)
at org.testng.SuiteRunner.run(SuiteRunner.java:276)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:96)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1212)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1134)
at org.testng.TestNG.runSuites(TestNG.java:1063)
at org.testng.TestNG.run(TestNG.java:1031)
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)
FAILED CONFIGURATION: #BeforeSuite toFailBeforeSuite
java.lang.RuntimeException
at testngTutorial.ABC.toFailBeforeSuite(ABC.java:14)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:133)
at org.testng.internal.MethodInvocationHelper.invokeMethodConsideringTimeout(MethodInvocationHelper.java:62)
at org.testng.internal.ConfigInvoker.invokeConfigurationMethod(ConfigInvoker.java:385)
at org.testng.internal.ConfigInvoker.invokeConfigurations(ConfigInvoker.java:321)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:317)
at org.testng.SuiteRunner.run(SuiteRunner.java:276)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:96)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1212)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1134)
at org.testng.TestNG.runSuites(TestNG.java:1063)
at org.testng.TestNG.run(TestNG.java:1031)
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)
SKIPPED: tetsCase
java.lang.RuntimeException
at testngTutorial.ABC.toFailBeforeTest(ABC.java:20)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:133)
at org.testng.internal.MethodInvocationHelper.invokeMethodConsideringTimeout(MethodInvocationHelper.java:62)
at org.testng.internal.ConfigInvoker.invokeConfigurationMethod(ConfigInvoker.java:385)
at org.testng.internal.ConfigInvoker.invokeConfigurations(ConfigInvoker.java:321)
at org.testng.TestRunner.invokeTestConfigurations(TestRunner.java:637)
at org.testng.TestRunner.beforeRun(TestRunner.java:627)
at org.testng.TestRunner.run(TestRunner.java:589)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:377)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:371)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:332)
at org.testng.SuiteRunner.run(SuiteRunner.java:276)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:96)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1212)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1134)
at org.testng.TestNG.runSuites(TestNG.java:1063)
at org.testng.TestNG.run(TestNG.java:1031)
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)
===============================================
Default test
Tests run: 1, Failures: 0, Skips: 1
Configuration Failures: 2, Skips: 0
===============================================
===============================================
Default suite
Total tests run: 1, Passes: 0, Failures: 0, Skips: 1
Configuration Failures: 2, Skips: 0
===============================================
I think here you have given dependsOnMethods = { "testCase2" }
That is why your second test itself isn't triggered and so aftermethod doesn't execute.
Please remove that depends and check ..it will execute aftermethod twice.

AppiumDriver gives null pointer exception

In my appium + testng app, what I have put is:
package com.tribehr.ios.ios_test;
import java.net.URL;
import io.appium.java_client.AppiumDriver;
import org.junit.After;
import org.junit.Before;
import org.openqa.selenium.*;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.Test;
import org.testng.Assert;
public class NewTest {
private AppiumDriver driver;
#Before
public void setUp() throws Exception {
// set up appium
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
capabilities.setCapability("platformVersion", "7.1");
capabilities.setCapability("platformName", "iOS");
capabilities.setCapability("deviceName", "iPhone Simulator");
capabilities.setCapability("app", "/path to .app");
driver = new AppiumDriver(new URL("http://0.0.0.0:4723/wd/hub"), capabilities);
}
#After
public void tearDown() throws Exception {
driver.quit();
}
#Test
public void Test1() throws Exception {
driver.findElement(By.xpath("//UIAApplication[1]/UIAWindow[1]/UIATextField[1]/UIATextField[1]"));
}
}
The following stack trace is given:
[TestNG] Running:
/private/var/folders/hh/r5f5h1lx23g6drvycy03g29w0000gs/T/testng-eclipse--1877089062/testng-customsuite.xml
FAILED: Test1
java.lang.NullPointerException
at com.tribehr.ios.ios_test.NewTest.Test1(NewTest.java:39)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:714)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
at org.testng.TestRunner.privateRun(TestRunner.java:767)
at org.testng.TestRunner.run(TestRunner.java:617)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
at org.testng.SuiteRunner.run(SuiteRunner.java:240)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
at org.testng.TestNG.run(TestNG.java:1057)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)
===============================================
Default test
Tests run: 1, Failures: 1, Skips: 0
===============================================
===============================================
Default suite
Total tests run: 1, Failures: 1, Skips: 0
===============================================
[TestNG] Time taken by org.testng.reporters.SuiteHTMLReporter#7b1d7fff: 23 ms
[TestNG] Time taken by org.testng.reporters.jq.Main#7b3300e5: 28 ms
[TestNG] Time taken by [FailedReporter passed=0 failed=0 skipped=0]: 2 ms
[TestNG] Time taken by org.testng.reporters.EmailableReporter2#2ff5659e: 4 ms
[TestNG] Time taken by org.testng.reporters.XMLReporter#43556938: 4 ms
[TestNG] Time taken by org.testng.reporters.JUnitReportReporter#57fa26b7: 2 ms
It seems like the Appium server is not instantiated successfully with the capability, but this is almost a copy-and-paste of examples online - and I cannot figure out what goes wrong..
Surround "driver" with an if statement, to understand whether it == null.
if(driver!=null){
System.out.println("driver does not == null");
driver.findElement(By.xpath("YourXpath"));
} else {
System.out.println("driver == null")
}
Here are my capabilities Working with appium 1.2*
public WebDriver appiumCapabilities() {
File appDir = new File(System.getProperty("user.dir"), "/app/");
File app = new File(appDir, "test.app");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.BROWSER_NAME, "iOS");
capabilities.setCapability(CapabilityType.PLATFORM, "Mac");
capabilities.setCapability("platformName", "iOS");
capabilities.setCapability("deviceName", "iPod");
capabilities.setCapability("platformVersion", "7.1");
capabilities.setCapability("device", "iphone");
capabilities.setCapability("udid", "cd827d3778cfdee2fc7210f8f44184821a083c06");
capabilities.setCapability("app", app);
try {
driver = new RemoteWebDriver(new URL("http://0.0.0.0:4723/wd/hub"), capabilities);
} catch (MalformedURLException e) {
e.printStackTrace();
}
return driver;
}

Categories