SlideShare ist ein Scribd-Unternehmen logo
1 von 26
Downloaden Sie, um offline zu lesen
Testing WebApps 101
For newbies by newbies
Requisites for the talk
● Virtualenv (of course)
● Django
● Selenium
Different Types of tests
● Unit Tests
A unit test establishes that the code does what you
intended the code to do (e.g. you wanted to add parameter
a and b, you in fact add them, and don't subtract them)
Different Types of tests
● Functional Tests
Functional tests test that all of the code works
together to get a correct result, so that what you
intended the code to do in fact gets the right
result in the system.
Different Types of tests
● Integration Tests
Is the phase in software testing in which
individual software modules are combined and
tested as a group
Integration tests tell what's not working. But
they are of no use in guessing where the
problem could be.
Some bugs are dependent of other modules
A single bug will break several features, and
several integration tests will fail
On the other hand, the same bug will break
just one unit test
virtualenv --python=/Library/Frameworks/Python.framework/Versions/3.3/bin/python
3 testdir
Installing Virtualenv
Functional
Testing
from selenium import webdriver
browser = webdriver.Firefox()
browser.get('http://localhost:8000')
assert 'Django' in browser.title
funcional_test.py
from selenium import webdriver
browser = webdriver.Firefox()
browser.get('http://localhost:8000')
assert 'Django' in browser.title
browser.quit()
funcional_test.py
def setUp(self):
self.browser = webdriver.Firefox()
self.browser.implicitly_wait(3)
Implicits wait
from selenium import webdriver
import unittest
class NewVisitorTest(unittest.TestCase): #
def setUp(self): #
self.browser = webdriver.Firefox()
def tearDown(self): #
self.browser.quit()
def test_can_start_a_list_and_retrieve_it_later(self):
self.browser.get('http://localhost:8000')
self.assertIn('To-Do', self.browser.title) #
self.fail('Finish the test!') #
if __name__ == '__main__': #
unittest.main(warnings='ignore') #
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import unittest
class NewVisitorTest(unittest.TestCase):
def setUp(self):
self.browser = webdriver.Firefox()
self.browser.implicitly_wait(3)
def tearDown(self):
self.browser.quit()
#It continues below…. next slide
# We continue here...
def test_can_start_a_list_and_retrieve_it_later(self):
# Edith has heard about a cool new online to-do app. She goes
# to check out its homepage
self.browser.get('http://localhost:8000')
# She notices the page title and header mention to-do lists
self.assertIn('To-Do', self.browser.title)
header_text = self.browser.find_element_by_tag_name('h1').text
self.assertIn('To-Do', header_text)
# She is invited to enter a to-do item straight away
inputbox = self.browser.find_element_by_id('id_new_item')
self.assertEqual(
inputbox.get_attribute('placeholder'),
'Enter a to-do item'
)
Django UnitTest
from django.test import TestCase
Django Tests
Views
from django.core.urlresolvers import resolve
from django.test import TestCase
from django.http import HttpRequest
from lists.views import home_page
class HomePageTest(TestCase):
def test_root_url_resolves_to_home_page_view(self):
found = resolve('/')
self.assertEqual(found.func, home_page)
def test_home_page_returns_correct_html(self):
request = HttpRequest() #
response = home_page(request) #
self.assertTrue(response.content.startswith(b'<html>')) #
self.assertIn(b'<title>To-Do lists</title>', response.content) #
self.assertTrue(response.content.endswith(b'</html>')) #
from django.core.urlresolvers import resolve
from django.test import TestCase
from lists.views import home_page #
class HomePageTest(TestCase):
def test_root_url_resolves_to_home_page_view
(self):
found = resolve('/') #
self.assertEqual(found.func, home_page) #
Views Tests
MODELS
from lists.models import Item
[...]
class ItemModelTest(TestCase):
def test_saving_and_retrieving_items(self):
first_item = Item()
first_item.text = 'The first (ever) list item'
first_item.save()
second_item = Item()
second_item.text = 'Item the second'
second_item.save()
saved_items = Item.objects.all()
self.assertEqual(saved_items.count(), 2)
first_saved_item = saved_items[0]
second_saved_item = saved_items[1]
self.assertEqual(first_saved_item.text, 'The first (ever) list item')
self.assertEqual(second_saved_item.text, 'Item the second')
POST Requests
def test_home_page_can_save_a_POST_request(self):
request = HttpRequest()
request.method = 'POST'
request.POST['item_text'] = 'A new list item'
response = home_page(request)
self.assertEqual(Item.objects.count(), 1) #
new_item = Item.objects.first() #
self.assertEqual(new_item.text, 'A new list item') #
self.assertIn('A new list item', response.content.decode())
expected_html = render_to_string(
'home.html',
{'new_item_text': 'A new list item'}
)
self.assertEqual(response.content.decode(), expected_html)
def test_home_page_can_redirect_after_POST(self):
request = HttpRequest()
request.method = 'POST'
request.POST['item_text'] = 'A new list item'
response = home_page(request)
self.assertEqual(Item.objects.count(), 1)
new_item = Item.objects.first()
self.assertEqual(new_item.text, 'A new list item')
#Redirect instead of template
self.assertEqual(response.status_code, 302)
self.assertEqual(response['location'], '/') #W

Weitere ähnliche Inhalte

Was ist angesagt?

Postman과 Newman을 이용한 RestAPI 테스트 자동화 가이드
Postman과 Newman을 이용한 RestAPI 테스트 자동화 가이드 Postman과 Newman을 이용한 RestAPI 테스트 자동화 가이드
Postman과 Newman을 이용한 RestAPI 테스트 자동화 가이드 SangIn Choung
 
Automated Web Testing Using Selenium
Automated Web Testing Using SeleniumAutomated Web Testing Using Selenium
Automated Web Testing Using SeleniumWeifeng Zhang
 
RESTful API Testing using Postman, Newman, and Jenkins
RESTful API Testing using Postman, Newman, and JenkinsRESTful API Testing using Postman, Newman, and Jenkins
RESTful API Testing using Postman, Newman, and JenkinsQASymphony
 
Rest api 테스트 수행가이드
Rest api 테스트 수행가이드Rest api 테스트 수행가이드
Rest api 테스트 수행가이드SangIn Choung
 
Page Object Model and Implementation in Selenium
Page Object Model and Implementation in Selenium  Page Object Model and Implementation in Selenium
Page Object Model and Implementation in Selenium Zoe Gilbert
 
Automation Testing with Test Complete
Automation Testing with Test CompleteAutomation Testing with Test Complete
Automation Testing with Test CompleteVartika Saxena
 
Python selenium
Python seleniumPython selenium
Python seleniumDucat
 
Mocking APIs Collaboratively with Postman
Mocking APIs Collaboratively with PostmanMocking APIs Collaboratively with Postman
Mocking APIs Collaboratively with PostmanNordic APIs
 
Automated Testing vs Manual Testing
Automated Testing vs Manual TestingAutomated Testing vs Manual Testing
Automated Testing vs Manual Testingdidev
 
자동화된 Test Case의 효과
자동화된 Test Case의 효과자동화된 Test Case의 효과
자동화된 Test Case의 효과도형 임
 

Was ist angesagt? (20)

Postman과 Newman을 이용한 RestAPI 테스트 자동화 가이드
Postman과 Newman을 이용한 RestAPI 테스트 자동화 가이드 Postman과 Newman을 이용한 RestAPI 테스트 자동화 가이드
Postman과 Newman을 이용한 RestAPI 테스트 자동화 가이드
 
Automated Web Testing Using Selenium
Automated Web Testing Using SeleniumAutomated Web Testing Using Selenium
Automated Web Testing Using Selenium
 
Automation Testing by Selenium Web Driver
Automation Testing by Selenium Web DriverAutomation Testing by Selenium Web Driver
Automation Testing by Selenium Web Driver
 
RESTful API Testing using Postman, Newman, and Jenkins
RESTful API Testing using Postman, Newman, and JenkinsRESTful API Testing using Postman, Newman, and Jenkins
RESTful API Testing using Postman, Newman, and Jenkins
 
Rest api 테스트 수행가이드
Rest api 테스트 수행가이드Rest api 테스트 수행가이드
Rest api 테스트 수행가이드
 
Page Object Model and Implementation in Selenium
Page Object Model and Implementation in Selenium  Page Object Model and Implementation in Selenium
Page Object Model and Implementation in Selenium
 
QSpiders - Automation using Selenium
QSpiders - Automation using SeleniumQSpiders - Automation using Selenium
QSpiders - Automation using Selenium
 
Automation Testing with Test Complete
Automation Testing with Test CompleteAutomation Testing with Test Complete
Automation Testing with Test Complete
 
Python selenium
Python seleniumPython selenium
Python selenium
 
Test automation proposal
Test automation proposalTest automation proposal
Test automation proposal
 
Introduction to selenium
Introduction to seleniumIntroduction to selenium
Introduction to selenium
 
Belajar Postman test runner
Belajar Postman test runnerBelajar Postman test runner
Belajar Postman test runner
 
Mocking APIs Collaboratively with Postman
Mocking APIs Collaboratively with PostmanMocking APIs Collaboratively with Postman
Mocking APIs Collaboratively with Postman
 
Angular Unit Testing
Angular Unit TestingAngular Unit Testing
Angular Unit Testing
 
Selenium
SeleniumSelenium
Selenium
 
Selenium WebDriver training
Selenium WebDriver trainingSelenium WebDriver training
Selenium WebDriver training
 
Automated Testing vs Manual Testing
Automated Testing vs Manual TestingAutomated Testing vs Manual Testing
Automated Testing vs Manual Testing
 
자동화된 Test Case의 효과
자동화된 Test Case의 효과자동화된 Test Case의 효과
자동화된 Test Case의 효과
 
Page object pattern
Page object patternPage object pattern
Page object pattern
 
Selenium web driver
Selenium web driverSelenium web driver
Selenium web driver
 

Andere mochten auch

Parallel Testing with Python with Selenium and Sauce Labs
Parallel Testing with Python with Selenium and Sauce LabsParallel Testing with Python with Selenium and Sauce Labs
Parallel Testing with Python with Selenium and Sauce LabsSauce Labs
 
Alali Wlis Prezentacia
Alali Wlis PrezentaciaAlali Wlis Prezentacia
Alali Wlis Prezentaciaingatoro
 
N.e.m.o. albert serrat
N.e.m.o. albert serratN.e.m.o. albert serrat
N.e.m.o. albert serratemallol1
 
Мониторинг рынка бытовых котлов. Импорт/производство/экспорт. Украина. 1-4 кв...
Мониторинг рынка бытовых котлов. Импорт/производство/экспорт. Украина. 1-4 кв...Мониторинг рынка бытовых котлов. Импорт/производство/экспорт. Украина. 1-4 кв...
Мониторинг рынка бытовых котлов. Импорт/производство/экспорт. Украина. 1-4 кв...Agency of Industrial Marketing
 
The future of_flash_do_the_thuan
The future of_flash_do_the_thuanThe future of_flash_do_the_thuan
The future of_flash_do_the_thuanTra Dang Meo Gay
 
Kerala Profile
Kerala ProfileKerala Profile
Kerala ProfileDYUTI
 
Circuits elèctrics
Circuits elèctricsCircuits elèctrics
Circuits elèctricsAvel·lí
 
Euro Fir Web Services Specifications Version 1 0
Euro Fir Web Services Specifications Version 1 0Euro Fir Web Services Specifications Version 1 0
Euro Fir Web Services Specifications Version 1 0jancisk
 
Electricitat
Electricitat Electricitat
Electricitat Avel·lí
 
D O M E S T I C V I O L E N C E A G A I N S T W O M E N [1]
D O M E S T I C  V I O L E N C E  A G A I N S T  W O M E N [1]D O M E S T I C  V I O L E N C E  A G A I N S T  W O M E N [1]
D O M E S T I C V I O L E N C E A G A I N S T W O M E N [1]DYUTI
 
Рынок промышленных котлов ( производство/импорт/экспорт )
Рынок промышленных котлов (производство/импорт/экспорт)Рынок промышленных котлов (производство/импорт/экспорт)
Рынок промышленных котлов ( производство/импорт/экспорт )Agency of Industrial Marketing
 
Мониторинг битумных кровельных материалов (мастики и праймеры) 2013
Мониторинг битумных кровельных материалов (мастики и праймеры) 2013Мониторинг битумных кровельных материалов (мастики и праймеры) 2013
Мониторинг битумных кровельных материалов (мастики и праймеры) 2013Agency of Industrial Marketing
 
Revenue in America : Scaling businesses in the US
Revenue in America:  Scaling businesses in the USRevenue in America:  Scaling businesses in the US
Revenue in America : Scaling businesses in the USVision & Execution, Inc.
 

Andere mochten auch (20)

Parallel Testing with Python with Selenium and Sauce Labs
Parallel Testing with Python with Selenium and Sauce LabsParallel Testing with Python with Selenium and Sauce Labs
Parallel Testing with Python with Selenium and Sauce Labs
 
Qook
QookQook
Qook
 
Little Bear Book
Little  Bear  BookLittle  Bear  Book
Little Bear Book
 
Мониторинг гибкой черепицы
Мониторинг гибкой черепицыМониторинг гибкой черепицы
Мониторинг гибкой черепицы
 
Alali Wlis Prezentacia
Alali Wlis PrezentaciaAlali Wlis Prezentacia
Alali Wlis Prezentacia
 
N.e.m.o. albert serrat
N.e.m.o. albert serratN.e.m.o. albert serrat
N.e.m.o. albert serrat
 
CV
CVCV
CV
 
Мониторинг рынка бытовых котлов. Импорт/производство/экспорт. Украина. 1-4 кв...
Мониторинг рынка бытовых котлов. Импорт/производство/экспорт. Украина. 1-4 кв...Мониторинг рынка бытовых котлов. Импорт/производство/экспорт. Украина. 1-4 кв...
Мониторинг рынка бытовых котлов. Импорт/производство/экспорт. Украина. 1-4 кв...
 
The future of_flash_do_the_thuan
The future of_flash_do_the_thuanThe future of_flash_do_the_thuan
The future of_flash_do_the_thuan
 
Kerala Profile
Kerala ProfileKerala Profile
Kerala Profile
 
storoguk
storogukstoroguk
storoguk
 
Circuits elèctrics
Circuits elèctricsCircuits elèctrics
Circuits elèctrics
 
submar
submarsubmar
submar
 
Euro Fir Web Services Specifications Version 1 0
Euro Fir Web Services Specifications Version 1 0Euro Fir Web Services Specifications Version 1 0
Euro Fir Web Services Specifications Version 1 0
 
Electricitat
Electricitat Electricitat
Electricitat
 
D O M E S T I C V I O L E N C E A G A I N S T W O M E N [1]
D O M E S T I C  V I O L E N C E  A G A I N S T  W O M E N [1]D O M E S T I C  V I O L E N C E  A G A I N S T  W O M E N [1]
D O M E S T I C V I O L E N C E A G A I N S T W O M E N [1]
 
sytay
sytaysytay
sytay
 
Рынок промышленных котлов ( производство/импорт/экспорт )
Рынок промышленных котлов (производство/импорт/экспорт)Рынок промышленных котлов (производство/импорт/экспорт)
Рынок промышленных котлов ( производство/импорт/экспорт )
 
Мониторинг битумных кровельных материалов (мастики и праймеры) 2013
Мониторинг битумных кровельных материалов (мастики и праймеры) 2013Мониторинг битумных кровельных материалов (мастики и праймеры) 2013
Мониторинг битумных кровельных материалов (мастики и праймеры) 2013
 
Revenue in America : Scaling businesses in the US
Revenue in America:  Scaling businesses in the USRevenue in America:  Scaling businesses in the US
Revenue in America : Scaling businesses in the US
 

Ähnlich wie Python Testing 101 with Selenium

Unit-testing and E2E testing in JS
Unit-testing and E2E testing in JSUnit-testing and E2E testing in JS
Unit-testing and E2E testing in JSMichael Haberman
 
UI Testing with Spec
 UI Testing with Spec UI Testing with Spec
UI Testing with SpecPharo
 
Working Effectively With Legacy Code
Working Effectively With Legacy CodeWorking Effectively With Legacy Code
Working Effectively With Legacy CodeNaresh Jain
 
Pragmatic Parallels: Java and JavaScript
Pragmatic Parallels: Java and JavaScriptPragmatic Parallels: Java and JavaScript
Pragmatic Parallels: Java and JavaScriptdavejohnson
 
Automating Django Functional Tests Using Selenium on Cloud
Automating Django Functional Tests Using Selenium on CloudAutomating Django Functional Tests Using Selenium on Cloud
Automating Django Functional Tests Using Selenium on CloudJonghyun Park
 
Getting started with appium
Getting started with appiumGetting started with appium
Getting started with appiumPratik Patel
 
Automation - web testing with selenium
Automation - web testing with seleniumAutomation - web testing with selenium
Automation - web testing with seleniumTzirla Rozental
 
Testing And Drupal
Testing And DrupalTesting And Drupal
Testing And DrupalPeter Arato
 
Selenium withnet
Selenium withnetSelenium withnet
Selenium withnetVlad Maniak
 
Selenium-Webdriver With PHPUnit Automation test for Joomla CMS!
Selenium-Webdriver With PHPUnit Automation test for Joomla CMS!Selenium-Webdriver With PHPUnit Automation test for Joomla CMS!
Selenium-Webdriver With PHPUnit Automation test for Joomla CMS!Puneet Kala
 
Embrace Unit Testing
Embrace Unit TestingEmbrace Unit Testing
Embrace Unit Testingalessiopace
 
Top100summit 谷歌-scott-improve your automated web application testing
Top100summit  谷歌-scott-improve your automated web application testingTop100summit  谷歌-scott-improve your automated web application testing
Top100summit 谷歌-scott-improve your automated web application testingdrewz lin
 
Ef Poco And Unit Testing
Ef Poco And Unit TestingEf Poco And Unit Testing
Ef Poco And Unit TestingJames Phillips
 
Writing automation tests with python selenium behave pageobjects
Writing automation tests with python selenium behave pageobjectsWriting automation tests with python selenium behave pageobjects
Writing automation tests with python selenium behave pageobjectsLeticia Rss
 
Unit Testing Android Applications
Unit Testing Android ApplicationsUnit Testing Android Applications
Unit Testing Android ApplicationsRody Middelkoop
 

Ähnlich wie Python Testing 101 with Selenium (20)

Selenium
SeleniumSelenium
Selenium
 
Selenium
SeleniumSelenium
Selenium
 
Unit-testing and E2E testing in JS
Unit-testing and E2E testing in JSUnit-testing and E2E testing in JS
Unit-testing and E2E testing in JS
 
UI Testing with Spec
 UI Testing with Spec UI Testing with Spec
UI Testing with Spec
 
Working Effectively With Legacy Code
Working Effectively With Legacy CodeWorking Effectively With Legacy Code
Working Effectively With Legacy Code
 
Pragmatic Parallels: Java and JavaScript
Pragmatic Parallels: Java and JavaScriptPragmatic Parallels: Java and JavaScript
Pragmatic Parallels: Java and JavaScript
 
Automating Django Functional Tests Using Selenium on Cloud
Automating Django Functional Tests Using Selenium on CloudAutomating Django Functional Tests Using Selenium on Cloud
Automating Django Functional Tests Using Selenium on Cloud
 
Getting started with appium
Getting started with appiumGetting started with appium
Getting started with appium
 
Automation - web testing with selenium
Automation - web testing with seleniumAutomation - web testing with selenium
Automation - web testing with selenium
 
Testing And Drupal
Testing And DrupalTesting And Drupal
Testing And Drupal
 
Selenium withnet
Selenium withnetSelenium withnet
Selenium withnet
 
Unit Testing in iOS
Unit Testing in iOSUnit Testing in iOS
Unit Testing in iOS
 
Selenium-Webdriver With PHPUnit Automation test for Joomla CMS!
Selenium-Webdriver With PHPUnit Automation test for Joomla CMS!Selenium-Webdriver With PHPUnit Automation test for Joomla CMS!
Selenium-Webdriver With PHPUnit Automation test for Joomla CMS!
 
Embrace Unit Testing
Embrace Unit TestingEmbrace Unit Testing
Embrace Unit Testing
 
UIAutomator
UIAutomatorUIAutomator
UIAutomator
 
Top100summit 谷歌-scott-improve your automated web application testing
Top100summit  谷歌-scott-improve your automated web application testingTop100summit  谷歌-scott-improve your automated web application testing
Top100summit 谷歌-scott-improve your automated web application testing
 
Ef Poco And Unit Testing
Ef Poco And Unit TestingEf Poco And Unit Testing
Ef Poco And Unit Testing
 
UI Testing
UI TestingUI Testing
UI Testing
 
Writing automation tests with python selenium behave pageobjects
Writing automation tests with python selenium behave pageobjectsWriting automation tests with python selenium behave pageobjects
Writing automation tests with python selenium behave pageobjects
 
Unit Testing Android Applications
Unit Testing Android ApplicationsUnit Testing Android Applications
Unit Testing Android Applications
 

Mehr von Leonardo Jimenez

Mehr von Leonardo Jimenez (9)

Debugging para el no iniciado
Debugging para el no iniciadoDebugging para el no iniciado
Debugging para el no iniciado
 
How to create developer communities
How to create developer communitiesHow to create developer communities
How to create developer communities
 
Pyladies Workshop (Spanish)
Pyladies Workshop (Spanish)Pyladies Workshop (Spanish)
Pyladies Workshop (Spanish)
 
Python for Dummies
Python for DummiesPython for Dummies
Python for Dummies
 
Lean startup 101
Lean startup 101Lean startup 101
Lean startup 101
 
Presentación comunidades python dominicana
Presentación comunidades python dominicanaPresentación comunidades python dominicana
Presentación comunidades python dominicana
 
The age of entrepreneurship
The age of entrepreneurshipThe age of entrepreneurship
The age of entrepreneurship
 
Startups 101
Startups 101Startups 101
Startups 101
 
Genetica Mutaciones
Genetica MutacionesGenetica Mutaciones
Genetica Mutaciones
 

Kürzlich hochgeladen

MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...Jittipong Loespradit
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...masabamasaba
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisamasabamasaba
 
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburgmasabamasaba
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxAnnaArtyushina1
 
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...masabamasaba
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park masabamasaba
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrainmasabamasaba
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationJuha-Pekka Tolvanen
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyviewmasabamasaba
 
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...masabamasaba
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...masabamasaba
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...masabamasaba
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Bert Jan Schrijver
 

Kürzlich hochgeladen (20)

MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptx
 
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 

Python Testing 101 with Selenium

  • 1. Testing WebApps 101 For newbies by newbies
  • 2. Requisites for the talk ● Virtualenv (of course) ● Django ● Selenium
  • 3. Different Types of tests ● Unit Tests A unit test establishes that the code does what you intended the code to do (e.g. you wanted to add parameter a and b, you in fact add them, and don't subtract them)
  • 4. Different Types of tests ● Functional Tests Functional tests test that all of the code works together to get a correct result, so that what you intended the code to do in fact gets the right result in the system.
  • 5. Different Types of tests ● Integration Tests Is the phase in software testing in which individual software modules are combined and tested as a group Integration tests tell what's not working. But they are of no use in guessing where the problem could be.
  • 6. Some bugs are dependent of other modules
  • 7. A single bug will break several features, and several integration tests will fail
  • 8. On the other hand, the same bug will break just one unit test
  • 11. from selenium import webdriver browser = webdriver.Firefox() browser.get('http://localhost:8000') assert 'Django' in browser.title funcional_test.py
  • 12. from selenium import webdriver browser = webdriver.Firefox() browser.get('http://localhost:8000') assert 'Django' in browser.title browser.quit() funcional_test.py
  • 13. def setUp(self): self.browser = webdriver.Firefox() self.browser.implicitly_wait(3) Implicits wait
  • 14. from selenium import webdriver import unittest class NewVisitorTest(unittest.TestCase): # def setUp(self): # self.browser = webdriver.Firefox() def tearDown(self): # self.browser.quit() def test_can_start_a_list_and_retrieve_it_later(self): self.browser.get('http://localhost:8000') self.assertIn('To-Do', self.browser.title) # self.fail('Finish the test!') # if __name__ == '__main__': # unittest.main(warnings='ignore') #
  • 15. from selenium import webdriver from selenium.webdriver.common.keys import Keys import unittest class NewVisitorTest(unittest.TestCase): def setUp(self): self.browser = webdriver.Firefox() self.browser.implicitly_wait(3) def tearDown(self): self.browser.quit() #It continues below…. next slide
  • 16. # We continue here... def test_can_start_a_list_and_retrieve_it_later(self): # Edith has heard about a cool new online to-do app. She goes # to check out its homepage self.browser.get('http://localhost:8000') # She notices the page title and header mention to-do lists self.assertIn('To-Do', self.browser.title) header_text = self.browser.find_element_by_tag_name('h1').text self.assertIn('To-Do', header_text) # She is invited to enter a to-do item straight away inputbox = self.browser.find_element_by_id('id_new_item') self.assertEqual( inputbox.get_attribute('placeholder'), 'Enter a to-do item' )
  • 18. from django.test import TestCase Django Tests
  • 19. Views
  • 20. from django.core.urlresolvers import resolve from django.test import TestCase from django.http import HttpRequest from lists.views import home_page class HomePageTest(TestCase): def test_root_url_resolves_to_home_page_view(self): found = resolve('/') self.assertEqual(found.func, home_page) def test_home_page_returns_correct_html(self): request = HttpRequest() # response = home_page(request) # self.assertTrue(response.content.startswith(b'<html>')) # self.assertIn(b'<title>To-Do lists</title>', response.content) # self.assertTrue(response.content.endswith(b'</html>')) #
  • 21. from django.core.urlresolvers import resolve from django.test import TestCase from lists.views import home_page # class HomePageTest(TestCase): def test_root_url_resolves_to_home_page_view (self): found = resolve('/') # self.assertEqual(found.func, home_page) # Views Tests
  • 23. from lists.models import Item [...] class ItemModelTest(TestCase): def test_saving_and_retrieving_items(self): first_item = Item() first_item.text = 'The first (ever) list item' first_item.save() second_item = Item() second_item.text = 'Item the second' second_item.save() saved_items = Item.objects.all() self.assertEqual(saved_items.count(), 2) first_saved_item = saved_items[0] second_saved_item = saved_items[1] self.assertEqual(first_saved_item.text, 'The first (ever) list item') self.assertEqual(second_saved_item.text, 'Item the second')
  • 25. def test_home_page_can_save_a_POST_request(self): request = HttpRequest() request.method = 'POST' request.POST['item_text'] = 'A new list item' response = home_page(request) self.assertEqual(Item.objects.count(), 1) # new_item = Item.objects.first() # self.assertEqual(new_item.text, 'A new list item') # self.assertIn('A new list item', response.content.decode()) expected_html = render_to_string( 'home.html', {'new_item_text': 'A new list item'} ) self.assertEqual(response.content.decode(), expected_html)
  • 26. def test_home_page_can_redirect_after_POST(self): request = HttpRequest() request.method = 'POST' request.POST['item_text'] = 'A new list item' response = home_page(request) self.assertEqual(Item.objects.count(), 1) new_item = Item.objects.first() self.assertEqual(new_item.text, 'A new list item') #Redirect instead of template self.assertEqual(response.status_code, 302) self.assertEqual(response['location'], '/') #W