Software Testing Urmi Saha Fundamentals By · Software Testing Fundamentals By Urmi Saha. What is...

22
Software Testing Fundamentals By Urmi Saha

Transcript of Software Testing Urmi Saha Fundamentals By · Software Testing Fundamentals By Urmi Saha. What is...

Page 1: Software Testing Urmi Saha Fundamentals By · Software Testing Fundamentals By Urmi Saha. What is software testing? 1. Process of verifying and validating that a software or application

Software Testing Fundamentals

ByUrmi Saha

Page 2: Software Testing Urmi Saha Fundamentals By · Software Testing Fundamentals By Urmi Saha. What is software testing? 1. Process of verifying and validating that a software or application

What is software testing?1. Process of verifying and validating that a software or application is bug free

AND

2. The software meets the technical requirements as guided by it’s design and development

AND

3. The software meets the user requirements effectively and efficiently with handling all the exceptional and boundary cases

Page 3: Software Testing Urmi Saha Fundamentals By · Software Testing Fundamentals By Urmi Saha. What is software testing? 1. Process of verifying and validating that a software or application

Software testing is divided into 2 steps:

1. Verification

This refers to the set of tasks that ensure that software correctly implements a specific function.

“Are we building the product right?”

2. Validation

This refers to a different set of tasks that ensure that the software that has been built is traceable to customer requirements.

“Are we building the right product?”

Page 4: Software Testing Urmi Saha Fundamentals By · Software Testing Fundamentals By Urmi Saha. What is software testing? 1. Process of verifying and validating that a software or application

Types of software testing:1. Manual Testing

The tester takes over the role of an end-user and tests the software to identify any unexpected behavior or bug without any automated tool or script.

2. Automation Testing

The tester writes scripts and uses another software to test the product. Used to re-run the test scenarios that were performed manually and repeatedly

Page 5: Software Testing Urmi Saha Fundamentals By · Software Testing Fundamentals By Urmi Saha. What is software testing? 1. Process of verifying and validating that a software or application

Techniques of software testing1. Black Box Testing

● Tester doesn’t have access to the source code or the internal logical structure of the software

● Functionality of the software is not known● This can only be done by trial and error method

2. White Box Testing● Tester is aware of the internal workings of the product● Tester has access to it’s source code● Testing conducted by making sure that all internal operations are performed according to the

specifications

Page 6: Software Testing Urmi Saha Fundamentals By · Software Testing Fundamentals By Urmi Saha. What is software testing? 1. Process of verifying and validating that a software or application

Levels of software testing

1. Unit Testing:

Individual units/components of a software are tested

2. Integration Testing:

Individual units are combined and tested as a group

3. System Testing:

Complete, integrated system/software is tested

4. Acceptance Testing:

Assess whether it is acceptable for delivery

Page 7: Software Testing Urmi Saha Fundamentals By · Software Testing Fundamentals By Urmi Saha. What is software testing? 1. Process of verifying and validating that a software or application

Unit TestingRecap

“Unit Testing is defined as a type of software testing where individual units/ components of a software are tested”

● Performed during the development (coding) of an application● Isolate a section of code and verify its correctness● A unit may be an individual function or procedure● Usually performed by the developer

Page 8: Software Testing Urmi Saha Fundamentals By · Software Testing Fundamentals By Urmi Saha. What is software testing? 1. Process of verifying and validating that a software or application

Unit Testing“How is it performed?”

● A developer writes a section of code in the application just to test the function.○ ”They would later comment out and finally remove the test code when the application is

deployed.”

● Relies on mock objects being created to test sections of code that are not yet part of a complete application.

○ “Mock objects fill in for the missing parts of the program”

Page 9: Software Testing Urmi Saha Fundamentals By · Software Testing Fundamentals By Urmi Saha. What is software testing? 1. Process of verifying and validating that a software or application

Example of a unit test case (Django)

from django.test import TestCasefrom myapp.models import Animal

class AnimalTestCase(TestCase):

def setUp(self): Animal.objects.create(name="lion", sound="roar") Animal.objects.create(name="cat", sound="meow")

def test_animals_can_speak(self): """Animals that can speak are correctly identified""" lion = Animal.objects.get(name="lion") cat = Animal.objects.get(name="cat") self.assertEqual(lion.speak(), 'The lion says "roar"') self.assertEqual(cat.speak(), 'The cat says "meow"')

● Django’s unit tests use a Python standard library module: “unittest”

● Here is an example which subclasses from django.test.TestCase, which is a subclass of unittest.TestCase that runs each test inside a transaction to provide isolation =>

● When you run your tests, the default behavior of the test utility is to find all the test cases (that is, subclasses of unittest.TestCase) in any file whose name begins with test, automatically build a test suite out of those test cases, and run that suite.

Page 10: Software Testing Urmi Saha Fundamentals By · Software Testing Fundamentals By Urmi Saha. What is software testing? 1. Process of verifying and validating that a software or application

End-to-End Testing with Selenium

Web App Testing Automation

Page 11: Software Testing Urmi Saha Fundamentals By · Software Testing Fundamentals By Urmi Saha. What is software testing? 1. Process of verifying and validating that a software or application

Why automated testing?

● Manual tests are repeated often during development cycles for source code changes.

● Once automated tests are created they can easily be repeated.

Page 12: Software Testing Urmi Saha Fundamentals By · Software Testing Fundamentals By Urmi Saha. What is software testing? 1. Process of verifying and validating that a software or application

What is Selenium?Browser Automation

● Selenium automates browsers.● It is a software testing

framework for web applications.

● Can be used for web-based administration tasks.

Page 13: Software Testing Urmi Saha Fundamentals By · Software Testing Fundamentals By Urmi Saha. What is software testing? 1. Process of verifying and validating that a software or application

Why Python in Selenium?

Selenium test cases can be written in Java, Python, C#,

Ruby, Perl, PHP, etc.

1. Python is simpler, faster and more compact than any other programming language.

2. It has far less verbose and easy to use.

3. Selenium Python bindings provides a simple API to write test-cases using Selenium WebDriver.

Page 14: Software Testing Urmi Saha Fundamentals By · Software Testing Fundamentals By Urmi Saha. What is software testing? 1. Process of verifying and validating that a software or application

Gecko Driver Drivers for web-driver

automation

1. Gecko is a web browser engine2. Gecko Driver is the link

between your tests in Selenium and the Firefox browser

3. Gecko Driver is an executable file needed in one of the system path before starting tests

Page 15: Software Testing Urmi Saha Fundamentals By · Software Testing Fundamentals By Urmi Saha. What is software testing? 1. Process of verifying and validating that a software or application

Installation

1. Selenium: pip3 install selenium

2. Geckodriver for firefox:a. wget

https://github.com/mozilla/geckodriver/releases/download/v0.20.1/geckodriver-v0.20.1-linux64.tar.gz

b. tar -xvzf geckodriver-v0.20.1-linux64.tar.gzc. rm geckodriver-v0.20.1-linux64.tar.gzd. chmod +x geckodrivere. cp geckodriver /usr/local/bin/

3. Write test script and run.

Page 16: Software Testing Urmi Saha Fundamentals By · Software Testing Fundamentals By Urmi Saha. What is software testing? 1. Process of verifying and validating that a software or application

Example of scriptimport unittestfrom selenium import webdriverfrom selenium.webdriver.common.keys import Keys

class PythonOrgSearch(unittest.TestCase):

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

def test_search_in_python_org(self): driver = self.driver driver.get("http://www.python.org") self.assertIn("Python", driver.title) elem = driver.find_element_by_name("q") elem.send_keys("pycon") elem.send_keys(Keys.RETURN) assert "No results found." not in driver.page_source

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

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

Console Output

python test_python_org_search.py.----------------------------------------------------------------------Ran 1 test in 15.566s

OK

Page 17: Software Testing Urmi Saha Fundamentals By · Software Testing Fundamentals By Urmi Saha. What is software testing? 1. Process of verifying and validating that a software or application

Examples of Selenium-WebDriver API Commands and Operations

Page 18: Software Testing Urmi Saha Fundamentals By · Software Testing Fundamentals By Urmi Saha. What is software testing? 1. Process of verifying and validating that a software or application

Locating UI Elements (WebElements)1. By ID:

html: <div id="coolestWidgetEvah">...</div>selenium code: element = driver.find_element_by_id("coolestWidgetEvah")

2. By Class Name: html: <div class="cheese"><span>Cheddar</span></div><div class="cheese"><span>Gouda</span></div>selenium code: cheeses = driver.find_elements_by_class_name("cheese")

3. By Name:html: <input name="cheese" type="text"/>selenium code: cheese = driver.find_element_by_name("cheese")

4. By XPath:html: <input type="text" name="example" />selenium code: inputs = driver.find_elements_by_xpath("//input")

etc.

Page 19: Software Testing Urmi Saha Fundamentals By · Software Testing Fundamentals By Urmi Saha. What is software testing? 1. Process of verifying and validating that a software or application

Getting text valueselement = driver.find_element_by_id("element_id")element.text

Moving Between Windows and Framesdriver.switchTo().window("windowName");

Page 20: Software Testing Urmi Saha Fundamentals By · Software Testing Fundamentals By Urmi Saha. What is software testing? 1. Process of verifying and validating that a software or application

Popup Dialogs

alert = driver.switch_to.alert

Navigationdriver.navigate().forward();

driver.navigate().back();

Page 21: Software Testing Urmi Saha Fundamentals By · Software Testing Fundamentals By Urmi Saha. What is software testing? 1. Process of verifying and validating that a software or application

Referencehttp://selenium-python.readthedocs.io

http://selenium-python.readthedocs.io/getting-started.html

https://www.seleniumhq.org/docs/03_webdriver.jsp

https://docs.djangoproject.com/en/dev/topics/testing/#writing-unit-tests

https://docs.djangoproject.com/en/dev/topics/testing/overview/

https://docs.djangoproject.com/en/dev/topics/testing/overview/#running-tests

https://www.dev2qa.com/django-unit-test-example/

Page 22: Software Testing Urmi Saha Fundamentals By · Software Testing Fundamentals By Urmi Saha. What is software testing? 1. Process of verifying and validating that a software or application

Thank You