cypress

cypress: How can manage the application flow, if the element xpath is not present

回眸只為那壹抹淺笑 提交于 2021-01-28 01:11:14
问题 I have the following scenario: if the element is present, i have to do one activity and if not present will do another activity. cy.xpath("//div[text()= 'button').its('length').then(res=> { if (res > 0) { return 1; } else { cy.log ("Element is not present") } } )} ''' if element is present = Code is working fine, if the element xpath is not present = it try to search the element xpath (//div[text()= 'button') and throwing the error as 'Timed out retrying: Expected to find element: undefined,

Cypress capture all requests cy.Route()

不羁的心 提交于 2021-01-27 19:30:56
问题 I want to capture all requests, however cy.Route() does not seem to accept wildcards. So, for example, I want to navigate to Reddit" and capture all the requests, however, I also want the code to be reusable so I can navigate to stack overflow and also capture all requests. Is this possible? I have tried * wildcard but it does not work cy.route('*').as('GETS'); cy.route(GET, '*').as('GETS'); 回答1: Cypress automatically includes minimatch and exposes it as Cypress.minimatch. According to

Cypress 5.0 - Unable to find installed browsers

不问归期 提交于 2021-01-27 13:03:05
问题 I have Cypress 5.0 installed and have all the browsers - Chrome, Edge and FF. When I run > npx cypress open Not able to see all the browsers on the top right corner. Only Electron is showing I tried > npx cypress open --browser chrome I get the following error Can't run because you've entered an invalid browser name. Browser: 'chrome' was not found on your system or is not supported by Cypress. Cypress supports the following browsers: - chrome - chromium - edge - electron - firefox (Cypress

Cypress 5.0 - Unable to find installed browsers

不想你离开。 提交于 2021-01-27 13:00:35
问题 I have Cypress 5.0 installed and have all the browsers - Chrome, Edge and FF. When I run > npx cypress open Not able to see all the browsers on the top right corner. Only Electron is showing I tried > npx cypress open --browser chrome I get the following error Can't run because you've entered an invalid browser name. Browser: 'chrome' was not found on your system or is not supported by Cypress. Cypress supports the following browsers: - chrome - chromium - edge - electron - firefox (Cypress

Cypress - install it on empty project

[亡魂溺海] 提交于 2021-01-27 06:31:37
问题 I am trying to install cypress on an empty project. However, cypress is not installed in the package.js file and cypress is not included on the project. How can I make it work? I cannot install cypress as part of the development project, so i am trying to create a separate test automation project with cypress. 回答1: You need to add --save or --save-dev to save it to package.json file. eg: npm install cypress --save . https://docs.npmjs.com/cli/v6/commands/npm-install 回答2: Steps to install

Different Cypress baseUrl for cy.visit() and cy.request()

给你一囗甜甜゛ 提交于 2021-01-27 05:57:25
问题 Our application under test locally has a frontend and backend that run on localhost:4200 and 127.0.0.1:8000 , respectively. When calling cy.visit('/somepage') we would like this to have a different baseUrl than for cy.request('/someapi') as cy.visit() will visit a page hosted on the frontend, while cy.request() will make a request to an API endpoint on the backend. We can use the default baseUrl config from cypress.json for cy.visit() , but is there a way to have cy.request() default to a

Cannot get code coverage with Cypress + Istanbul

廉价感情. 提交于 2021-01-22 08:04:42
问题 I tried setting up code coverage in an Angular 8 project using Cypress and istanbul nyc . I managed to get the code instrumented (the global variable __coverage__ is properly set) : and the coverage file generated in .nyc_output after running cypress:open But the generated coverage report is empty: $ cat coverage/coverage-final.json {} Same result when I execute the command: $ npx nyc report --report-dir ./coverage --temp-dir .nyc_output --reporter=text ----------|----------|----------|------

Cannot get code coverage with Cypress + Istanbul

假装没事ソ 提交于 2021-01-22 08:02:39
问题 I tried setting up code coverage in an Angular 8 project using Cypress and istanbul nyc . I managed to get the code instrumented (the global variable __coverage__ is properly set) : and the coverage file generated in .nyc_output after running cypress:open But the generated coverage report is empty: $ cat coverage/coverage-final.json {} Same result when I execute the command: $ npx nyc report --report-dir ./coverage --temp-dir .nyc_output --reporter=text ----------|----------|----------|------

[Cypress] Test Variations of a Feature in Cypress with a data-driven Test

帅比萌擦擦* 提交于 2021-01-11 08:14:59
Many applications have features that can be used with slight variations. Instead of maintaining multiple tests with nearly identical code, we can take advantage of the JavaScript runtime and use normal data structures and plain old JavaScript to test and make assertions for multiple interactions in a single test. we have a new fixture: // cypress/fixtures/mixed_todos.json [ { "id": 1, "name": "One", "isComplete": false }, { "id": 2, "name": "Two", "isComplete": true }, { "id": 3, "name": "Three", "isComplete": true }, { "id": 4, "name": "Four", "isComplete": false } ] In the app, when we click

[Cypress] Interact with Hidden Elements in a Cypress Test

别说谁变了你拦得住时间么 提交于 2021-01-11 07:56:02
We often only show UI elements as a result of some user interaction. Cypress detects visibility and by default won’t allow your test to interact with an element that isn’t visible. In this lesson, we’ll work with a button that is shown on hover and see how you can either bypass the visibility restriction or use Cypress to update the state of your application, making items visible prior to interacting with them. For example the delete icon was hidden by default, only show up when you hover over it, to test those hidden element. we need to call: .invoke('show') it('should Delete an item',