SlideShare a Scribd company logo
1 of 4
Lettuce example using scenarios
outline:
El siguiente ejemplo tiene tres archivos, un feature y dos py. En el siguiente ejemplo
atacaremos la api del tiempo y comprobaremos que ciertos valores sean correctos. Para ello
utilizaremos lettuce con python. Además utilizaremos scenarios Outline.
Weather2.feature:
Feature: Check if the weather service works properly
In order to check the weather service
As beginner
I'll get some values and check if they are ok and if the temperature given is correct
Scenario Outline: Check if a city and and country given are correct
Given I access the url with http://api.openweathermap.org/data/2.5/weather
And the city is <city> and the country <country>
When I ask for the city and country name
Then I check if the city and country are correct
And I check if the status code is 200
Examples:
| city | country |
| London | GB |
| Madrid | ES |
| Barcelona | ES |
Scenario Outline: Check if a latitude and longitude given are correct
Given I access the url with http://api.openweathermap.org/data/2.5/weather
And the latitude is <latitude> and the longitude <longitude>
When I ask for the latitude and longitude
Then I check if the latitude and longitude are correct
And I check if the status code is 200
Examples:
| latitude | longitude |
| 51.51 | -0.13 |
| 40.42 | 3.7 |
| 10.13 | -64.7 |
Scenario Outline: Check if the temperature is correct given a city and a country
Given I access the url with http://api.openweathermap.org/data/2.5/weather
And the city is <city> and the country <country>
When I ask for the city and country name
Then I get the temperature look by city and country
Examples:
| city | country |
| London | GB |
| Madrid | ES |
| Barcelona | ES |
Scenario Outline: Check if the temperature is correct given the latitude and longitude
Given I access the url with http://api.openweathermap.org/data/2.5/weather
And the latitude is <latitude> and the longitude <longitude>
When I ask for weather information by latitude and longitude
Then I get the temperature look by latitude and longitude
Examples:
| latitude | longitude |
| 51.51 | -0.13 |
| 40.42 | 3.7 |
| 10.13 | -64.7 |
Weather2.py:
__author__ = 'kwiznia'
import requests
from lettuce import world
import json
class weather2():
"""
def getStatus_code(self, response):
world.response = response
world.response = requests.get(response)
return world.response.status_code
"""
def getInformation(self, response):
world.response = requests.get(response)
return world.response.json()
weather2steps.py:
__author__ = 'kwiznia'
from lettuce import *
from weather2 import *
from nose.tools import *
weather2 = weather2()
@step("I access the url with (.*)")
def access_url(self, expectedUrl):
world.expectedUrl = expectedUrl
assert_regexp_matches(world.expectedUrl, '^http'), "The URL is empty"
@step('the city is ([^"]+) and the country ([^"]+)')
def city_and_country(self, expectedCity, expectedCountry):
world.expectedCity = expectedCity
world.expectedCountry = expectedCountry
@step("I ask for the city and country name")
def ask_for_city_and_country(self):
world.url = world.expectedUrl + "?q=" + world.expectedCity + "," + world.expectedCountry
world.page_info = weather2.getInformation(world.url)
@step("I check if the city and country are correct")
def check_city_and_country_are_correct(self):
sys = world.page_info['sys']
assert sys != ""
assert world.expectedCity in world.page_info['name']
assert world.expectedCountry in sys['country']
@step("I check if the status code is 200")
def check_status_code(self):
assert_equals(world.response.status_code, 200), "page not found"
@step('the latitude is ([^"]+) and the longitude ([^"]+)')
def check_lat_and_long(self, expectedLatitude, expectedLongitude):
world.expectedLatitude = expectedLatitude
world.expectedLongitude = expectedLongitude
@step("I ask for the latitude and longitude")
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("I check if the latitude and longitude are correct")
def check_lat_and_long_are_correct(self):
latlon = world.page_info['coord']
assert latlon['lon'] != ""
assert latlon['lat'] != ""
assert_equals(float(world.expectedLatitude), latlon['lat'])
assert_equals(float(world.expectedLongitude), latlon['lon'])
@step("I get the temperature look by city and country")
def get_temperature_look_by_city(self):
temperature = world.page_info['main']
temperatuce_farenhait = temperature['temp']
assert temperatuce_farenhait != ""
@step("I ask for weather information by latitude and longitude")
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("I get the temperature look by latitude and longitude")
def get_temperature_by_latlong(self):
temperature = world.page_info_by_latlon['main']
temperatuce_farenhait = temperature['temp']
assert temperatuce_farenhait != ""

