SlideShare a Scribd company logo
1 of 3
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 outlineKaren 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 doManning Publications
 
Re-analysis of Umbraco code
Re-analysis of Umbraco codeRe-analysis of Umbraco code
Re-analysis of Umbraco codePVS-Studio
 
PhoneGap - Hardware Manipulation
PhoneGap - Hardware ManipulationPhoneGap - Hardware Manipulation
PhoneGap - Hardware ManipulationDoncho 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 projectPVS-Studio
 
C++ Course - Lesson 1
C++ Course - Lesson 1C++ Course - Lesson 1
C++ Course - Lesson 1Mohamed 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 systemsJason 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 EngineAndy 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 andiDynatrace
 
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 PrimerAdam Englander
 
Asynchronous programming patterns in Perl
Asynchronous programming patterns in PerlAsynchronous programming patterns in Perl
Asynchronous programming patterns in Perldeepfountainconsulting
 
"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 MoldovanFwdays
 

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 finalKaren Wiznia
 
Arduino - código - video
Arduino - código - videoArduino - código - video
Arduino - código - videoKaren Wiznia
 
Arduino - telesketch automático
Arduino - telesketch automáticoArduino - telesketch automático
Arduino - telesketch automáticoKaren Wiznia
 
Requests lettuce y python
Requests lettuce y pythonRequests lettuce y python
Requests lettuce y pythonKaren Wiznia
 
Testing & selenium - examples
Testing & selenium - examplesTesting & selenium - examples
Testing & selenium - examplesKaren Wiznia
 
Requests con lettuce y python
Requests con lettuce y pythonRequests con lettuce y python
Requests con lettuce y pythonKaren Wiznia
 
Selenium with lettuce and python
Selenium with lettuce and pythonSelenium with lettuce and python
Selenium with lettuce and pythonKaren Wiznia
 
Crear un repositorio con Gir Bash
Crear un repositorio con Gir BashCrear un repositorio con Gir Bash
Crear un repositorio con Gir BashKaren 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

Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsSafe Software
 
eSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration toolseSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration toolsosttopstonverter
 
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptxReal-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptxRTS corp
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxAndreas Kunz
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprisepreethippts
 
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...OnePlan Solutions
 
SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?Alexandre Beguel
 
Understanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM ArchitectureUnderstanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM Architecturerahul_net
 
Osi security architecture in network.pptx
Osi security architecture in network.pptxOsi security architecture in network.pptx
Osi security architecture in network.pptxVinzoCenzo
 
VictoriaMetrics Q1 Meet Up '24 - Community & News Update
VictoriaMetrics Q1 Meet Up '24 - Community & News UpdateVictoriaMetrics Q1 Meet Up '24 - Community & News Update
VictoriaMetrics Q1 Meet Up '24 - Community & News UpdateVictoriaMetrics
 
Keeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository worldKeeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository worldRoberto Pérez Alcolea
 
Large Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLarge Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLionel Briand
 
Strategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero resultsStrategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero resultsJean Silva
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identityteam-WIBU
 
Salesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZSalesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZABSYZ Inc
 
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full RecordingOpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full RecordingShane Coughlan
 
What’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 UpdatesWhat’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 UpdatesVictoriaMetrics
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...OnePlan Solutions
 
Ronisha Informatics Private Limited Catalogue
Ronisha Informatics Private Limited CatalogueRonisha Informatics Private Limited Catalogue
Ronisha Informatics Private Limited Catalogueitservices996
 
Amazon Bedrock in Action - presentation of the Bedrock's capabilities
Amazon Bedrock in Action - presentation of the Bedrock's capabilitiesAmazon Bedrock in Action - presentation of the Bedrock's capabilities
Amazon Bedrock in Action - presentation of the Bedrock's capabilitiesKrzysztofKkol1
 

Recently uploaded (20)

Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data Streams
 
eSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration toolseSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration tools
 
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptxReal-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprise
 
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
 
SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?
 
Understanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM ArchitectureUnderstanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM Architecture
 
Osi security architecture in network.pptx
Osi security architecture in network.pptxOsi security architecture in network.pptx
Osi security architecture in network.pptx
 
VictoriaMetrics Q1 Meet Up '24 - Community & News Update
VictoriaMetrics Q1 Meet Up '24 - Community & News UpdateVictoriaMetrics Q1 Meet Up '24 - Community & News Update
VictoriaMetrics Q1 Meet Up '24 - Community & News Update
 
Keeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository worldKeeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository world
 
Large Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLarge Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and Repair
 
Strategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero resultsStrategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero results
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identity
 
Salesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZSalesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZ
 
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full RecordingOpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
 
What’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 UpdatesWhat’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 Updates
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
 
Ronisha Informatics Private Limited Catalogue
Ronisha Informatics Private Limited CatalogueRonisha Informatics Private Limited Catalogue
Ronisha Informatics Private Limited Catalogue
 
Amazon Bedrock in Action - presentation of the Bedrock's capabilities
Amazon Bedrock in Action - presentation of the Bedrock's capabilitiesAmazon Bedrock in Action - presentation of the Bedrock's capabilities
Amazon Bedrock in Action - presentation of the Bedrock's capabilities
 

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()