Sunday, August 12, 2018

Beauty of Gateway Of India and Tajmahal Palace Hotel


The Taj Mahal Palace Hotel

The Taj Mahal Palace Hotel is a heritage, five-star luxury hotel in the Colaba region of Mumbai, Maharashtra, India, situated next to the Gateway of India. Historically it was known as the "Taj Mahal Hotel" or the "Taj Palace Hotel" or simply "the Taj".

The Gateway of India

The Gateway of India is an arch monument built during the 20th century in BombayIndia. The monument was erected to commemorate the landing of King George V and Queen Mary at Apollo Bunder on their visit to India in 1911.


Share:

Thursday, August 2, 2018

Python Selenium : Generating the HTML Test Report and Screenshot feature.

Python Selenium : HtmlTestRunner and Screenshot feature.

Introduction

HtmlTest runner
HtmlTest runner is a unittest test runner that save test results in Html files, for human readable presentation of results.

Screenshots
In automation, it is mandatory to take the screenshot for verification so that can prove also that your test case has covered certain functionality or not. Screenshots help you a lot when your test case will fail so that you can identify what went wrong in your script or in your application.

1. HtmlTestRunner Installation

You can install and read more about HtmlTestRunner from the Github..
HtmlTestRunner Github Page
Using pip, you can install selenium like this:
pip install html-testRunner

2. Sample Selenium Test

create pythonorg-sample.py

import unittest
import HtmlTestRunner
from selenium import webdriver
from selenium.webdriver.common.keys import Keys


class PythonOrgSearch(unittest.TestCase):

    def setUp(self):
        self.driver = webdriver.Chrome()

    def test_search_in_python_org(self):
        driver = self.driver
        driver.get("http://www.python.org")

        # take screen shot
        self.driver.save_screenshot("python-org.png")

        elem = driver.find_element_by_name("q")
        elem.send_keys("pycon")
        elem.send_keys(Keys.RETURN)

        # take screen shot after search
        self.driver.save_screenshot("python-org-after-search.png")

        assert "No results found." not in driver.page_source

    def test_error(self):
        """ This test should be marked as error one. """
        raise ValueError

    def test_fail(self):
        """ This test should fail. """
        self.assertEqual(1, 2)

    def tearDown(self):
        self.driver.close()


if __name__ == "__main__":
    unittest.main(testRunner=HtmlTestRunner.HTMLTestRunner(output='report'))

3. Run Selenium Test

python pythonorg-sample.py

4. Screenshots

HtmlTestRunner
Console Log

Running tests...
----------------------------------------------------------------------
 This test should be marked as error one. ... ERROR (1.961452)s
 This test should fail. ... FAIL (1.838222)s
 test_search_in_python_org (__main__.PythonOrgSearch) ... OK (12.246906)s

======================================================================
ERROR [1.961452s]: This test should be marked as error one.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "pythonorg-sample.py", line 31, in test_error
    raise ValueError
ValueError

======================================================================
FAIL [1.838222s]: This test should fail.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "pythonorg-sample.py", line 35, in test_fail
    self.assertEqual(1, 2)
AssertionError: 1 != 2

----------------------------------------------------------------------
Ran 3 tests in 0:00:16

FAILED
 (Failures=1, Errors=1)

Generating HTML reports...

Share:

Wednesday, August 1, 2018

Getting Started with Python Selenium on Mac OS X

1. Introduction

Selenium Python bindings provides a simple API to write functional/acceptance tests using Selenium WebDriver. Through Selenium Python API you can access all functionalities of Selenium WebDriver in an intuitive way. Selenium Python bindings provide a convenient API to access Selenium WebDrivers like Firefox, Ie, Chrome, Remote etc. The current supported Python versions are 2.7, 3.5 and above.

2. Downloading Python bindings for Selenium and Installation

You can download Python bindings for Selenium from the PyPI page for selenium package. However, a better approach would be to use pip to install the selenium package. Python 3.6 has pip available in the standard library. Using pip, you can install selenium like this:
pip install selenium

3. Drivers

download chrome driver

Selenium requires a driver to interface with the chosen browser. Firefox, for example, requires geckodriver, which needs to be installed before the below examples can be run. Make sure it’s in your PATH, e. g., place it in /usr/bin or /usr/local/bin.
cp chromedriver /usr/local/bin/

4. Sample Selenium Test

create main.py file

from selenium import webdriver
from selenium.webdriver.common.keys import Keys

driver = webdriver.Chrome()
driver.get("http://www.python.org")
assert "Python" in driver.title
elem = driver.find_element_by_name("q")
elem.clear()
elem.send_keys("pycon")
elem.send_keys(Keys.RETURN)
assert "No results found." not in driver.page_source
driver.close()

5. Run Script

python main.py
Share: