Skip to content

Commit

Permalink
add bonus 52 spec
Browse files Browse the repository at this point in the history
  • Loading branch information
bahmutov committed Jun 22, 2023
1 parent dabd589 commit bfcf6d1
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 25 deletions.
25 changes: 0 additions & 25 deletions cypress/e2e/misc/two-domains.cy.ts

This file was deleted.

43 changes: 43 additions & 0 deletions cypress/e2e/misc/two-tests-two-domains.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { LoginPage } from '@support/pages/login.page'
import { LoginInfo } from '..'

// make sure to start the second server
// using "npm run start:2nd" NPM alias
// It should host a page at "localhost:5555"
// with the name of the item the user won

// the name of the item will be set in the first test
let name: string

it('gets the item name', { baseUrl: 'http://localhost:5555' }, () => {
// visit the base page of the second domain
// https://on.cypress.io/visit
cy.visit('/')
// get the winning item name
// and store it in the local variable "name"
cy.get('.won')
.invoke('text')
.then((s) => {
name = s
cy.log(`won item ${name}`)
})
})

it('has the winning item', () => {
// we are back to the default "baseUrl"
// print the name of the item we found in the first test
cy.log(`checking item ${name}`)

// log in using the LoginPage method
const user: LoginInfo = Cypress.env('users').standard
LoginPage.login(user.username, user.password)
// visit the inventory page
// and confirm it contains the winning item by name
cy.visit('/inventory.html')
cy.contains('.inventory_item', name)
// scroll the winning item into the current viewport
// https://on.cypress.io/scrollintoview
.scrollIntoView()
// Bonus: highlight the winning item by giving it a magenta border
.invoke('css', 'border', '2px solid magenta')
})

0 comments on commit bfcf6d1

Please sign in to comment.