SlideShare a Scribd company logo
Lettuce example using simple
scenarios:
El siguienteejemplotienetresarchivos,un feature ydospy.En el siguiente ejemplo
atacaremosla api del tiempoycomprobaremosque ciertosvaloresseancorrectos. Paraello
utilizaremos lettuce conpython. Ademásutilizaremosscenariossimples.
Weather.feature:
Feature:Checkif the weatherservice worksproperly
In orderto check the weatherservice
As beginner
I'll get some valuesandcheckif theyare okand if the temperature giveniscorrect
Scenario:Checkif a cityand a countrygivenare correct
GivenI accessthe url withhttp://api.openweathermap.org/data/2.5/weather
Andthe cityis Londonandthe countryGB
WhenI ask for the cityand country name
ThenI check if the city andcountry are correct
AndI checkif the status code is200
Scenario:Checkif a latitude andlongitudegivenare correct
GivenI accessthe url withhttp://api.openweathermap.org/data/2.5/weather
Andthe latitude is35 and the longitude 139
WhenI ask for the latitude andlongitude
ThenI check if the latitude andlongitude are correct
AndI checkif the status code is200
Scenario:Checkif the temperature iscorrectgivenacity anda country
GivenI accessthe url withhttp://api.openweathermap.org/data/2.5/weather
Andthe cityis Madridand the country ES
WhenI ask for the cityand country name
ThenI get the temperature lookbycityandcountry
Scenario:Checkif the temperature iscorrectgiventhe latitude andlongitude
GivenI accessthe url withhttp://api.openweathermap.org/data/2.5/weather
Andthe latitude is35 and the longitude 139
WhenI ask for weatherinformationbylatitudeandlongitude
ThenI get the temperature lookbylatitude andlongitude
weatherSteps.py:
__author__ = 'kwiznia'
fromlettuce import*
fromweather2import*
fromnose.toolsimport*
weather2= weather2()
@step("Iaccessthe url with(.*)")
def access_url(self,expectedUrl):
world.expectedUrl =expectedUrl
assert_regexp_matches(world.expectedUrl,'^http'),"The URL isempty"
@step("the cityis(Madrid|London|Barcelona|Berlin)andthe country(GB|ES|Germany)")
def city_and_country(self,expectedCity,expectedCountry):
world.expectedCity =expectedCity
world.expectedCountry=expectedCountry
@step("Iaskfor the cityand countryname")
def ask_for_city_and_country(self):
world.url = world.expectedUrl +"?q=" + world.expectedCity+","+ world.expectedCountry
world.page_info =weather2.getInformation(world.url)
@step("Icheckif the cityand country are correct")
def check_city_and_country_are_correct(self):
sys = world.page_info['sys']
assertsys != ""
assertworld.expectedCityinworld.page_info['name']
assertworld.expectedCountryinsys['country']
@step("Icheckif the statuscode is200")
def check_status_code(self):
assert_equals(world.response.status_code,200),"page not found"
@step("the latitude is(40|35|41.3|53.2) andthe longitude (-3.7|139|2.1|13.3)")
def check_lat_and_long(self,expectedLatitude,expectedLongitude):
world.expectedLatitude =expectedLatitude
world.expectedLongitude =expectedLongitude
@step("Iaskfor the latitude andlongitude")
def ask_for_lat_and_long(self):
world.url = world.expectedUrl +"?lat=" + world.expectedLatitude +"&lon="+
world.expectedLongitude
world.page_info=weather2.getInformation(world.url)
@step("Icheckif the latitude andlongitudeare correct")
def check_lat_and_long_are_correct(self):
latlon= world.page_info['coord']
assertlatlon['lon'] !=""
assertlatlon['lat'] !=""
assert_equals(int(world.expectedLatitude),latlon['lat'])
assert_equals(int(world.expectedLongitude),latlon['lon'])
@step("Igetthe temperature lookbycityandcountry")
def get_temperature_look_by_city(self):
temperature =world.page_info['main']
temperatuce_farenhait=temperature['temp']
asserttemperatuce_farenhait!=""
@step("Iaskfor weatherinformationbylatitudeandlongitude")
def ask_for_weather_information_by_latlong(self):
world.url = world.expectedUrl +"?lat=" + world.expectedLatitude +"&lon="+
world.expectedLongitude
world.page_info_by_latlon=weather2.getInformation(world.url)
@step("Igetthe temperature lookbylatitudeandlongitude")
def get_temperature_by_latlong(self):
temperature =world.page_info_by_latlon['main']
temperatuce_farenhait=temperature['temp']
asserttemperatuce_farenhait!=""
weather.py:
__author__ = 'kwiznia'
importrequests
fromlettuce importworld
importjson
classweather2():
"""
def getStatus_code(self,response):
world.response=response
world.response=requests.get(response)
returnworld.response.status_code
"""
def getInformation(self,response):
world.response=requests.get(response)
returnworld.response.json()

