Like to try Cypress without installing it by yourself? Then download this Ubuntu VM for VirtualBox!
https://drive.google.com/file/d/1gq8fBKUrMyXZ7H1Y0Fv7LtLk0vYH3sDU/view
user and password: osboxes.org
Start Cypress in new Terminal window with command:
osboxes@osboxes:
cd ~/Work/Cypress && npm run cypress:open
Example testcase 1:
describe('Check if the Hotel App from Adactin is available', function() {
it('Visits the Adactin Hotel App website', function() {
cy.visit('https://adactin.com/HotelApp/')
cy.contains('Welcome to AdactIn Group of Hotels')
cy.get('#username')
.type('Cucumbertestuser')
cy.get('#password')
.type('cucumbertestuser')
cy.get('#login').click()
})
})
Install Visual Studio code if you need another IDE to edit Cypress scripts:
https://websiteforstudents.com/install-visual-studio-code-on-ubuntu-16-04-18-04/
Example testcase 2:
describe('Check if you can book a room with the Hotel App from Adactin', function () {
const todaysDate = Cypress.moment().format('DD/MM/YYYY')
const fourteenDaysForward = Cypress.moment().add(14, 'day');
const todaysDatePlus14 = Cypress.moment(fourteenDaysForward).format('DD/MM/YYYY');
const twoYearsForward = Cypress.moment().add(2, 'year');
const todaysDatePlusTwoYears = Cypress.moment(twoYearsForward).format('YYYY');
beforeEach(function () {
// login on the website before each test
cy.visit('https://adactin.com/HotelApp/')
cy.contains('Welcome to AdactIn Group of Hotels')
cy.get('#username')
.type('Cucumbertestuser')
cy.get('#password')
.type('cucumbertestuser')
cy.get('#login').click()
cy.contains('Search Hotel')
cy.contains('Fields marked with Red asterix (*) are mandatory')
})
function fillsearchscreen(Location, Hotels, RoomType, RoomNos, DatepickIn, DatepickOut, AdultRoom, ChildRoom) {
cy.get('#location')
.select(Location)
cy.get('#hotels')
.select(Hotels)
cy.get('#room_type')
.select(RoomType)
cy.get('#room_nos')
.select(RoomNos)
cy.get('#datepick_in').clear()
.type(DatepickIn)
cy.get('#datepick_out').clear()
.type(DatepickOut)
cy.get('#adult_room')
.select(AdultRoom)
cy.get('#child_room')
.select(ChildRoom)
cy.get('#Submit').click()
cy.contains('Select Hotel')
}
// it('can fill the screen for search hotel', function () {
// fillsearchscreen('London', 'Hotel Sunshine', 'Double', '2 - Two', todaysDate, todaysDatePlus14, '2 - Two', '2 - Two')
// })
// it('can select a hotel after searching', function () {
// fillsearchscreen('London', 'Hotel Sunshine', 'Double', '2 - Two', todaysDate, todaysDatePlus14, '2 - Two', '2 - Two')
// cy.get('#radiobutton_0').click()
// cy.get('#continue').click()
// cy.contains('Book A Hotel')
// })
// it('can select the second hotel after searching', function () {
// fillsearchscreen('Sydney', '- Select Hotel -', 'Double', '2 - Two', todaysDate, todaysDatePlus14, '2 - Two', '2 - Two')
// cy.get('#radiobutton_2').click()
// cy.get('#continue').click()
// cy.contains('Book A Hotel')
// })
it('can book an hotel and search it in the reservation menu', function () {
fillsearchscreen('Sydney', '- Select Hotel -', 'Double', '2 - Two', todaysDate, todaysDatePlus14, '2 - Two', '2 - Two')
cy.get('#radiobutton_2').click()
cy.get('#continue').click()
cy.contains('Book A Hotel')
cy.get('#first_name')
.type('CypressFirst')
cy.get('#last_name')
.type('CypressLast')
cy.get('#address')
.type('CypressAddress')
cy.get('#cc_num')
.type('1234567812345678')
cy.get('#cc_type')
.select('VISA')
cy.get('#cc_exp_month')
.select('June')
cy.get('#cc_exp_year')
.select(todaysDatePlusTwoYears)
cy.get('#cc_cvv')
.type('1234')
cy.get('#book_now').click()
cy.contains('Please wait! We are processing your Hotel Booking').should('be.visible')
cy.contains('Booking Confirmation').should('be.visible')
cy.get('#order_no').then(ordernr => {
const OrderNo = Cypress.$(ordernr).val();
cy.get('#my_itinerary').click()
cy.contains('Search Order Id')
cy.get('#order_id_text')
.type(OrderNo)
cy.get('#search_hotel_id').click()
cy.contains('1 result(s) found').should('be.visible')
cy.get('tr:nth-child(2) > td:nth-child(2) > input').should('have.value', OrderNo)
cy.get('td:nth-child(4) > input').should('have.value', 'Hotel Creek')
cy.get('#check_all').click()
cy.get('input.reg_button:nth-child(1)').click()
cy.get('#order_id_text')
.type(OrderNo)
cy.get('#search_hotel_id').click()
cy.contains('0 result(s) found').should('be.visible')
});
})
})
Or a project* with this above example combining Cucumber and Cypress:
Cypress Cucumber Example project
*source: https://github.com/TheBrainFamily/cypress-cucumber-example