More Related Content

Similar to Lettuce example using scenarios outline

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
 
Rethinking Syncing at AltConf 2019
Rethinking Syncing at AltConf 2019Rethinking Syncing at AltConf 2019
Rethinking Syncing at AltConf 2019Joe Keeley
 
Code implementation.pptx
Code implementation.pptxCode implementation.pptx
Code implementation.pptxAasimAbdul
 
Analyzing Air Quality Measurements in Macedonia with Apache Drill
Analyzing Air Quality Measurements in Macedonia with Apache DrillAnalyzing Air Quality Measurements in Macedonia with Apache Drill
Analyzing Air Quality Measurements in Macedonia with Apache DrillMarjan Sterjev
 
Monitoring Your ISP Using InfluxDB Cloud and Raspberry Pi
Monitoring Your ISP Using InfluxDB Cloud and Raspberry PiMonitoring Your ISP Using InfluxDB Cloud and Raspberry Pi
Monitoring Your ISP Using InfluxDB Cloud and Raspberry PiInfluxData
 
Predicting landing distance: Adrian Valles
Predicting landing distance: Adrian VallesPredicting landing distance: Adrian Valles
Predicting landing distance: Adrian VallesAdrián Vallés
 
In this assignment you will practice creating classes and enumeratio.pdf
In this assignment you will practice creating classes and enumeratio.pdfIn this assignment you will practice creating classes and enumeratio.pdf
In this assignment you will practice creating classes and enumeratio.pdfivylinvaydak64229
 
Mp24: The Bachelor, a facebook game
Mp24: The Bachelor, a facebook gameMp24: The Bachelor, a facebook game
Mp24: The Bachelor, a facebook gameMontreal Python
 
Introduction to ECMAScript 2015
Introduction to ECMAScript 2015Introduction to ECMAScript 2015
Introduction to ECMAScript 2015Tomasz Dziuda
 
PhoneGap - Hardware Manipulation
PhoneGap - Hardware ManipulationPhoneGap - Hardware Manipulation
PhoneGap - Hardware ManipulationDoncho Minkov
 
Context-aware application development with FIWARE #CPBR8
Context-aware application development with FIWARE #CPBR8Context-aware application development with FIWARE #CPBR8
Context-aware application development with FIWARE #CPBR8Fermin Galan
 
Weather scraper for your data warehouse
Weather scraper for your data warehouseWeather scraper for your data warehouse
Weather scraper for your data warehouseFru Louis
 
Angular Promises and Advanced Routing
Angular Promises and Advanced RoutingAngular Promises and Advanced Routing
Angular Promises and Advanced RoutingAlexe Bogdan
 
Classic Games Development with Drools
Classic Games Development with DroolsClassic Games Development with Drools
Classic Games Development with DroolsMark Proctor
 
rules, events and workflow
rules, events and workflowrules, events and workflow
rules, events and workflowMark Proctor
 
REST meets Semantic Web
REST meets Semantic WebREST meets Semantic Web
REST meets Semantic WebSteve Speicher
 
RxJS - The Reactive extensions for JavaScript
RxJS - The Reactive extensions for JavaScriptRxJS - The Reactive extensions for JavaScript
RxJS - The Reactive extensions for JavaScriptViliam Elischer
 
Swift LA Meetup at eHarmony- What's New in Swift 2.0
Swift LA Meetup at eHarmony- What's New in Swift 2.0Swift LA Meetup at eHarmony- What's New in Swift 2.0
Swift LA Meetup at eHarmony- What's New in Swift 2.0Claire Townend Gee
 

Similar to Lettuce example using scenarios outline (20)

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
 
Rethinking Syncing at AltConf 2019
Rethinking Syncing at AltConf 2019Rethinking Syncing at AltConf 2019
Rethinking Syncing at AltConf 2019
 
Code implementation.pptx
Code implementation.pptxCode implementation.pptx
Code implementation.pptx
 