More Related Content

Similar to Lettuce example using simple scenario

Lettuce example using scenarios outline
Lettuce example using scenarios outlineLettuce example using scenarios outline
Lettuce example using scenarios outline
Karen Wiznia
 
Modern Java in Action: learn all the things Java can do
Modern Java in Action: learn all the things Java can doModern Java in Action: learn all the things Java can do
Modern Java in Action: learn all the things Java can do
Manning Publications
 
Re-analysis of Umbraco code
Re-analysis of Umbraco codeRe-analysis of Umbraco code
Re-analysis of Umbraco code
PVS-Studio
 
PhoneGap - Hardware Manipulation
PhoneGap - Hardware ManipulationPhoneGap - Hardware Manipulation
PhoneGap - Hardware Manipulation
Doncho Minkov
 
Dusting the globe: analysis of NASA World Wind project
Dusting the globe: analysis of NASA World Wind projectDusting the globe: analysis of NASA World Wind project
Dusting the globe: analysis of NASA World Wind project
PVS-Studio
 
C++ Course - Lesson 1
C++ Course - Lesson 1C++ Course - Lesson 1
C++ Course - Lesson 1
Mohamed Ahmed
 
ApacheCon2019 Talk: Improving the Observability of Cassandra, Kafka and Kuber...
ApacheCon2019 Talk: Improving the Observability of Cassandra, Kafka and Kuber...ApacheCon2019 Talk: Improving the Observability of Cassandra, Kafka and Kuber...
ApacheCon2019 Talk: Improving the Observability of Cassandra, Kafka and Kuber...
Paul Brebner
 
Load Testing with RedLine13: Or getting paid to DoS your own systems
Load Testing with RedLine13: Or getting paid to DoS your own systemsLoad Testing with RedLine13: Or getting paid to DoS your own systems
Load Testing with RedLine13: Or getting paid to DoS your own systems
Jason Lotito
 
Cross Domain Web
Mashups with JQuery and Google App Engine
Cross Domain Web
Mashups with JQuery and Google App EngineCross Domain Web
Mashups with JQuery and Google App Engine
Cross Domain Web
Mashups with JQuery and Google App Engine
Andy McKay
 
Dynatrace: DevOps, shift-left & self-healing a performance clinic with andi
Dynatrace: DevOps, shift-left & self-healing a performance clinic with andiDynatrace: DevOps, shift-left & self-healing a performance clinic with andi
Dynatrace: DevOps, shift-left & self-healing a performance clinic with andi
Dynatrace
 
ZendCon 2017 - Build a Bot Workshop - Async Primer
ZendCon 2017 - Build a Bot Workshop - Async PrimerZendCon 2017 - Build a Bot Workshop - Async Primer
ZendCon 2017 - Build a Bot Workshop - Async Primer
Adam Englander
 
Asynchronous programming patterns in Perl
Asynchronous programming patterns in PerlAsynchronous programming patterns in Perl
Asynchronous programming patterns in Perl
deepfountainconsulting
 
Talk About Performance
Talk About PerformanceTalk About Performance
Talk About Performance
Yaroslav Bunyak
 
"Load Testing Distributed Systems with NBomber 4.0", Anton Moldovan
"Load Testing Distributed Systems with NBomber 4.0",  Anton Moldovan"Load Testing Distributed Systems with NBomber 4.0",  Anton Moldovan
"Load Testing Distributed Systems with NBomber 4.0", Anton Moldovan
Fwdays
 

Similar to Lettuce example using simple scenario (14)

Lettuce example using scenarios outline
Lettuce example using scenarios outlineLettuce example using scenarios outline
Lettuce example using scenarios outline
 
Modern Java in Action: learn all the things Java can do
Modern Java in Action: learn all the things Java can doModern Java in Action: learn all the things Java can do
Modern Java in Action: learn all the things Java can do
 
Re-analysis of Umbraco code
Re-analysis of Umbraco codeRe-analysis of Umbraco code
Re-analysis of Umbraco code
 
PhoneGap - Hardware Manipulation
PhoneGap - Hardware ManipulationPhoneGap - Hardware Manipulation
PhoneGap - Hardware Manipulation
 
Dusting the globe: analysis of NASA World Wind project
Dusting the globe: analysis of NASA World Wind projectDusting the globe: analysis of NASA World Wind project
Dusting the globe: analysis of NASA World Wind project
 
