tonder-web-sdk 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. package/.env-example +1 -0
  2. package/.htaccess +1 -0
  3. package/README.md +204 -0
  4. package/cypress/e2e/1-getting-started/todo.cy.js +143 -0
  5. package/cypress/e2e/2-advanced-examples/actions.cy.js +299 -0
  6. package/cypress/e2e/2-advanced-examples/aliasing.cy.js +39 -0
  7. package/cypress/e2e/2-advanced-examples/assertions.cy.js +176 -0
  8. package/cypress/e2e/2-advanced-examples/connectors.cy.js +98 -0
  9. package/cypress/e2e/2-advanced-examples/cookies.cy.js +118 -0
  10. package/cypress/e2e/2-advanced-examples/cypress_api.cy.js +185 -0
  11. package/cypress/e2e/2-advanced-examples/files.cy.js +85 -0
  12. package/cypress/e2e/2-advanced-examples/location.cy.js +32 -0
  13. package/cypress/e2e/2-advanced-examples/misc.cy.js +104 -0
  14. package/cypress/e2e/2-advanced-examples/navigation.cy.js +56 -0
  15. package/cypress/e2e/2-advanced-examples/network_requests.cy.js +163 -0
  16. package/cypress/e2e/2-advanced-examples/querying.cy.js +114 -0
  17. package/cypress/e2e/2-advanced-examples/spies_stubs_clocks.cy.js +201 -0
  18. package/cypress/e2e/2-advanced-examples/storage.cy.js +110 -0
  19. package/cypress/e2e/2-advanced-examples/traversal.cy.js +121 -0
  20. package/cypress/e2e/2-advanced-examples/utilities.cy.js +108 -0
  21. package/cypress/e2e/2-advanced-examples/viewport.cy.js +58 -0
  22. package/cypress/e2e/2-advanced-examples/waiting.cy.js +30 -0
  23. package/cypress/e2e/2-advanced-examples/window.cy.js +22 -0
  24. package/cypress/fixtures/example.json +5 -0
  25. package/cypress/support/commands.js +25 -0
  26. package/cypress/support/e2e.js +20 -0
  27. package/cypress.config.js +9 -0
  28. package/index.html +178 -0
  29. package/index.js.example +50 -0
  30. package/package.json +29 -0
  31. package/samples/react/README.md +70 -0
  32. package/samples/react/build/asset-manifest.json +16 -0
  33. package/samples/react/build/favicon.ico +0 -0
  34. package/samples/react/build/index.html +1 -0
  35. package/samples/react/build/logo192.png +0 -0
  36. package/samples/react/build/logo512.png +0 -0
  37. package/samples/react/build/manifest.json +25 -0
  38. package/samples/react/build/robots.txt +3 -0
  39. package/samples/react/build/static/css/main.073c9b0a.css +2 -0
  40. package/samples/react/build/static/css/main.073c9b0a.css.map +1 -0
  41. package/samples/react/build/static/js/787.b83ed06f.chunk.js +2 -0
  42. package/samples/react/build/static/js/787.b83ed06f.chunk.js.map +1 -0
  43. package/samples/react/build/static/js/main.0a848807.js +3 -0
  44. package/samples/react/build/static/js/main.0a848807.js.LICENSE.txt +39 -0
  45. package/samples/react/build/static/js/main.0a848807.js.map +1 -0
  46. package/samples/react/build/static/media/sdk-icons.b491623214b2af4cccdb.png +0 -0
  47. package/samples/react/package-lock.json +28973 -0
  48. package/samples/react/package.json +44 -0
  49. package/samples/react/public/favicon.ico +0 -0
  50. package/samples/react/public/index.html +43 -0
  51. package/samples/react/public/logo192.png +0 -0
  52. package/samples/react/public/logo512.png +0 -0
  53. package/samples/react/public/manifest.json +25 -0
  54. package/samples/react/public/robots.txt +3 -0
  55. package/samples/react/src/App.css +38 -0
  56. package/samples/react/src/App.js +22 -0
  57. package/samples/react/src/App.test.js +8 -0
  58. package/samples/react/src/assets/img/sdk-icons.png +0 -0
  59. package/samples/react/src/components/Cart.js +29 -0
  60. package/samples/react/src/components/ProductCard.js +27 -0
  61. package/samples/react/src/context/CartContext.js +116 -0
  62. package/samples/react/src/index.css +13 -0
  63. package/samples/react/src/index.js +17 -0
  64. package/samples/react/src/logo.svg +1 -0
  65. package/samples/react/src/reportWebVitals.js +13 -0
  66. package/samples/react/src/screens/Checkout.js +82 -0
  67. package/samples/react/src/screens/Store.js +21 -0
  68. package/samples/react/src/setupTests.js +5 -0
  69. package/samples/react/src/storeProducts.js +30 -0
  70. package/src/classes/3dsHandler.js +203 -0
  71. package/src/classes/checkout.js +125 -0
  72. package/src/classes/inlineCheckout.js +349 -0
  73. package/src/data/api.js +109 -0
  74. package/src/helpers/skyflow.js +139 -0
  75. package/src/helpers/styles.js +61 -0
  76. package/src/helpers/template.js +112 -0
  77. package/src/helpers/utils.js +68 -0
  78. package/src/index-dev.js +129 -0
  79. package/src/index.html +58 -0
  80. package/src/index.js +7 -0
  81. package/success.html +22 -0
  82. package/v1/bundle.min.js +18 -0
  83. package/webpack.config.js +66 -0
@@ -0,0 +1,176 @@
1
+ /// <reference types="cypress" />
2
+
3
+ context('Assertions', () => {
4
+ beforeEach(() => {
5
+ cy.visit('https://example.cypress.io/commands/assertions')
6
+ })
7
+
8
+ describe('Implicit Assertions', () => {
9
+ it('.should() - make an assertion about the current subject', () => {
10
+ // https://on.cypress.io/should
11
+ cy.get('.assertion-table')
12
+ .find('tbody tr:last')
13
+ .should('have.class', 'success')
14
+ .find('td')
15
+ .first()
16
+ // checking the text of the <td> element in various ways
17
+ .should('have.text', 'Column content')
18
+ .should('contain', 'Column content')
19
+ .should('have.html', 'Column content')
20
+ // chai-jquery uses "is()" to check if element matches selector
21
+ .should('match', 'td')
22
+ // to match text content against a regular expression
23
+ // first need to invoke jQuery method text()
24
+ // and then match using regular expression
25
+ .invoke('text')
26
+ .should('match', /column content/i)
27
+
28
+ // a better way to check element's text content against a regular expression
29
+ // is to use "cy.contains"
30
+ // https://on.cypress.io/contains
31
+ cy.get('.assertion-table')
32
+ .find('tbody tr:last')
33
+ // finds first <td> element with text content matching regular expression
34
+ .contains('td', /column content/i)
35
+ .should('be.visible')
36
+
37
+ // for more information about asserting element's text
38
+ // see https://on.cypress.io/using-cypress-faq#How-do-I-get-an-element’s-text-contents
39
+ })
40
+
41
+ it('.and() - chain multiple assertions together', () => {
42
+ // https://on.cypress.io/and
43
+ cy.get('.assertions-link')
44
+ .should('have.class', 'active')
45
+ .and('have.attr', 'href')
46
+ .and('include', 'cypress.io')
47
+ })
48
+ })
49
+
50
+ describe('Explicit Assertions', () => {
51
+ // https://on.cypress.io/assertions
52
+ it('expect - make an assertion about a specified subject', () => {
53
+ // We can use Chai's BDD style assertions
54
+ expect(true).to.be.true
55
+ const o = { foo: 'bar' }
56
+
57
+ expect(o).to.equal(o)
58
+ expect(o).to.deep.equal({ foo: 'bar' })
59
+ // matching text using regular expression
60
+ expect('FooBar').to.match(/bar$/i)
61
+ })
62
+
63
+ it('pass your own callback function to should()', () => {
64
+ // Pass a function to should that can have any number
65
+ // of explicit assertions within it.
66
+ // The ".should(cb)" function will be retried
67
+ // automatically until it passes all your explicit assertions or times out.
68
+ cy.get('.assertions-p')
69
+ .find('p')
70
+ .should(($p) => {
71
+ // https://on.cypress.io/$
72
+ // return an array of texts from all of the p's
73
+ const texts = $p.map((i, el) => Cypress.$(el).text())
74
+
75
+ // jquery map returns jquery object
76
+ // and .get() convert this to simple array
77
+ const paragraphs = texts.get()
78
+
79
+ // array should have length of 3
80
+ expect(paragraphs, 'has 3 paragraphs').to.have.length(3)
81
+
82
+ // use second argument to expect(...) to provide clear
83
+ // message with each assertion
84
+ expect(paragraphs, 'has expected text in each paragraph').to.deep.eq([
85
+ 'Some text from first p',
86
+ 'More text from second p',
87
+ 'And even more text from third p',
88
+ ])
89
+ })
90
+ })
91
+
92
+ it('finds element by class name regex', () => {
93
+ cy.get('.docs-header')
94
+ .find('div')
95
+ // .should(cb) callback function will be retried
96
+ .should(($div) => {
97
+ expect($div).to.have.length(1)
98
+
99
+ const className = $div[0].className
100
+
101
+ expect(className).to.match(/heading-/)
102
+ })
103
+ // .then(cb) callback is not retried,
104
+ // it either passes or fails
105
+ .then(($div) => {
106
+ expect($div, 'text content').to.have.text('Introduction')
107
+ })
108
+ })
109
+
110
+ it('can throw any error', () => {
111
+ cy.get('.docs-header')
112
+ .find('div')
113
+ .should(($div) => {
114
+ if ($div.length !== 1) {
115
+ // you can throw your own errors
116
+ throw new Error('Did not find 1 element')
117
+ }
118
+
119
+ const className = $div[0].className
120
+
121
+ if (!className.match(/heading-/)) {
122
+ throw new Error(`Could not find class "heading-" in ${className}`)
123
+ }
124
+ })
125
+ })
126
+
127
+ it('matches unknown text between two elements', () => {
128
+ /**
129
+ * Text from the first element.
130
+ * @type {string}
131
+ */
132
+ let text
133
+
134
+ /**
135
+ * Normalizes passed text,
136
+ * useful before comparing text with spaces and different capitalization.
137
+ * @param {string} s Text to normalize
138
+ */
139
+ const normalizeText = (s) => s.replace(/\s/g, '').toLowerCase()
140
+
141
+ cy.get('.two-elements')
142
+ .find('.first')
143
+ .then(($first) => {
144
+ // save text from the first element
145
+ text = normalizeText($first.text())
146
+ })
147
+
148
+ cy.get('.two-elements')
149
+ .find('.second')
150
+ .should(($div) => {
151
+ // we can massage text before comparing
152
+ const secondText = normalizeText($div.text())
153
+
154
+ expect(secondText, 'second text').to.equal(text)
155
+ })
156
+ })
157
+
158
+ it('assert - assert shape of an object', () => {
159
+ const person = {
160
+ name: 'Joe',
161
+ age: 20,
162
+ }
163
+
164
+ assert.isObject(person, 'value is object')
165
+ })
166
+
167
+ it('retries the should callback until assertions pass', () => {
168
+ cy.get('#random-number')
169
+ .should(($div) => {
170
+ const n = parseFloat($div.text())
171
+
172
+ expect(n).to.be.gte(1).and.be.lte(10)
173
+ })
174
+ })
175
+ })
176
+ })
@@ -0,0 +1,98 @@
1
+ /// <reference types="cypress" />
2
+
3
+ context('Connectors', () => {
4
+ beforeEach(() => {
5
+ cy.visit('https://example.cypress.io/commands/connectors')
6
+ })
7
+
8
+ it('.each() - iterate over an array of elements', () => {
9
+ // https://on.cypress.io/each
10
+ cy.get('.connectors-each-ul>li')
11
+ .each(($el, index, $list) => {
12
+ console.log($el, index, $list)
13
+ })
14
+ })
15
+
16
+ it('.its() - get properties on the current subject', () => {
17
+ // https://on.cypress.io/its
18
+ cy.get('.connectors-its-ul>li')
19
+ // calls the 'length' property yielding that value
20
+ .its('length')
21
+ .should('be.gt', 2)
22
+ })
23
+
24
+ it('.invoke() - invoke a function on the current subject', () => {
25
+ // our div is hidden in our script.js
26
+ // $('.connectors-div').hide()
27
+ cy.get('.connectors-div').should('be.hidden')
28
+
29
+ // https://on.cypress.io/invoke
30
+ // call the jquery method 'show' on the 'div.container'
31
+ cy.get('.connectors-div').invoke('show')
32
+
33
+ cy.get('.connectors-div').should('be.visible')
34
+ })
35
+
36
+ it('.spread() - spread an array as individual args to callback function', () => {
37
+ // https://on.cypress.io/spread
38
+ const arr = ['foo', 'bar', 'baz']
39
+
40
+ cy.wrap(arr).spread((foo, bar, baz) => {
41
+ expect(foo).to.eq('foo')
42
+ expect(bar).to.eq('bar')
43
+ expect(baz).to.eq('baz')
44
+ })
45
+ })
46
+
47
+ describe('.then()', () => {
48
+ it('invokes a callback function with the current subject', () => {
49
+ // https://on.cypress.io/then
50
+ cy.get('.connectors-list > li')
51
+ .then(($lis) => {
52
+ expect($lis, '3 items').to.have.length(3)
53
+ expect($lis.eq(0), 'first item').to.contain('Walk the dog')
54
+ expect($lis.eq(1), 'second item').to.contain('Feed the cat')
55
+ expect($lis.eq(2), 'third item').to.contain('Write JavaScript')
56
+ })
57
+ })
58
+
59
+ it('yields the returned value to the next command', () => {
60
+ cy.wrap(1)
61
+ .then((num) => {
62
+ expect(num).to.equal(1)
63
+
64
+ return 2
65
+ })
66
+ .then((num) => {
67
+ expect(num).to.equal(2)
68
+ })
69
+ })
70
+
71
+ it('yields the original subject without return', () => {
72
+ cy.wrap(1)
73
+ .then((num) => {
74
+ expect(num).to.equal(1)
75
+ // note that nothing is returned from this callback
76
+ })
77
+ .then((num) => {
78
+ // this callback receives the original unchanged value 1
79
+ expect(num).to.equal(1)
80
+ })
81
+ })
82
+
83
+ it('yields the value yielded by the last Cypress command inside', () => {
84
+ cy.wrap(1)
85
+ .then((num) => {
86
+ expect(num).to.equal(1)
87
+ // note how we run a Cypress command
88
+ // the result yielded by this Cypress command
89
+ // will be passed to the second ".then"
90
+ cy.wrap(2)
91
+ })
92
+ .then((num) => {
93
+ // this callback receives the value yielded by "cy.wrap(2)"
94
+ expect(num).to.equal(2)
95
+ })
96
+ })
97
+ })
98
+ })
@@ -0,0 +1,118 @@
1
+ /// <reference types="cypress" />
2
+
3
+ context('Cookies', () => {
4
+ beforeEach(() => {
5
+ Cypress.Cookies.debug(true)
6
+
7
+ cy.visit('https://example.cypress.io/commands/cookies')
8
+
9
+ // clear cookies again after visiting to remove
10
+ // any 3rd party cookies picked up such as cloudflare
11
+ cy.clearCookies()
12
+ })
13
+
14
+ it('cy.getCookie() - get a browser cookie', () => {
15
+ // https://on.cypress.io/getcookie
16
+ cy.get('#getCookie .set-a-cookie').click()
17
+
18
+ // cy.getCookie() yields a cookie object
19
+ cy.getCookie('token').should('have.property', 'value', '123ABC')
20
+ })
21
+
22
+ it('cy.getCookies() - get browser cookies for the current domain', () => {
23
+ // https://on.cypress.io/getcookies
24
+ cy.getCookies().should('be.empty')
25
+
26
+ cy.get('#getCookies .set-a-cookie').click()
27
+
28
+ // cy.getCookies() yields an array of cookies
29
+ cy.getCookies().should('have.length', 1).should((cookies) => {
30
+ // each cookie has these properties
31
+ expect(cookies[0]).to.have.property('name', 'token')
32
+ expect(cookies[0]).to.have.property('value', '123ABC')
33
+ expect(cookies[0]).to.have.property('httpOnly', false)
34
+ expect(cookies[0]).to.have.property('secure', false)
35
+ expect(cookies[0]).to.have.property('domain')
36
+ expect(cookies[0]).to.have.property('path')
37
+ })
38
+ })
39
+
40
+ it('cy.getAllCookies() - get all browser cookies', () => {
41
+ // https://on.cypress.io/getallcookies
42
+ cy.getAllCookies().should('be.empty')
43
+
44
+ cy.setCookie('key', 'value')
45
+ cy.setCookie('key', 'value', { domain: '.example.com' })
46
+
47
+ // cy.getAllCookies() yields an array of cookies
48
+ cy.getAllCookies().should('have.length', 2).should((cookies) => {
49
+ // each cookie has these properties
50
+ expect(cookies[0]).to.have.property('name', 'key')
51
+ expect(cookies[0]).to.have.property('value', 'value')
52
+ expect(cookies[0]).to.have.property('httpOnly', false)
53
+ expect(cookies[0]).to.have.property('secure', false)
54
+ expect(cookies[0]).to.have.property('domain')
55
+ expect(cookies[0]).to.have.property('path')
56
+
57
+ expect(cookies[1]).to.have.property('name', 'key')
58
+ expect(cookies[1]).to.have.property('value', 'value')
59
+ expect(cookies[1]).to.have.property('httpOnly', false)
60
+ expect(cookies[1]).to.have.property('secure', false)
61
+ expect(cookies[1]).to.have.property('domain', '.example.com')
62
+ expect(cookies[1]).to.have.property('path')
63
+ })
64
+ })
65
+
66
+ it('cy.setCookie() - set a browser cookie', () => {
67
+ // https://on.cypress.io/setcookie
68
+ cy.getCookies().should('be.empty')
69
+
70
+ cy.setCookie('foo', 'bar')
71
+
72
+ // cy.getCookie() yields a cookie object
73
+ cy.getCookie('foo').should('have.property', 'value', 'bar')
74
+ })
75
+
76
+ it('cy.clearCookie() - clear a browser cookie', () => {
77
+ // https://on.cypress.io/clearcookie
78
+ cy.getCookie('token').should('be.null')
79
+
80
+ cy.get('#clearCookie .set-a-cookie').click()
81
+
82
+ cy.getCookie('token').should('have.property', 'value', '123ABC')
83
+
84
+ // cy.clearCookies() yields null
85
+ cy.clearCookie('token').should('be.null')
86
+
87
+ cy.getCookie('token').should('be.null')
88
+ })
89
+
90
+ it('cy.clearCookies() - clear browser cookies for the current domain', () => {
91
+ // https://on.cypress.io/clearcookies
92
+ cy.getCookies().should('be.empty')
93
+
94
+ cy.get('#clearCookies .set-a-cookie').click()
95
+
96
+ cy.getCookies().should('have.length', 1)
97
+
98
+ // cy.clearCookies() yields null
99
+ cy.clearCookies()
100
+
101
+ cy.getCookies().should('be.empty')
102
+ })
103
+
104
+ it('cy.clearAllCookies() - clear all browser cookies', () => {
105
+ // https://on.cypress.io/clearallcookies
106
+ cy.getAllCookies().should('be.empty')
107
+
108
+ cy.setCookie('key', 'value')
109
+ cy.setCookie('key', 'value', { domain: '.example.com' })
110
+
111
+ cy.getAllCookies().should('have.length', 2)
112
+
113
+ // cy.clearAllCookies() yields null
114
+ cy.clearAllCookies()
115
+
116
+ cy.getAllCookies().should('be.empty')
117
+ })
118
+ })
@@ -0,0 +1,185 @@
1
+ /// <reference types="cypress" />
2
+
3
+ context('Cypress APIs', () => {
4
+
5
+ context('Cypress.Commands', () => {
6
+ beforeEach(() => {
7
+ cy.visit('https://example.cypress.io/cypress-api')
8
+ })
9
+
10
+ // https://on.cypress.io/custom-commands
11
+
12
+ it('.add() - create a custom command', () => {
13
+ Cypress.Commands.add('console', {
14
+ prevSubject: true,
15
+ }, (subject, method) => {
16
+ // the previous subject is automatically received
17
+ // and the commands arguments are shifted
18
+
19
+ // allow us to change the console method used
20
+ method = method || 'log'
21
+
22
+ // log the subject to the console
23
+ console[method]('The subject is', subject)
24
+
25
+ // whatever we return becomes the new subject
26
+ // we don't want to change the subject so
27
+ // we return whatever was passed in
28
+ return subject
29
+ })
30
+
31
+ cy.get('button').console('info').then(($button) => {
32
+ // subject is still $button
33
+ })
34
+ })
35
+ })
36
+
37
+ context('Cypress.Cookies', () => {
38
+ beforeEach(() => {
39
+ cy.visit('https://example.cypress.io/cypress-api')
40
+ })
41
+
42
+ // https://on.cypress.io/cookies
43
+ it('.debug() - enable or disable debugging', () => {
44
+ Cypress.Cookies.debug(true)
45
+
46
+ // Cypress will now log in the console when
47
+ // cookies are set or cleared
48
+ cy.setCookie('fakeCookie', '123ABC')
49
+ cy.clearCookie('fakeCookie')
50
+ cy.setCookie('fakeCookie', '123ABC')
51
+ cy.clearCookie('fakeCookie')
52
+ cy.setCookie('fakeCookie', '123ABC')
53
+ })
54
+ })
55
+
56
+ context('Cypress.arch', () => {
57
+ beforeEach(() => {
58
+ cy.visit('https://example.cypress.io/cypress-api')
59
+ })
60
+
61
+ it('Get CPU architecture name of underlying OS', () => {
62
+ // https://on.cypress.io/arch
63
+ expect(Cypress.arch).to.exist
64
+ })
65
+ })
66
+
67
+ context('Cypress.config()', () => {
68
+ beforeEach(() => {
69
+ cy.visit('https://example.cypress.io/cypress-api')
70
+ })
71
+
72
+ it('Get and set configuration options', () => {
73
+ // https://on.cypress.io/config
74
+ let myConfig = Cypress.config()
75
+
76
+ expect(myConfig).to.have.property('animationDistanceThreshold', 5)
77
+ expect(myConfig).to.have.property('baseUrl', null)
78
+ expect(myConfig).to.have.property('defaultCommandTimeout', 4000)
79
+ expect(myConfig).to.have.property('requestTimeout', 5000)
80
+ expect(myConfig).to.have.property('responseTimeout', 30000)
81
+ expect(myConfig).to.have.property('viewportHeight', 660)
82
+ expect(myConfig).to.have.property('viewportWidth', 1000)
83
+ expect(myConfig).to.have.property('pageLoadTimeout', 60000)
84
+ expect(myConfig).to.have.property('waitForAnimations', true)
85
+
86
+ expect(Cypress.config('pageLoadTimeout')).to.eq(60000)
87
+
88
+ // this will change the config for the rest of your tests!
89
+ Cypress.config('pageLoadTimeout', 20000)
90
+
91
+ expect(Cypress.config('pageLoadTimeout')).to.eq(20000)
92
+
93
+ Cypress.config('pageLoadTimeout', 60000)
94
+ })
95
+ })
96
+
97
+ context('Cypress.dom', () => {
98
+ beforeEach(() => {
99
+ cy.visit('https://example.cypress.io/cypress-api')
100
+ })
101
+
102
+ // https://on.cypress.io/dom
103
+ it('.isHidden() - determine if a DOM element is hidden', () => {
104
+ let hiddenP = Cypress.$('.dom-p p.hidden').get(0)
105
+ let visibleP = Cypress.$('.dom-p p.visible').get(0)
106
+
107
+ // our first paragraph has css class 'hidden'
108
+ expect(Cypress.dom.isHidden(hiddenP)).to.be.true
109
+ expect(Cypress.dom.isHidden(visibleP)).to.be.false
110
+ })
111
+ })
112
+
113
+ context('Cypress.env()', () => {
114
+ beforeEach(() => {
115
+ cy.visit('https://example.cypress.io/cypress-api')
116
+ })
117
+
118
+ // We can set environment variables for highly dynamic values
119
+
120
+ // https://on.cypress.io/environment-variables
121
+ it('Get environment variables', () => {
122
+ // https://on.cypress.io/env
123
+ // set multiple environment variables
124
+ Cypress.env({
125
+ host: 'veronica.dev.local',
126
+ api_server: 'http://localhost:8888/v1/',
127
+ })
128
+
129
+ // get environment variable
130
+ expect(Cypress.env('host')).to.eq('veronica.dev.local')
131
+
132
+ // set environment variable
133
+ Cypress.env('api_server', 'http://localhost:8888/v2/')
134
+ expect(Cypress.env('api_server')).to.eq('http://localhost:8888/v2/')
135
+
136
+ // get all environment variable
137
+ expect(Cypress.env()).to.have.property('host', 'veronica.dev.local')
138
+ expect(Cypress.env()).to.have.property('api_server', 'http://localhost:8888/v2/')
139
+ })
140
+ })
141
+
142
+ context('Cypress.log', () => {
143
+ beforeEach(() => {
144
+ cy.visit('https://example.cypress.io/cypress-api')
145
+ })
146
+
147
+ it('Control what is printed to the Command Log', () => {
148
+ // https://on.cypress.io/cypress-log
149
+ })
150
+ })
151
+
152
+ context('Cypress.platform', () => {
153
+ beforeEach(() => {
154
+ cy.visit('https://example.cypress.io/cypress-api')
155
+ })
156
+
157
+ it('Get underlying OS name', () => {
158
+ // https://on.cypress.io/platform
159
+ expect(Cypress.platform).to.be.exist
160
+ })
161
+ })
162
+
163
+ context('Cypress.version', () => {
164
+ beforeEach(() => {
165
+ cy.visit('https://example.cypress.io/cypress-api')
166
+ })
167
+
168
+ it('Get current version of Cypress being run', () => {
169
+ // https://on.cypress.io/version
170
+ expect(Cypress.version).to.be.exist
171
+ })
172
+ })
173
+
174
+ context('Cypress.spec', () => {
175
+ beforeEach(() => {
176
+ cy.visit('https://example.cypress.io/cypress-api')
177
+ })
178
+
179
+ it('Get current spec information', () => {
180
+ // https://on.cypress.io/spec
181
+ // wrap the object so we can inspect it easily by clicking in the command log
182
+ cy.wrap(Cypress.spec).should('include.keys', ['name', 'relative', 'absolute'])
183
+ })
184
+ })
185
+ })
@@ -0,0 +1,85 @@
1
+ /// <reference types="cypress" />
2
+
3
+ /// JSON fixture file can be loaded directly using
4
+ // the built-in JavaScript bundler
5
+ const requiredExample = require('../../fixtures/example')
6
+
7
+ context('Files', () => {
8
+ beforeEach(() => {
9
+ cy.visit('https://example.cypress.io/commands/files')
10
+
11
+ // load example.json fixture file and store
12
+ // in the test context object
13
+ cy.fixture('example.json').as('example')
14
+ })
15
+
16
+ it('cy.fixture() - load a fixture', () => {
17
+ // https://on.cypress.io/fixture
18
+
19
+ // Instead of writing a response inline you can
20
+ // use a fixture file's content.
21
+
22
+ // when application makes an Ajax request matching "GET **/comments/*"
23
+ // Cypress will intercept it and reply with the object in `example.json` fixture
24
+ cy.intercept('GET', '**/comments/*', { fixture: 'example.json' }).as('getComment')
25
+
26
+ // we have code that gets a comment when
27
+ // the button is clicked in scripts.js
28
+ cy.get('.fixture-btn').click()
29
+
30
+ cy.wait('@getComment').its('response.body')
31
+ .should('have.property', 'name')
32
+ .and('include', 'Using fixtures to represent data')
33
+ })
34
+
35
+ it('cy.fixture() or require - load a fixture', function () {
36
+ // we are inside the "function () { ... }"
37
+ // callback and can use test context object "this"
38
+ // "this.example" was loaded in "beforeEach" function callback
39
+ expect(this.example, 'fixture in the test context')
40
+ .to.deep.equal(requiredExample)
41
+
42
+ // or use "cy.wrap" and "should('deep.equal', ...)" assertion
43
+ cy.wrap(this.example)
44
+ .should('deep.equal', requiredExample)
45
+ })
46
+
47
+ it('cy.readFile() - read file contents', () => {
48
+ // https://on.cypress.io/readfile
49
+
50
+ // You can read a file and yield its contents
51
+ // The filePath is relative to your project's root.
52
+ cy.readFile(Cypress.config('configFile')).then((config) => {
53
+ expect(config).to.be.an('string')
54
+ })
55
+ })
56
+
57
+ it('cy.writeFile() - write to a file', () => {
58
+ // https://on.cypress.io/writefile
59
+
60
+ // You can write to a file
61
+
62
+ // Use a response from a request to automatically
63
+ // generate a fixture file for use later
64
+ cy.request('https://jsonplaceholder.cypress.io/users')
65
+ .then((response) => {
66
+ cy.writeFile('cypress/fixtures/users.json', response.body)
67
+ })
68
+
69
+ cy.fixture('users').should((users) => {
70
+ expect(users[0].name).to.exist
71
+ })
72
+
73
+ // JavaScript arrays and objects are stringified
74
+ // and formatted into text.
75
+ cy.writeFile('cypress/fixtures/profile.json', {
76
+ id: 8739,
77
+ name: 'Jane',
78
+ email: 'jane@example.com',
79
+ })
80
+
81
+ cy.fixture('profile').should((profile) => {
82
+ expect(profile.name).to.eq('Jane')
83
+ })
84
+ })
85
+ })
@@ -0,0 +1,32 @@
1
+ /// <reference types="cypress" />
2
+
3
+ context('Location', () => {
4
+ beforeEach(() => {
5
+ cy.visit('https://example.cypress.io/commands/location')
6
+ })
7
+
8
+ it('cy.hash() - get the current URL hash', () => {
9
+ // https://on.cypress.io/hash
10
+ cy.hash().should('be.empty')
11
+ })
12
+
13
+ it('cy.location() - get window.location', () => {
14
+ // https://on.cypress.io/location
15
+ cy.location().should((location) => {
16
+ expect(location.hash).to.be.empty
17
+ expect(location.href).to.eq('https://example.cypress.io/commands/location')
18
+ expect(location.host).to.eq('example.cypress.io')
19
+ expect(location.hostname).to.eq('example.cypress.io')
20
+ expect(location.origin).to.eq('https://example.cypress.io')
21
+ expect(location.pathname).to.eq('/commands/location')
22
+ expect(location.port).to.eq('')
23
+ expect(location.protocol).to.eq('https:')
24
+ expect(location.search).to.be.empty
25
+ })
26
+ })
27
+
28
+ it('cy.url() - get the current URL', () => {
29
+ // https://on.cypress.io/url
30
+ cy.url().should('eq', 'https://example.cypress.io/commands/location')
31
+ })
32
+ })