Analyzing Air Quality Measurements in Macedonia with Apache Drill
Analyzing Air Quality Measurements in Macedonia with Apache DrillAnalyzing Air Quality Measurements in Macedonia with Apache Drill
Analyzing Air Quality Measurements in Macedonia with Apache Drill
 
huhu
huhuhuhu
huhu
 
app.js.docx
app.js.docxapp.js.docx
app.js.docx
 
Monitoring Your ISP Using InfluxDB Cloud and Raspberry Pi
Monitoring Your ISP Using InfluxDB Cloud and Raspberry PiMonitoring Your ISP Using InfluxDB Cloud and Raspberry Pi
Monitoring Your ISP Using InfluxDB Cloud and Raspberry Pi
 
Predicting landing distance: Adrian Valles
Predicting landing distance: Adrian VallesPredicting landing distance: Adrian Valles
Predicting landing distance: Adrian Valles
 
In this assignment you will practice creating classes and enumeratio.pdf
In this assignment you will practice creating classes and enumeratio.pdfIn this assignment you will practice creating classes and enumeratio.pdf
In this assignment you will practice creating classes and enumeratio.pdf
 
Mp24: The Bachelor, a facebook game
Mp24: The Bachelor, a facebook gameMp24: The Bachelor, a facebook game
Mp24: The Bachelor, a facebook game
 
Introduction to ECMAScript 2015
Introduction to ECMAScript 2015Introduction to ECMAScript 2015
Introduction to ECMAScript 2015
 
PhoneGap - Hardware Manipulation
PhoneGap - Hardware ManipulationPhoneGap - Hardware Manipulation
PhoneGap - Hardware Manipulation
 
Context-aware application development with FIWARE #CPBR8
Context-aware application development with FIWARE #CPBR8Context-aware application development with FIWARE #CPBR8
Context-aware application development with FIWARE #CPBR8
 
Weather scraper for your data warehouse
Weather scraper for your data warehouseWeather scraper for your data warehouse
Weather scraper for your data warehouse
 
Angular Promises and Advanced Routing
Angular Promises and Advanced RoutingAngular Promises and Advanced Routing
Angular Promises and Advanced Routing
 
Classic Games Development with Drools
Classic Games Development with DroolsClassic Games Development with Drools
Classic Games Development with Drools
 
rules, events and workflow
rules, events and workflowrules, events and workflow
rules, events and workflow
 
REST meets Semantic Web
REST meets Semantic WebREST meets Semantic Web
REST meets Semantic Web
 
RxJS - The Reactive extensions for JavaScript
RxJS - The Reactive extensions for JavaScriptRxJS - The Reactive extensions for JavaScript
RxJS - The Reactive extensions for JavaScript
 
Swift LA Meetup at eHarmony- What's New in Swift 2.0
Swift LA Meetup at eHarmony- What's New in Swift 2.0Swift LA Meetup at eHarmony- What's New in Swift 2.0
Swift LA Meetup at eHarmony- What's New in Swift 2.0
 

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

SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalLionel Briand
 
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...Akihiro Suda
 
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
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Angel Borroy López
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfDrew Moseley
 
Patterns for automating API delivery. API conference
Patterns for automating API delivery. API conferencePatterns for automating API delivery. API conference
Patterns for automating API delivery. API conferencessuser9e7c64
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Natan Silnitsky
 
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
 
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
 
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
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsChristian Birchler
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfMarharyta Nedzelska
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtimeandrehoraa
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 
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
 
Ronisha Informatics Private Limited Catalogue
Ronisha Informatics Private Limited CatalogueRonisha Informatics Private Limited Catalogue
Ronisha Informatics Private Limited Catalogueitservices996
 
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
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf31events.com
 

Recently uploaded (20)

SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive Goal
 
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
 
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
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdf
 
Patterns for automating API delivery. API conference
Patterns for automating API delivery. API conferencePatterns for automating API delivery. API conference
Patterns for automating API delivery. API conference
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
 
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...
 
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
 
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
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdf
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtime
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 
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
 
Ronisha Informatics Private Limited Catalogue
Ronisha Informatics Private Limited CatalogueRonisha Informatics Private Limited Catalogue
Ronisha Informatics Private Limited Catalogue
 
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
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf
 

