SlideShare a Scribd company logo
1 of 3
Download to read offline
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

Effectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryErrorEffectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryErrorTier1 app
 
oracle 23c new features for developer and dba
oracle 23c new features for developer and dbaoracle 23c new features for developer and dba
oracle 23c new features for developer and dbaRemote DBA Services
 
ETE PPT.pdf LMMKLMKLMLKMLLMJKBHJBHBNUIHBU
ETE PPT.pdf LMMKLMKLMLKMLLMJKBHJBHBNUIHBUETE PPT.pdf LMMKLMKLMLKMLLMJKBHJBHBNUIHBU
ETE PPT.pdf LMMKLMKLMLKMLLMJKBHJBHBNUIHBUsamruddhijedgule2004
 
Advantages of Cargo Cloud Solutions.pptx
Advantages of Cargo Cloud Solutions.pptxAdvantages of Cargo Cloud Solutions.pptx
Advantages of Cargo Cloud Solutions.pptxRTS corp
 
Business Analyzopedia - Your Pocket Gita for Business Analysis
Business Analyzopedia - Your Pocket Gita for Business AnalysisBusiness Analyzopedia - Your Pocket Gita for Business Analysis
Business Analyzopedia - Your Pocket Gita for Business AnalysisDEEPRAJ PATHAK
 
Zer0con 2024 final share short version.pdf
Zer0con 2024 final share short version.pdfZer0con 2024 final share short version.pdf
Zer0con 2024 final share short version.pdfmaor17
 
What are the core components of Azure Data Engineer courses.docx
What are the core components of Azure Data Engineer courses.docxWhat are the core components of Azure Data Engineer courses.docx
What are the core components of Azure Data Engineer courses.docxkzayra69
 
GraphSummit Madrid - Product Vision and Roadmap - Luis Salvador Neo4j
GraphSummit Madrid - Product Vision and Roadmap - Luis Salvador Neo4jGraphSummit Madrid - Product Vision and Roadmap - Luis Salvador Neo4j
GraphSummit Madrid - Product Vision and Roadmap - Luis Salvador Neo4jNeo4j
 
Chapter -5 Agile Testing types and its examples.pptx
Chapter -5 Agile Testing types and its examples.pptxChapter -5 Agile Testing types and its examples.pptx
Chapter -5 Agile Testing types and its examples.pptxManishaPatil932723
 
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...OnePlan Solutions
 
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdfAndrey Devyatkin
 
ManageIQ - Sprint 234 Review - Slide Deck
ManageIQ - Sprint 234 Review - Slide DeckManageIQ - Sprint 234 Review - Slide Deck
ManageIQ - Sprint 234 Review - Slide DeckManageIQ
 
Effort Estimation Techniques used in Software Projects
Effort Estimation Techniques used in Software ProjectsEffort Estimation Techniques used in Software Projects
Effort Estimation Techniques used in Software ProjectsDEEPRAJ PATHAK
 
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
 
AmsterdamJUG April 2024 - Going serverless with Quarkus GraalVM native images...
AmsterdamJUG April 2024 - Going serverless with Quarkus GraalVM native images...AmsterdamJUG April 2024 - Going serverless with Quarkus GraalVM native images...
AmsterdamJUG April 2024 - Going serverless with Quarkus GraalVM native images...Bert Jan Schrijver
 
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
 
What is Mendix and the concept of low-code development.docx
What is Mendix and the concept of low-code development.docxWhat is Mendix and the concept of low-code development.docx
What is Mendix and the concept of low-code development.docxTechnogeeks
 
Explore the Three Main Types of Logistics - Inbound Logistics, Outbound Logis...
Explore the Three Main Types of Logistics - Inbound Logistics, Outbound Logis...Explore the Three Main Types of Logistics - Inbound Logistics, Outbound Logis...
Explore the Three Main Types of Logistics - Inbound Logistics, Outbound Logis...Piyovi
 
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...Bert Jan Schrijver
 