C++ Course - Lesson 1
C++ Course - Lesson 1C++ Course - Lesson 1
C++ Course - Lesson 1
 
ApacheCon2019 Talk: Improving the Observability of Cassandra, Kafka and Kuber...
ApacheCon2019 Talk: Improving the Observability of Cassandra, Kafka and Kuber...ApacheCon2019 Talk: Improving the Observability of Cassandra, Kafka and Kuber...
ApacheCon2019 Talk: Improving the Observability of Cassandra, Kafka and Kuber...
 
Load Testing with RedLine13: Or getting paid to DoS your own systems
Load Testing with RedLine13: Or getting paid to DoS your own systemsLoad Testing with RedLine13: Or getting paid to DoS your own systems
Load Testing with RedLine13: Or getting paid to DoS your own systems
 
Cross Domain Web
Mashups with JQuery and Google App Engine
Cross Domain Web
Mashups with JQuery and Google App EngineCross Domain Web
Mashups with JQuery and Google App Engine
Cross Domain Web
Mashups with JQuery and Google App Engine
 
Dynatrace: DevOps, shift-left & self-healing a performance clinic with andi
Dynatrace: DevOps, shift-left & self-healing a performance clinic with andiDynatrace: DevOps, shift-left & self-healing a performance clinic with andi
Dynatrace: DevOps, shift-left & self-healing a performance clinic with andi
 
ZendCon 2017 - Build a Bot Workshop - Async Primer
ZendCon 2017 - Build a Bot Workshop - Async PrimerZendCon 2017 - Build a Bot Workshop - Async Primer
ZendCon 2017 - Build a Bot Workshop - Async Primer
 
Asynchronous programming patterns in Perl
Asynchronous programming patterns in PerlAsynchronous programming patterns in Perl
Asynchronous programming patterns in Perl
 
Talk About Performance
Talk About PerformanceTalk About Performance
Talk About Performance
 
"Load Testing Distributed Systems with NBomber 4.0", Anton Moldovan
"Load Testing Distributed Systems with NBomber 4.0",  Anton Moldovan"Load Testing Distributed Systems with NBomber 4.0",  Anton Moldovan
"Load Testing Distributed Systems with NBomber 4.0", Anton Moldovan
 

More from Karen Wiznia

Anteproyecto - código - Video final
Anteproyecto - código - Video finalAnteproyecto - código - Video final
Anteproyecto - código - Video final
Karen Wiznia
 
Arduino - código - video
Arduino - código - videoArduino - código - video
Arduino - código - video
Karen Wiznia
 
Arduino - telesketch automático
Arduino - telesketch automáticoArduino - telesketch automático
Arduino - telesketch automático
Karen Wiznia
 
Requests lettuce y python
Requests lettuce y pythonRequests lettuce y python
Requests lettuce y python
Karen Wiznia
 
Testing & selenium - examples
Testing & selenium - examplesTesting & selenium - examples
Testing & selenium - examples
Karen Wiznia
 
Requests con lettuce y python
Requests con lettuce y pythonRequests con lettuce y python
Requests con lettuce y python
Karen Wiznia
 
Selenium with lettuce and python
Selenium with lettuce and pythonSelenium with lettuce and python
Selenium with lettuce and python
Karen Wiznia
 
Crear un repositorio con Gir Bash
Crear un repositorio con Gir BashCrear un repositorio con Gir Bash
Crear un repositorio con Gir Bash
Karen Wiznia
 
Malware
MalwareMalware
Malware
Karen Wiznia
 

More from Karen Wiznia (9)

Anteproyecto - código - Video final
Anteproyecto - código - Video finalAnteproyecto - código - Video final
Anteproyecto - código - Video final
 
Arduino - código - video
Arduino - código - videoArduino - código - video
Arduino - código - video
 
Arduino - telesketch automático
Arduino - telesketch automáticoArduino - telesketch automático
Arduino - telesketch automático
 
Requests lettuce y python
Requests lettuce y pythonRequests lettuce y python
Requests lettuce y python
 
Testing & selenium - examples
Testing & selenium - examplesTesting & selenium - examples
Testing & selenium - examples
 
Requests con lettuce y python
Requests con lettuce y pythonRequests con lettuce y python
Requests con lettuce y python
 
Selenium with lettuce and python
Selenium with lettuce and pythonSelenium with lettuce and python
Selenium with lettuce and python
 
Crear un repositorio con Gir Bash
Crear un repositorio con Gir BashCrear un repositorio con Gir Bash
Crear un repositorio con Gir Bash
 
Malware
MalwareMalware
Malware
 

Recently uploaded

Microservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we workMicroservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we work
Sven Peters
 
fiscal year variant fiscal year variant.
fiscal year variant fiscal year variant.fiscal year variant fiscal year variant.
fiscal year variant fiscal year variant.
AnkitaPandya11
 
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
Bert Jan Schrijver
 
如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样
如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样
如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样
gapen1
 
zOS Mainframe JES2-JES3 JCL-JECL Differences
zOS Mainframe JES2-JES3 JCL-JECL DifferenceszOS Mainframe JES2-JES3 JCL-JECL Differences
zOS Mainframe JES2-JES3 JCL-JECL Differences
YousufSait3
 
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
safelyiotech
 
一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理
dakas1
 
Modelling Up - DDDEurope 2024 - Amsterdam
Modelling Up - DDDEurope 2024 - AmsterdamModelling Up - DDDEurope 2024 - Amsterdam
Modelling Up - DDDEurope 2024 - Amsterdam
Alberto Brandolini
 
The Key to Digital Success_ A Comprehensive Guide to Continuous Testing Integ...
The Key to Digital Success_ A Comprehensive Guide to Continuous Testing Integ...The Key to Digital Success_ A Comprehensive Guide to Continuous Testing Integ...
The Key to Digital Success_ A Comprehensive Guide to Continuous Testing Integ...
kalichargn70th171
 
Using Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query PerformanceUsing Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query Performance
Grant Fritchey
 
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling ExtensionsUI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
Peter Muessig
 
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, FactsALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
Green Software Development
 
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdfTop Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
VALiNTRY360
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
Octavian Nadolu
 
Oracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptxOracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptx
Remote DBA Services
 
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Julian Hyde
 
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
XfilesPro
 
Project Management: The Role of Project Dashboards.pdf
Project Management: The Role of Project Dashboards.pdfProject Management: The Role of Project Dashboards.pdf
Project Management: The Role of Project Dashboards.pdf
Karya Keeper
 
YAML crash COURSE how to write yaml file for adding configuring details
YAML crash COURSE how to write yaml file for adding configuring detailsYAML crash COURSE how to write yaml file for adding configuring details
YAML crash COURSE how to write yaml file for adding configuring details
NishanthaBulumulla1
 
Liberarsi dai framework con i Web Component.pptx
Liberarsi dai framework con i Web Component.pptxLiberarsi dai framework con i Web Component.pptx
Liberarsi dai framework con i Web Component.pptx
Massimo Artizzu
 

Recently uploaded (20)

Microservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we workMicroservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we work
 
fiscal year variant fiscal year variant.
fiscal year variant fiscal year variant.fiscal year variant fiscal year variant.
fiscal year variant fiscal year variant.
 
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
 
如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样
如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样
如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样
 
zOS Mainframe JES2-JES3 JCL-JECL Differences
zOS Mainframe JES2-JES3 JCL-JECL DifferenceszOS Mainframe JES2-JES3 JCL-JECL Differences
zOS Mainframe JES2-JES3 JCL-JECL Differences
 
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
 
一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理
 
Modelling Up - DDDEurope 2024 - Amsterdam
Modelling Up - DDDEurope 2024 - AmsterdamModelling Up - DDDEurope 2024 - Amsterdam
Modelling Up - DDDEurope 2024 - Amsterdam
 
The Key to Digital Success_ A Comprehensive Guide to Continuous Testing Integ...
The Key to Digital Success_ A Comprehensive Guide to Continuous Testing Integ...The Key to Digital Success_ A Comprehensive Guide to Continuous Testing Integ...
The Key to Digital Success_ A Comprehensive Guide to Continuous Testing Integ...
 
Using Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query PerformanceUsing Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query Performance
 
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling ExtensionsUI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
 
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, FactsALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
 
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdfTop Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
 
Oracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptxOracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptx
 
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)
 
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
 
Project Management: The Role of Project Dashboards.pdf
Project Management: The Role of Project Dashboards.pdfProject Management: The Role of Project Dashboards.pdf
Project Management: The Role of Project Dashboards.pdf
 
YAML crash COURSE how to write yaml file for adding configuring details
YAML crash COURSE how to write yaml file for adding configuring detailsYAML crash COURSE how to write yaml file for adding configuring details
YAML crash COURSE how to write yaml file for adding configuring details
 
Liberarsi dai framework con i Web Component.pptx
Liberarsi dai framework con i Web Component.pptxLiberarsi dai framework con i Web Component.pptx
Liberarsi dai framework con i Web Component.pptx
 