Lettuce example using scenarios outline

  • 1. Lettuce example using scenarios outline: El siguiente ejemplo tiene tres archivos, un feature y dos py. En el siguiente ejemplo atacaremos la api del tiempo y comprobaremos que ciertos valores sean correctos. Para ello utilizaremos lettuce con python. Además utilizaremos scenarios Outline. Weather2.feature: Feature: Check if the weather service works properly In order to check the weather service As beginner I'll get some values and check if they are ok and if the temperature given is correct Scenario Outline: Check if a city and and country given are correct Given I access the url with http://api.openweathermap.org/data/2.5/weather And the city is <city> and the country <country> When I ask for the city and country name Then I check if the city and country are correct And I check if the status code is 200 Examples: | city | country | | London | GB | | Madrid | ES | | Barcelona | ES | Scenario Outline: Check if a latitude and longitude given are correct Given I access the url with http://api.openweathermap.org/data/2.5/weather And the latitude is <latitude> and the longitude <longitude> When I ask for the latitude and longitude Then I check if the latitude and longitude are correct And I check if the status code is 200 Examples: | latitude | longitude | | 51.51 | -0.13 | | 40.42 | 3.7 | | 10.13 | -64.7 | Scenario Outline: Check if the temperature is correct given a city and a country Given I access the url with http://api.openweathermap.org/data/2.5/weather And the city is <city> and the country <country> When I ask for the city and country name Then I get the temperature look by city and country Examples:
  • 2. | city | country | | London | GB | | Madrid | ES | | Barcelona | ES | Scenario Outline: Check if the temperature is correct given the latitude and longitude Given I access the url with http://api.openweathermap.org/data/2.5/weather And the latitude is <latitude> and the longitude <longitude> When I ask for weather information by latitude and longitude Then I get the temperature look by latitude and longitude Examples: | latitude | longitude | | 51.51 | -0.13 | | 40.42 | 3.7 | | 10.13 | -64.7 | Weather2.py: __author__ = 'kwiznia' import requests from lettuce import world import json class weather2(): """ def getStatus_code(self, response): world.response = response world.response = requests.get(response) return world.response.status_code """ def getInformation(self, response): world.response = requests.get(response) return world.response.json() weather2steps.py: __author__ = 'kwiznia' from lettuce import * from weather2 import * from nose.tools import * weather2 = weather2() @step("I access the url with (.*)") def access_url(self, expectedUrl): world.expectedUrl = expectedUrl assert_regexp_matches(world.expectedUrl, '^http'), "The URL is empty"
  • 3. @step('the city is ([^"]+) and the country ([^"]+)') def city_and_country(self, expectedCity, expectedCountry): world.expectedCity = expectedCity world.expectedCountry = expectedCountry @step("I ask for the city and country name") def ask_for_city_and_country(self): world.url = world.expectedUrl + "?q=" + world.expectedCity + "," + world.expectedCountry world.page_info = weather2.getInformation(world.url) @step("I check if the city and country are correct") def check_city_and_country_are_correct(self): sys = world.page_info['sys'] assert sys != "" assert world.expectedCity in world.page_info['name'] assert world.expectedCountry in sys['country'] @step("I check if the status code is 200") def check_status_code(self): assert_equals(world.response.status_code, 200), "page not found" @step('the latitude is ([^"]+) and the longitude ([^"]+)') def check_lat_and_long(self, expectedLatitude, expectedLongitude): world.expectedLatitude = expectedLatitude world.expectedLongitude = expectedLongitude @step("I ask for the latitude and longitude") 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("I check if the latitude and longitude are correct") def check_lat_and_long_are_correct(self): latlon = world.page_info['coord'] assert latlon['lon'] != "" assert latlon['lat'] != "" assert_equals(float(world.expectedLatitude), latlon['lat']) assert_equals(float(world.expectedLongitude), latlon['lon']) @step("I get the temperature look by city and country") def get_temperature_look_by_city(self): temperature = world.page_info['main']
  • 4. temperatuce_farenhait = temperature['temp'] assert temperatuce_farenhait != "" @step("I ask for weather information by latitude and longitude") 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("I get the temperature look by latitude and longitude") def get_temperature_by_latlong(self): temperature = world.page_info_by_latlon['main'] temperatuce_farenhait = temperature['temp'] assert temperatuce_farenhait != ""