full course of software engineering mid term.pdf
full course of software engineering mid term.pdffull course of software engineering mid term.pdf
full course of software engineering mid term.pdfAbdul salam
 

Recently uploaded (20)

Effectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryErrorEffectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryError
 
oracle 23c new features for developer and dba
oracle 23c new features for developer and dbaoracle 23c new features for developer and dba
oracle 23c new features for developer and dba
 
ETE PPT.pdf LMMKLMKLMLKMLLMJKBHJBHBNUIHBU
ETE PPT.pdf LMMKLMKLMLKMLLMJKBHJBHBNUIHBUETE PPT.pdf LMMKLMKLMLKMLLMJKBHJBHBNUIHBU
ETE PPT.pdf LMMKLMKLMLKMLLMJKBHJBHBNUIHBU
 
Advantages of Cargo Cloud Solutions.pptx
Advantages of Cargo Cloud Solutions.pptxAdvantages of Cargo Cloud Solutions.pptx
Advantages of Cargo Cloud Solutions.pptx
 
Business Analyzopedia - Your Pocket Gita for Business Analysis
Business Analyzopedia - Your Pocket Gita for Business AnalysisBusiness Analyzopedia - Your Pocket Gita for Business Analysis
Business Analyzopedia - Your Pocket Gita for Business Analysis
 
Zer0con 2024 final share short version.pdf
Zer0con 2024 final share short version.pdfZer0con 2024 final share short version.pdf
Zer0con 2024 final share short version.pdf
 
What are the core components of Azure Data Engineer courses.docx
What are the core components of Azure Data Engineer courses.docxWhat are the core components of Azure Data Engineer courses.docx
What are the core components of Azure Data Engineer courses.docx
 
GraphSummit Madrid - Product Vision and Roadmap - Luis Salvador Neo4j
GraphSummit Madrid - Product Vision and Roadmap - Luis Salvador Neo4jGraphSummit Madrid - Product Vision and Roadmap - Luis Salvador Neo4j
GraphSummit Madrid - Product Vision and Roadmap - Luis Salvador Neo4j
 
Chapter -5 Agile Testing types and its examples.pptx
Chapter -5 Agile Testing types and its examples.pptxChapter -5 Agile Testing types and its examples.pptx
Chapter -5 Agile Testing types and its examples.pptx
 
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
 
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf
 
ManageIQ - Sprint 234 Review - Slide Deck
ManageIQ - Sprint 234 Review - Slide DeckManageIQ - Sprint 234 Review - Slide Deck
ManageIQ - Sprint 234 Review - Slide Deck
 
Effort Estimation Techniques used in Software Projects
Effort Estimation Techniques used in Software ProjectsEffort Estimation Techniques used in Software Projects
Effort Estimation Techniques used in Software Projects
 
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
 
AmsterdamJUG April 2024 - Going serverless with Quarkus GraalVM native images...
AmsterdamJUG April 2024 - Going serverless with Quarkus GraalVM native images...AmsterdamJUG April 2024 - Going serverless with Quarkus GraalVM native images...
AmsterdamJUG April 2024 - Going serverless with Quarkus GraalVM native images...
 
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 ?
 
What is Mendix and the concept of low-code development.docx
What is Mendix and the concept of low-code development.docxWhat is Mendix and the concept of low-code development.docx
What is Mendix and the concept of low-code development.docx
 
Explore the Three Main Types of Logistics - Inbound Logistics, Outbound Logis...
Explore the Three Main Types of Logistics - Inbound Logistics, Outbound Logis...Explore the Three Main Types of Logistics - Inbound Logistics, Outbound Logis...
Explore the Three Main Types of Logistics - Inbound Logistics, Outbound Logis...
 
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
 
full course of software engineering mid term.pdf
full course of software engineering mid term.pdffull course of software engineering mid term.pdf
full course of software engineering mid term.pdf
 

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