How to fix report opening app after test and then taking screenshotHow do you assert that a certain exception is thrown in JUnit 4 tests?How do I fix android.os.NetworkOnMainThreadException?How to fix java.lang.UnsupportedClassVersionError: Unsupported major.minor versionTestNG retrying failed tests doesn't output the correct test resultsTestNG suppressing @AfterMethod to reporterHow to take screen shot for the Failed Tests only after 'Retry'Test design for taking screenshot with Selenium WebDriver on failed JUnit testsTake screenshot in selenium (java) only in after methodHow do I catch exceptions if thrown in @BeforeMethod or @BeforeClass without using a TestNGListenerTake Screenshots on Test Fails
Where can I find my serialized Sitecore items?
English idiomatic equivalents of 能骗就骗 (if you can cheat, then cheat)
Is it advisable to inform the CEO about his brother accessing his office?
Could all three Gorgons turn people to stone, or just Medusa?
What does 'in attendance' mean on an England death certificate?
German idiomatic equivalents of 能骗就骗 (if you can cheat, then cheat)
Having to constantly redo everything because I don't know how to do it
Why are examinees often not allowed to leave during the start and end of an exam?
Would skyscrapers tip over if people fell sideways?
Why wasn't ASCII designed with a contiguous alphanumeric character order?
What does 5d4 x 10 gp mean?
What prevents a US state from colonizing a smaller state?
Checkmate in 1 on a Tangled Board
Can dual citizens open crypto exchange accounts where U.S. citizens are prohibited?
"I am [the / an] owner of a bookstore"?
Is it OK to throw pebbles and stones in streams, waterfalls, ponds, etc.?
How do I tell my girlfriend she's been buying me books by the wrong author for the last nine months?
Meaning of the word "good" in context
Where to connect the fuse and why?
What verb for taking advantage fits in "I don't want to ________ on the friendship"?
Does a lens with a bigger max. aperture focus faster than a lens with a smaller max. aperture?
What are the children of two Muggle-borns called?
Can I take Amul cottage cheese from India to Netherlands?
Rear derailleur got caught in the spokes, what could be a root cause
How to fix report opening app after test and then taking screenshot
How do you assert that a certain exception is thrown in JUnit 4 tests?How do I fix android.os.NetworkOnMainThreadException?How to fix java.lang.UnsupportedClassVersionError: Unsupported major.minor versionTestNG retrying failed tests doesn't output the correct test resultsTestNG suppressing @AfterMethod to reporterHow to take screen shot for the Failed Tests only after 'Retry'Test design for taking screenshot with Selenium WebDriver on failed JUnit testsTake screenshot in selenium (java) only in after methodHow do I catch exceptions if thrown in @BeforeMethod or @BeforeClass without using a TestNGListenerTake Screenshots on Test Fails
Trying to take a screenshot when the test fails. What is actually happening is once intellij gets to my @AfterMethod it launches the application again and takes a screenshot of the home screen.
I have tried putting the extent.flush(); into a @AfterMethod and changing the current @AfterMethod to an @AfterTest
@AfterMethod
public synchronized void afterMethod(ITestResult result) throws IOException
AppiumDriver<MobileElement> driver = MetricellTest.setupTests();
String screenShot = CaptureScreenShot.captureScreen(driver, CaptureScreenShot.generateFileName(result));
if (result.getStatus() == ITestResult.FAILURE)
test.get().log(Status.FAIL, result.getName());
test.get().log(Status.FAIL, result.getThrowable());
test.get().fail("Screen Shot : " + test.get().addScreenCaptureFromPath(screenShot));
test.get().fail(result.getThrowable());
else if (result.getStatus() == ITestResult.SKIP)
test.get().skip("Test Case : " + result.getName() + " has been skipped");
test.get().skip(result.getThrowable());
else
test.get().pass("Test passed");
extent.flush();
}
I expect it to take screenshots as it goes through and tests fail. Currently it just opens the application at the end of the test and takes a screenshot of the home screen.
java testng appium-android extentreports
add a comment |
Trying to take a screenshot when the test fails. What is actually happening is once intellij gets to my @AfterMethod it launches the application again and takes a screenshot of the home screen.
I have tried putting the extent.flush(); into a @AfterMethod and changing the current @AfterMethod to an @AfterTest
@AfterMethod
public synchronized void afterMethod(ITestResult result) throws IOException
AppiumDriver<MobileElement> driver = MetricellTest.setupTests();
String screenShot = CaptureScreenShot.captureScreen(driver, CaptureScreenShot.generateFileName(result));
if (result.getStatus() == ITestResult.FAILURE)
test.get().log(Status.FAIL, result.getName());
test.get().log(Status.FAIL, result.getThrowable());
test.get().fail("Screen Shot : " + test.get().addScreenCaptureFromPath(screenShot));
test.get().fail(result.getThrowable());
else if (result.getStatus() == ITestResult.SKIP)
test.get().skip("Test Case : " + result.getName() + " has been skipped");
test.get().skip(result.getThrowable());
else
test.get().pass("Test passed");
extent.flush();
}
I expect it to take screenshots as it goes through and tests fail. Currently it just opens the application at the end of the test and takes a screenshot of the home screen.
java testng appium-android extentreports
Please add the code for your methodsetupTests
as well so that we could get more clarity on the problem.
– Sameer Arora
Mar 25 at 16:21
@SameerArora I have added the code the setupTests method
– Tom Cockram
Mar 25 at 17:00
add a comment |
Trying to take a screenshot when the test fails. What is actually happening is once intellij gets to my @AfterMethod it launches the application again and takes a screenshot of the home screen.
I have tried putting the extent.flush(); into a @AfterMethod and changing the current @AfterMethod to an @AfterTest
@AfterMethod
public synchronized void afterMethod(ITestResult result) throws IOException
AppiumDriver<MobileElement> driver = MetricellTest.setupTests();
String screenShot = CaptureScreenShot.captureScreen(driver, CaptureScreenShot.generateFileName(result));
if (result.getStatus() == ITestResult.FAILURE)
test.get().log(Status.FAIL, result.getName());
test.get().log(Status.FAIL, result.getThrowable());
test.get().fail("Screen Shot : " + test.get().addScreenCaptureFromPath(screenShot));
test.get().fail(result.getThrowable());
else if (result.getStatus() == ITestResult.SKIP)
test.get().skip("Test Case : " + result.getName() + " has been skipped");
test.get().skip(result.getThrowable());
else
test.get().pass("Test passed");
extent.flush();
}
I expect it to take screenshots as it goes through and tests fail. Currently it just opens the application at the end of the test and takes a screenshot of the home screen.
java testng appium-android extentreports
Trying to take a screenshot when the test fails. What is actually happening is once intellij gets to my @AfterMethod it launches the application again and takes a screenshot of the home screen.
I have tried putting the extent.flush(); into a @AfterMethod and changing the current @AfterMethod to an @AfterTest
@AfterMethod
public synchronized void afterMethod(ITestResult result) throws IOException
AppiumDriver<MobileElement> driver = MetricellTest.setupTests();
String screenShot = CaptureScreenShot.captureScreen(driver, CaptureScreenShot.generateFileName(result));
if (result.getStatus() == ITestResult.FAILURE)
test.get().log(Status.FAIL, result.getName());
test.get().log(Status.FAIL, result.getThrowable());
test.get().fail("Screen Shot : " + test.get().addScreenCaptureFromPath(screenShot));
test.get().fail(result.getThrowable());
else if (result.getStatus() == ITestResult.SKIP)
test.get().skip("Test Case : " + result.getName() + " has been skipped");
test.get().skip(result.getThrowable());
else
test.get().pass("Test passed");
extent.flush();
}
I expect it to take screenshots as it goes through and tests fail. Currently it just opens the application at the end of the test and takes a screenshot of the home screen.
java testng appium-android extentreports
java testng appium-android extentreports
edited Mar 26 at 10:10
Tom Cockram
asked Mar 25 at 15:45
Tom CockramTom Cockram
236 bronze badges
236 bronze badges
Please add the code for your methodsetupTests
as well so that we could get more clarity on the problem.
– Sameer Arora
Mar 25 at 16:21
@SameerArora I have added the code the setupTests method
– Tom Cockram
Mar 25 at 17:00
add a comment |
Please add the code for your methodsetupTests
as well so that we could get more clarity on the problem.
– Sameer Arora
Mar 25 at 16:21
@SameerArora I have added the code the setupTests method
– Tom Cockram
Mar 25 at 17:00
Please add the code for your method
setupTests
as well so that we could get more clarity on the problem.– Sameer Arora
Mar 25 at 16:21
Please add the code for your method
setupTests
as well so that we could get more clarity on the problem.– Sameer Arora
Mar 25 at 16:21
@SameerArora I have added the code the setupTests method
– Tom Cockram
Mar 25 at 17:00
@SameerArora I have added the code the setupTests method
– Tom Cockram
Mar 25 at 17:00
add a comment |
1 Answer
1
active
oldest
votes
In the @AfterMethod
, you are initialising the driver
again and calling the setupTests
method and your setupTests
method is doing the initialisation of the app, because of which the app is getting opened again.
So, you need to make the following changes in your code and it would work fine then:
Declare the
AppiumDriver<MobileElement> driver
globally instead of
declaring it in thesetupTests
method, so that it can be used
throughout the class.Remove the line of code
AppiumDriver<MobileElement> driver =
from your
MetricellTest.setupTests();@AfterMethod
because it is
initialising thedriver
and the app again.
Updated Answer and adding extra explanation:
You can declare the driver
globally like:
So, lets say your class name is testClass
, you should declare the driver
just after the code for the class is starting like:
public class testClass
AppiumDriver<MobileElement> driver;
// Add Rest of the code here
Thanks for your answer. How do I declare the drvier globally?
– Tom Cockram
Mar 25 at 17:13
@TomCockram have updated my answer, please check it now
– Sameer Arora
Mar 25 at 17:19
Thanks, I've made those changes but I'm getting null pointer exception. I'm setting the driver like thispublic static AppiumDriver<MobileElement> AppiumDriver = null;
which I don't think is correct. How should I be doing it?
– Tom Cockram
Mar 25 at 17:26
On which line you are getting NPE ?
– Sameer Arora
Mar 25 at 17:27
Can you post your whole class code in the question after making the changes i suggested ? Would be able to help you better then
– Sameer Arora
Mar 25 at 17:49
|
show 14 more comments
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55341559%2fhow-to-fix-report-opening-app-after-test-and-then-taking-screenshot%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
In the @AfterMethod
, you are initialising the driver
again and calling the setupTests
method and your setupTests
method is doing the initialisation of the app, because of which the app is getting opened again.
So, you need to make the following changes in your code and it would work fine then:
Declare the
AppiumDriver<MobileElement> driver
globally instead of
declaring it in thesetupTests
method, so that it can be used
throughout the class.Remove the line of code
AppiumDriver<MobileElement> driver =
from your
MetricellTest.setupTests();@AfterMethod
because it is
initialising thedriver
and the app again.
Updated Answer and adding extra explanation:
You can declare the driver
globally like:
So, lets say your class name is testClass
, you should declare the driver
just after the code for the class is starting like:
public class testClass
AppiumDriver<MobileElement> driver;
// Add Rest of the code here
Thanks for your answer. How do I declare the drvier globally?
– Tom Cockram
Mar 25 at 17:13
@TomCockram have updated my answer, please check it now
– Sameer Arora
Mar 25 at 17:19
Thanks, I've made those changes but I'm getting null pointer exception. I'm setting the driver like thispublic static AppiumDriver<MobileElement> AppiumDriver = null;
which I don't think is correct. How should I be doing it?
– Tom Cockram
Mar 25 at 17:26
On which line you are getting NPE ?
– Sameer Arora
Mar 25 at 17:27
Can you post your whole class code in the question after making the changes i suggested ? Would be able to help you better then
– Sameer Arora
Mar 25 at 17:49
|
show 14 more comments
In the @AfterMethod
, you are initialising the driver
again and calling the setupTests
method and your setupTests
method is doing the initialisation of the app, because of which the app is getting opened again.
So, you need to make the following changes in your code and it would work fine then:
Declare the
AppiumDriver<MobileElement> driver
globally instead of
declaring it in thesetupTests
method, so that it can be used
throughout the class.Remove the line of code
AppiumDriver<MobileElement> driver =
from your
MetricellTest.setupTests();@AfterMethod
because it is
initialising thedriver
and the app again.
Updated Answer and adding extra explanation:
You can declare the driver
globally like:
So, lets say your class name is testClass
, you should declare the driver
just after the code for the class is starting like:
public class testClass
AppiumDriver<MobileElement> driver;
// Add Rest of the code here
Thanks for your answer. How do I declare the drvier globally?
– Tom Cockram
Mar 25 at 17:13
@TomCockram have updated my answer, please check it now
– Sameer Arora
Mar 25 at 17:19
Thanks, I've made those changes but I'm getting null pointer exception. I'm setting the driver like thispublic static AppiumDriver<MobileElement> AppiumDriver = null;
which I don't think is correct. How should I be doing it?
– Tom Cockram
Mar 25 at 17:26
On which line you are getting NPE ?
– Sameer Arora
Mar 25 at 17:27
Can you post your whole class code in the question after making the changes i suggested ? Would be able to help you better then
– Sameer Arora
Mar 25 at 17:49
|
show 14 more comments
In the @AfterMethod
, you are initialising the driver
again and calling the setupTests
method and your setupTests
method is doing the initialisation of the app, because of which the app is getting opened again.
So, you need to make the following changes in your code and it would work fine then:
Declare the
AppiumDriver<MobileElement> driver
globally instead of
declaring it in thesetupTests
method, so that it can be used
throughout the class.Remove the line of code
AppiumDriver<MobileElement> driver =
from your
MetricellTest.setupTests();@AfterMethod
because it is
initialising thedriver
and the app again.
Updated Answer and adding extra explanation:
You can declare the driver
globally like:
So, lets say your class name is testClass
, you should declare the driver
just after the code for the class is starting like:
public class testClass
AppiumDriver<MobileElement> driver;
// Add Rest of the code here
In the @AfterMethod
, you are initialising the driver
again and calling the setupTests
method and your setupTests
method is doing the initialisation of the app, because of which the app is getting opened again.
So, you need to make the following changes in your code and it would work fine then:
Declare the
AppiumDriver<MobileElement> driver
globally instead of
declaring it in thesetupTests
method, so that it can be used
throughout the class.Remove the line of code
AppiumDriver<MobileElement> driver =
from your
MetricellTest.setupTests();@AfterMethod
because it is
initialising thedriver
and the app again.
Updated Answer and adding extra explanation:
You can declare the driver
globally like:
So, lets say your class name is testClass
, you should declare the driver
just after the code for the class is starting like:
public class testClass
AppiumDriver<MobileElement> driver;
// Add Rest of the code here
edited Mar 25 at 17:18
answered Mar 25 at 17:08
Sameer AroraSameer Arora
2,2882 gold badges3 silver badges15 bronze badges
2,2882 gold badges3 silver badges15 bronze badges
Thanks for your answer. How do I declare the drvier globally?
– Tom Cockram
Mar 25 at 17:13
@TomCockram have updated my answer, please check it now
– Sameer Arora
Mar 25 at 17:19
Thanks, I've made those changes but I'm getting null pointer exception. I'm setting the driver like thispublic static AppiumDriver<MobileElement> AppiumDriver = null;
which I don't think is correct. How should I be doing it?
– Tom Cockram
Mar 25 at 17:26
On which line you are getting NPE ?
– Sameer Arora
Mar 25 at 17:27
Can you post your whole class code in the question after making the changes i suggested ? Would be able to help you better then
– Sameer Arora
Mar 25 at 17:49
|
show 14 more comments
Thanks for your answer. How do I declare the drvier globally?
– Tom Cockram
Mar 25 at 17:13
@TomCockram have updated my answer, please check it now
– Sameer Arora
Mar 25 at 17:19
Thanks, I've made those changes but I'm getting null pointer exception. I'm setting the driver like thispublic static AppiumDriver<MobileElement> AppiumDriver = null;
which I don't think is correct. How should I be doing it?
– Tom Cockram
Mar 25 at 17:26
On which line you are getting NPE ?
– Sameer Arora
Mar 25 at 17:27
Can you post your whole class code in the question after making the changes i suggested ? Would be able to help you better then
– Sameer Arora
Mar 25 at 17:49
Thanks for your answer. How do I declare the drvier globally?
– Tom Cockram
Mar 25 at 17:13
Thanks for your answer. How do I declare the drvier globally?
– Tom Cockram
Mar 25 at 17:13
@TomCockram have updated my answer, please check it now
– Sameer Arora
Mar 25 at 17:19
@TomCockram have updated my answer, please check it now
– Sameer Arora
Mar 25 at 17:19
Thanks, I've made those changes but I'm getting null pointer exception. I'm setting the driver like this
public static AppiumDriver<MobileElement> AppiumDriver = null;
which I don't think is correct. How should I be doing it?– Tom Cockram
Mar 25 at 17:26
Thanks, I've made those changes but I'm getting null pointer exception. I'm setting the driver like this
public static AppiumDriver<MobileElement> AppiumDriver = null;
which I don't think is correct. How should I be doing it?– Tom Cockram
Mar 25 at 17:26
On which line you are getting NPE ?
– Sameer Arora
Mar 25 at 17:27
On which line you are getting NPE ?
– Sameer Arora
Mar 25 at 17:27
Can you post your whole class code in the question after making the changes i suggested ? Would be able to help you better then
– Sameer Arora
Mar 25 at 17:49
Can you post your whole class code in the question after making the changes i suggested ? Would be able to help you better then
– Sameer Arora
Mar 25 at 17:49
|
show 14 more comments
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55341559%2fhow-to-fix-report-opening-app-after-test-and-then-taking-screenshot%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Please add the code for your method
setupTests
as well so that we could get more clarity on the problem.– Sameer Arora
Mar 25 at 16:21
@SameerArora I have added the code the setupTests method
– Tom Cockram
Mar 25 at 17:00