Logging
test case results is as important as writing test cases. There are many
ways to log the results provided by JUnit but I am going to provide a
simple and effective solutions which I adopted to Log Test case results
on Android Studio.This method is independent of selection of automation
tool.
It
is also a good practice to take a screenshot from the device when test
case fails but that code is tool dependent so I will share that too in
future posts.
The
way you log your test case results will simplify tracking of bugs and
generate a proper report as output of your Test Suit Run.Hence I suggest
you to start Logging your test case results starting from your very
first test case.
Let us see with simple example.
1. Create a Java Class names TestCases in the Android Studio.
2. Declare a Tag in the class as String LoginTestCase.
3. Then write the log on sucess or failure as per you like as shown in below test case. I have added Appium test case as sample but this you can use in any of your Test Cases.
public void TestCase { AppiumDriver driver; String Tag_name="ScrollTestCase"; @Before public void testCaseSetup()throws Exception { DesiredCapabilities cap=new DesiredCapabilities(); cap.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android"); cap.setCapability(MobileCapabilityType.DEVICE_NAME, "Android device"); cap.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, "4000"); cap.setCapability(MobileCapabilityType.APP, "c://apks//seekbarsample.apk"); cap.setCapability("noReset", true); driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), cap); } @Test public void testVerticalScroll() { //Scroll till the 25th row driver.scrollTo("List item:25"); //Click on the 25th row text driver.findElement(By.name("List item:25")).click(); try { Log.e(Tag_name,"Test case passes"); Assert.assertEquals("Clicked on row no: 25", driver.findElement(By.id("row_select")).getText()); }catch (AssertionError e) { Log.e(Tag_name,"Test case failed") } } @After public void testCaseTearDown() { driver.quit(); } }
4. Once you are done adding adding log in each test case ten run the test suite.
5. Then click on Android Monitor at the and it will open the Monitor as shown in below screenshot
Log Appium Test Execution Report |
6. Then click on Edit Filter Configuration as shown below.
Check logs in Android Studio |
7.Enter Filer name and our Tag name hit OK.
Filter Logs in Android Studio |
8. Then you can read your test case logs.
I hope you find this tutorial useful. Do share your feedback and questions in comments section below.Please follow QA Automated on social media to get latest post updates. Happy Testing :-)
Thanks for one marvelous posting! I enjoyed reading it; you are a great author. I will make sure to bookmark your blog and may come back someday. I want to encourage that you continue your great posts.
ReplyDeleteDevops training in Chennai