Selenium + python reports

I am doing R&D on selenium + python. I wrote some test cases in python using selenium webdriver and unittest module. I want to know how I can create a test case report. Is there a built-in solution available in selenium, or I need to code to generate a file.

Or is there any other javascript-enabled web testing framework available in python that has reporting features.

I am basically new to python as well as to selenium. Just trying to research.

+5
source share
6 answers

Selenium + Python, unittest python. Selenium .

HTMLTestRunner unittest , HTML.

+7

, . , , , , . Python, logging , Handlers Formatters. , , , , , .

+1

. , . python (, , ). - , .

+1

Robot Framework - , :

  • , .
  • ,
    • RF
    • RF
    • HTML-

enter image description here

+1

HTMLTestRunner

URL:

http://tungwaiyip.info/software/HTMLTestRunner.html

  • HTMLTestRunner.py
  • HTMLTestRunner.py
  • , import
  • HTMLTestRunner

:

from selenium import webdriver
import unittest
import HTMLTestRunner

class LoginTest(unittest.TestCase):

def setUp(self):

    print driverpath
    self.driver = webdriver.Chrome(driverpath + "chromedriver.exe")
    self.driver.get("http://google.com/")

def testPythonScript(self):
    driver=self.driver
    driver.maximize_window()
    driver.implicitly_wait(60)
    driver.get_screenshot_as_file(screenshotpath + "testPngFunction.png")
    driver.find_element_by_xpath("(//a[contains(@href,'contact-us')])[1]").click()
    driver.find_element_by_name("name").send_keys("shubham")
    driver.find_element_by_id("contactemail").send_keys("shubham.xyz@abc.com")
    driver.find_element_by_css_selector("#contact_form > div:nth-child(3) > div:nth-child(3) > input").send_keys(
        "389198318312")
    driver.find_element_by_name("company").send_keys("myname")
    driver.get_screenshot_as_file(screenshotpath + "ConatctUs.png")
    print driver.title
    assert "Hello" in driver.title
    print "execution ends"

def testPythonFailScript(self):
    driver=self.driver
    driver.find_element_by_name("notExist").send_keys("done")

    def tearDown(self):
        driver = self.driver
        driver.quit();

if __name__ == "__main__":
    HTMLTestRunner.main()

python scriptFileName.py > TestReport.HTML

Note: scriptFileName is the name of the Python file, and TestReport is the name of the report in html format. You can call it what you want.

+1
source

In my specific application, I use the Nose extension to record and run a luxury test.

In addition, I use the html-reporting plugin , which generates good reports from my test cycles.

0
source

All Articles