Automation testing using selenium and python



  • I am new to automation testing. I am learning from last 2 months. My company needs a program to check multiple URLs and perform tests on them to see if the sites are working or not. If not working, then a report should be generated and an email should be sent to all with the report. I made a program to browse multiple URLS and also to should an email using SMTP. But the issue is that, I am unable to use the same code to login to multiple URLS. Also, I need to send no-reply email. I am unable to do so. Please help me if anyone is aware of it. I am using selenium and python language for my program.



  • With Python you could use subTest() to create a single unit tests which loops over multiple inputs.

    def test_login_multiple_urls(self):
        # setup driver here
        urls = ["http://server1.com", "http://server2.com", "http://server3.com"]
        for url in urls:
            with self.subTest(url=url):
                driver.get(url)
                # more setup
                # some actions to test
                # some assert
    

    For sending as emails as no-reply define the FROM field to a no-reply@example.org mail address:

    msg = EmailMessage()
    msg['Subject'] = 'Test results'
    msg['From'] = 'no-reply@example.org'
    

    Read more in the Python email documentation: https://docs.python.org/3/library/email.examples.html


Log in to reply
 

Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2