Monday, February 23, 2015

While writing functional test cases using selenium tearDown() method is one of the greatest functionality/place to do all cleanup actions. This method called immediately after the test method has been called and the result recorded. This is called even if the test method raised an exception, so the implementation in subclasses may need to be particularly careful about checking internal state. Any exception raised by this method will be considered an error rather than a test failure. This method will only be called if the setUp() succeeds, regardless of the outcome of the test method. The default implementation does nothing. 

So instead of adding screenshots functionality in each test cases, we can add this functionality in tearDown method as follows:

def tearDown(self):
        if sys.exc_info()[0]:
            test_method_name = self._testMethodName
            now = datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
            self.driver.save_screenshot(os.getcwd() +'/screenshots/' + test_method_name + "-" + now + ".png")
--

Make sure to import following packages for above code.

from selenium import webdriver
from datetime import datetime
import os 



13 comments:

  1. The future of software testing is on positive note. It offers huge career prospects for talented professionals to be skilled software testers. Software testing training institutes

    ReplyDelete
  2. Thanks for your informative article on UFT automation testing tool. Your post helped me to understand the features and functionality of QTP automation testing tool. QTP Training in Chennai | QTP training

    ReplyDelete
  3. Testing is the only way to deliver reliable products in the Information Technology market. Articles like this are vital in improvising one's ability as a software testing professional. Thank you so much for sharing this information in here. Keep blogging.

    Software testing training in chennai | Software testing course | Software testing training institutes in chennai | Software testing training institute in chennai

    ReplyDelete
  4. Automation will make any work to be completed so soon(Selenium training in chennai), in addition to this recording the actions is possible with automated tool. Your content explicitely states the same(Selenium testing training). Thanks for sharing this worth able content in here. This was very useful to me as well. Keep blogging like this(Selenium testing tool training chennai).

    ReplyDelete
  5. Excellent post. Hi everyone, I did Selenium Training in Chennai at a leading training institute.Its really useful for me to know more details about selenium testing. Now I am working as a software tester. So join this institute and get bright future.

    ReplyDelete
  6. Really interesting content which is unique which provided me the required information.
    Selenium Training in Chennai | best selenium testing training institute in Chennai.

    ReplyDelete
  7. Selenium is a testing tool which is an open source which can work very well for the professionals and for testers. If a profesional is knowing manual testing then if he learn seenium then there are good chance for career growth.
    selenium training in chennai | selenium training institute in chennai | selenium course in chennai

    ReplyDelete
  8. Manual testing is the process of testing the software manually in order to detect the software defects. It requires the role of tester to deliver the product efficiently to the customer and use all of its application to ensure that it works correctly
    manual testing training institute in chennai | manual testing training



    ReplyDelete
  9. Testing now a days has become as importnant as developing of an application. With the help of testing, we can find out the potential bugs which would affect the application. Fixing this at a very early stage would help the application to run without any problem.
    Software testing training in Chennai | Software testing training institute in Chennai | Software testing courses in Chennai

    ReplyDelete
  10. Well Said, you have furnished the right information that will be useful to anyone at all time. Thanks for sharing your Ideas.
    digital marketing course in Chennai | digital marketing training in Chennai

    ReplyDelete
  11. The content you posted helps me to get the in depth knowledge about the various technology and it is very interesting to go through it. Thanks for sharing it.
    AngularJS Training in Chennai | AngularJS course in Chennai

    ReplyDelete
  12. A debt of gratitude is in order for requiring some serious energy share this post. It is truly useful. I propose to visit this site to my group members. Please continue posting this way.
    Regards,
    Selenium Training in Chennai | Selenium Testing Training in Chennai | Selenium Course in Chennai

    ReplyDelete
  13. Well Said, you have furnished the right information that will be useful to anyone at all time. Thanks for sharing your Ideas.
    Salesforce Training in Chennai | Salesforce Training Institute in Chennai

    ReplyDelete

Categories

.
Powered by Blogger.

Popular Posts

Like Us