Lettuce example using simple scenario

  • 1. Lettuce example using simple scenarios: El siguienteejemplotienetresarchivos,un feature ydospy.En el siguiente ejemplo atacaremosla api del tiempoycomprobaremosque ciertosvaloresseancorrectos. Paraello utilizaremos lettuce conpython. Ademásutilizaremosscenariossimples. Weather.feature: Feature:Checkif the weatherservice worksproperly In orderto check the weatherservice As beginner I'll get some valuesandcheckif theyare okand if the temperature giveniscorrect Scenario:Checkif a cityand a countrygivenare correct GivenI accessthe url withhttp://api.openweathermap.org/data/2.5/weather Andthe cityis Londonandthe countryGB WhenI ask for the cityand country name ThenI check if the city andcountry are correct AndI checkif the status code is200 Scenario:Checkif a latitude andlongitudegivenare correct GivenI accessthe url withhttp://api.openweathermap.org/data/2.5/weather Andthe latitude is35 and the longitude 139 WhenI ask for the latitude andlongitude ThenI check if the latitude andlongitude are correct AndI checkif the status code is200 Scenario:Checkif the temperature iscorrectgivenacity anda country GivenI accessthe url withhttp://api.openweathermap.org/data/2.5/weather Andthe cityis Madridand the country ES WhenI ask for the cityand country name ThenI get the temperature lookbycityandcountry Scenario:Checkif the temperature iscorrectgiventhe latitude andlongitude GivenI accessthe url withhttp://api.openweathermap.org/data/2.5/weather Andthe latitude is35 and the longitude 139 WhenI ask for weatherinformationbylatitudeandlongitude ThenI get the temperature lookbylatitude andlongitude weatherSteps.py: __author__ = 'kwiznia' fromlettuce import* fromweather2import* fromnose.toolsimport*
  • 2. weather2= weather2() @step("Iaccessthe url with(.*)") def access_url(self,expectedUrl): world.expectedUrl =expectedUrl assert_regexp_matches(world.expectedUrl,'^http'),"The URL isempty" @step("the cityis(Madrid|London|Barcelona|Berlin)andthe country(GB|ES|Germany)") def city_and_country(self,expectedCity,expectedCountry): world.expectedCity =expectedCity world.expectedCountry=expectedCountry @step("Iaskfor the cityand countryname") def ask_for_city_and_country(self): world.url = world.expectedUrl +"?q=" + world.expectedCity+","+ world.expectedCountry world.page_info =weather2.getInformation(world.url) @step("Icheckif the cityand country are correct") def check_city_and_country_are_correct(self): sys = world.page_info['sys'] assertsys != "" assertworld.expectedCityinworld.page_info['name'] assertworld.expectedCountryinsys['country'] @step("Icheckif the statuscode is200") def check_status_code(self): assert_equals(world.response.status_code,200),"page not found" @step("the latitude is(40|35|41.3|53.2) andthe longitude (-3.7|139|2.1|13.3)") def check_lat_and_long(self,expectedLatitude,expectedLongitude): world.expectedLatitude =expectedLatitude world.expectedLongitude =expectedLongitude @step("Iaskfor the latitude andlongitude") def ask_for_lat_and_long(self): world.url = world.expectedUrl +"?lat=" + world.expectedLatitude +"&lon="+ world.expectedLongitude world.page_info=weather2.getInformation(world.url) @step("Icheckif the latitude andlongitudeare correct") def check_lat_and_long_are_correct(self): latlon= world.page_info['coord'] assertlatlon['lon'] !="" assertlatlon['lat'] !="" assert_equals(int(world.expectedLatitude),latlon['lat'])
  • 3. assert_equals(int(world.expectedLongitude),latlon['lon']) @step("Igetthe temperature lookbycityandcountry") def get_temperature_look_by_city(self): temperature =world.page_info['main'] temperatuce_farenhait=temperature['temp'] asserttemperatuce_farenhait!="" @step("Iaskfor weatherinformationbylatitudeandlongitude") def ask_for_weather_information_by_latlong(self): world.url = world.expectedUrl +"?lat=" + world.expectedLatitude +"&lon="+ world.expectedLongitude world.page_info_by_latlon=weather2.getInformation(world.url) @step("Igetthe temperature lookbylatitudeandlongitude") def get_temperature_by_latlong(self): temperature =world.page_info_by_latlon['main'] temperatuce_farenhait=temperature['temp'] asserttemperatuce_farenhait!="" weather.py: __author__ = 'kwiznia' importrequests fromlettuce importworld importjson classweather2(): """ def getStatus_code(self,response): world.response=response world.response=requests.get(response) returnworld.response.status_code """ def getInformation(self,response): world.response=requests.get(response) returnworld.response.json()