在尝试安装时npm install,出现以下错误,如何解决?
$
npm install
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: sssclub@0.1.0
npm ERR! Found: react@18.1.0
npm ERR! node_modules/react
npm ERR! react@"^18.0.0" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer react@"^16.8.0 || ^17.0.0" from @material-ui/core@4.12.4
npm ERR! node_modules/@material-ui/core
npm ERR! @material-ui/core@"^4.12.4" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this …Run Code Online (Sandbox Code Playgroud) 在加载.env文件以将 env 值传递给getToken.jscypress 根文件夹中的脚本时,会抛出无法找到模块 'dotenv' 错误。我已经安装了npm install dotenv. 有人可以告诉我在这里缺少什么吗?.env文件位于 cypress 根文件夹中。
环境:Windows 10 > git bash /命令提示符
const puppeteer = require("puppeteer");
require('dotenv').config({path: '.env'})
const baseURL = process.env.CYPRESS_BASE_URL
const testsUser = process.env.CYPRESS_TESTS_USERNAME
puppeteer
.launch({ headless: true, chromeWebSecurity: false, args: ['--no-sandbox'] })
.then(async browser => {
const page = await browser.newPage();
await page.goto(`${baseURL}/login`);
await page.waitFor(2000);
await page.waitForSelector("input[name=username]");
await page.type("input[name=username]", testsUser , {
delay: 50
});
browser.close();
});
Run Code Online (Sandbox Code Playgroud)
包.json
"scripts": {
"cy:run": "cypress run",
"get-token-main": …Run Code Online (Sandbox Code Playgroud) 如何在Cypress中将文本输入字段的值获取为'const'变量,以便我可以使用cy.log()记录该变量。以下代码不记录任何内容,熟悉Cypress.io的人可以建议
cy.get('input[name="email"]').then(($text)=>{
const txt = $text.text()
cy.log(txt)
})
Run Code Online (Sandbox Code Playgroud) 我们如何options从普通的下拉列表框中选择所有内容并使用 Cypress 验证它们。
<select id="cars_list">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="mercedes">Mercedes</option>
<option value="audi">Audi</option>
</select>
Run Code Online (Sandbox Code Playgroud)
//下面的测试只能检查一个选项,我们如何验证rest?
describe("Select all values from drop down list", function() {
it("Cypress test and verify all options", function() {
cy.visit("Https://sometestingsite.com")
cy.get('#cars_list').then(function($select){
$select.val('volvo')
})
cy.get('select').should('have.value', 'volvo')
});
});
Run Code Online (Sandbox Code Playgroud) Cypress.io 中的 cy.readFile 和 cy.fixture 有什么区别?我们应该在什么情况下使用 cy.readFile 和 cy.fixture ?
cy.readFile('menu.json')
cy.fixture('users/admin.json') // Get data from {fixturesFolder}/users/admin.json
Run Code Online (Sandbox Code Playgroud) 我们如何使用 Cypress.io 测试标记/标记在 Google 地图上的显示?我不知道使用什么方法来查找 Google 地图上显示的标记。
describe('Display of marker on Google map', function(){
it.only('Check the display of marker on Google map', function(){
cy.visit('https://www.google.co.nz/maps/@-36.9139788,174.8740846,15z?hl=en')
cy.get('#searchboxinput').type('gold coast')
//don't know how to select Gold Coast from the populated search items
//How to find a marker displayed on Google Map ?
})
})
Run Code Online (Sandbox Code Playgroud) 我正在使用 cypresscy.task()方法/函数将文件从一个目录复制csv到另一个目录。以下是我cy.task('copycsvFile')在文件中编写的相关代码support/index.js。运行时会抛出以下错误;CypressError:cy.task('copycsvFile')失败并出现以下错误:
The 'task' event has not been registered in the plugins file. You must register it before using cy.task()知道为什么无法识别吗?
节点版本:v10.15.3,赛普拉斯版本:3.1.5
//sample-spec.js 文件
cy.task('copycsvFile');
Run Code Online (Sandbox Code Playgroud)
下面是我的index.js文件 // support/index.js 文件
const fs = require('fs');
module.exports = (on) => {
on('task', {
copycsvFile: (Obj)=>{
var fs = require('fs');
fs.createReadStream('C:/Users/SomeName/Downloads/Export_Survey_CSV.csv').pipe(fs.createWriteStream('C:/User/Client/Client - Cypress Web UI Tests/cypress/fixtures/Export_Survey_CSV.csv'));
}
});
};
Run Code Online (Sandbox Code Playgroud) 如何在 cypress 中获取“剪贴板”内容。我的 Web 应用程序中有一个按钮,单击按钮系统将执行“复制到剪贴板”并显示一条消息。以下是复制到剪贴板的 url 内容示例(此 url 内容与网站 url 不同)
我仔细检查href了该按钮标签中没有属性。所以我使用了一个名为 clipboardy 的插件,并添加了plugins/index.js文件
const clipboardy = require('clipboardy');
module.exports = ( on ) => {
on('task', {
getClipboard () {
return clipboardy.readSync();
}
});
};
Run Code Online (Sandbox Code Playgroud)
在我的测试中,我使用 cy.task() 来获取剪贴板内容,但这并没有打印实际的 url 内容
cy.get('td').find('div').find('span').find('button').find('i').eq(0).click().then(()=>{
cy.task('getClipboard').then((data)=>{
console.log("Helloooo:"+data);
})
})
Run Code Online (Sandbox Code Playgroud)
const clipboardy = require('clipboardy');
module.exports = ( on ) => {
on('task', {
getClipboard () {
return clipboardy.readSync();
}
});
};
Run Code Online (Sandbox Code Playgroud)
我已经在“ Cypress.env.json”文件中设置了环境变量,在运行cypress测试时,它成功读取了Cypress.env变量。但是,为了更加注重安全性,而不是“硬编码”值,我的团队要求我将此变量保留为单独的“参数”,该参数从Windows 10环境变量中读取。我该如何实现?如果有人可以对此提供建议,那将真的很有帮助。
{
"QA_Server": "https://sometestingsite.com",
"username": "testQA",
"password": "Password1234!"
}
Run Code Online (Sandbox Code Playgroud) 有什么方法test results可以将 Cypress 导出为 HTML 或任何其他格式(如 cucumber-report.html)