我有以下用于使用 Cypress 的目录结构:
cypress-automation
cypress
fixtures
integration
apps
pulse
smhw-prod
smhw-qa
folder-a
sample-spec.js
examples
plugins
screenshots
support
videos
node_modules
cypress.json // this is where the file currently is
package-lock.json
package.json
Run Code Online (Sandbox Code Playgroud)
期待
我想要做的是运行smhw-qa文件夹内的所有测试(那里有许多规范文件)..并且能够--project使用 CLI使用命令传递它。
目前,如果我只运行 `--run` 没有任何其他参数所有的规范文件,从所有文件夹将开始运行这是不可取的,因为有多个应用程序“项目”(smhw-qa,smhw-prod 等)在这个结构内。这将允许我仅根据需要从单个文件夹运行规范文件。
我也知道使用--run命令来“运行”特定文件夹,但我想使用“项目”来组织这些测试,以便以后更容易识别它们。
我已经查看了显示--project命令使用的文档,但是我需要帮助了解我还需要设置什么才能完成这项工作。通过这个,我指的是package.json文件。
到目前为止,
我尝试遵循为测试“嵌套文件夹”提供的示例:https :
//github.com/cypress-io/cypress-test-nested-projects
package.json:添加了以下脚本:
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"smhw-qa": "cypress run --project ./cypress/integration/apps/smhw-qa"
},
Run Code Online (Sandbox Code Playgroud)
当我像这样通过终端运行它时:
? cypress-automation npx cypress run --project …Run Code Online (Sandbox Code Playgroud) 我是 Cypress 的新手,有一个小问题,我需要一些帮助。
我的应用程序中有一个输入字段,允许我输入名称。此名称必须是唯一的,并且不得与系统中已有的名称相同。
我目前正在通过以下方式单击此输入字段:
cy.get('input[type="text"].form-control')
如果我使用该cy.type()命令,这将始终输入所提供的相同值,但每次测试运行时,我都想分配一个不同的值。
// Fill in some details of a new class to proceed with creation
cy.get('.pull-left > h4').contains('Add a new class')
cy.get('input[type="text"].form-control') // Clicks on the field
// Some code to go here to create a random string and use what was created and
type this into the field above
Run Code Online (Sandbox Code Playgroud)
预期
创建一个函数,该函数允许生成一个随机字符串,然后通过普通的 cypress 命令将其输入到输入字段中。
背景
嗨,我是 cypress 的新手,我有以下代码允许指定的用户类型(总共 4 个)登录。
由于这是主要测试之一,因此不必将相同的代码复制并粘贴到我的每个新测试中,我想让它们可重复使用,以便在未来的测试中,可以再次使用或“调用”它们.
将这些测试保存在单独的文件夹和单独的文件中会更容易,这样它们就可以自己维护,但可以在我创建的任何未来测试文件中在必要时调用它们。
例如,如果我有一个与教师相关的未来测试,我可以调用执行教师登录的函数,然后开始编写实际处理测试的脚本的其余部分,而无需每次都搞砸复制和粘贴.
执行登录部分的代码块如下(对于所有其他类型的用户几乎相同)
我一直在尝试研究如何创建方法和函数,但对我应该使用的结构不太确定,并且查看了文档但我有点困惑。
describe('Create Homework', function() {
it('Create New Assignment', function() {
cy.visit('http://www.demoapp.com')
cy.contains('Log in')
// Check that the user has indeed landed on the login page
cy.url().should('include','/login')
// Make a school selection
cy.get('#school-selector-search-box')
.type('Bristol Free School')
// Click the suggestion
.get('.suggestions > .ember-view.suggestion:nth-of-type(1) > .suggested-school-name').click()
// Enter a username at this step
cy.get('#identification')
.type('gdawson_4319c')
.should ('have.value','gdawson_4319c')
// Enter a password at this step
cy.get('#password')
.type('demo')
.should ('have.value','demo')
// Proceed …Run Code Online (Sandbox Code Playgroud) 我有一个测试,我想滚动到页面的末尾以声明某些内容。
如何使用硒和红宝石实现此目的?我可以在此“特殊”测试中添加一些内容,在其中可以滚动到底部吗?
我有以下函数,它在父函数中。
function generate_random_string(string_length) { // A function that creates a random string and will later pass this to a variable
let random_string = '';
let random_ascii;
for(let i = 0; i < string_length; i++) {
random_ascii = Math.floor((Math.random() * 25) + 97);
random_string += String.fromCharCode(random_ascii)
}
return random_string
}
var random_string = generate_random_string(6)
Run Code Online (Sandbox Code Playgroud)
对于不同情况的其他测试文件,此随机字符串生成器有很多用途。无需每次都复制和粘贴此函数,我想重用此函数并在另一个测试文件中调用它。
我应该如何设置?
我试图在commands.js文件中创建一个自定义命令,如下所示:
Cypress.Commands.add("random_string_gen",
function generate_random_string(string_length) {
let random_string = '';
let random_ascii;
for(let i = 0; i < string_length; i++) {
random_ascii = Math.floor((Math.random() …Run Code Online (Sandbox Code Playgroud)