Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/testing/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Testing Cypress中的.click()命令未执行其功能_Testing_Cypress - Fatal编程技术网

Testing Cypress中的.click()命令未执行其功能

Testing Cypress中的.click()命令未执行其功能,testing,cypress,Testing,Cypress,这是我第一次使用Cyrpress,我正在尝试为我的React应用程序运行一个测试。测试是在模式中输入名称后,单击submit按钮,您将进入主页。但是,.click函数不起作用,至少我认为它不起作用,因为modal仍然存在,上面还有名称。有人能告诉我我做错了什么以及如何修复它吗 以下是我编写测试的方式: **fourth.spec.js** describe ('UI tests', () => { it('should navgitate to

这是我第一次使用Cyrpress,我正在尝试为我的React应用程序运行一个测试。测试是在模式中输入名称后,单击submit按钮,您将进入主页。但是,.click函数不起作用,至少我认为它不起作用,因为modal仍然存在,上面还有名称。有人能告诉我我做错了什么以及如何修复它吗

以下是我编写测试的方式:

   **fourth.spec.js**
        describe ('UI tests', () => {
            it('should navgitate to landing page after submitting with button', () =>{
                const text = "Christian"
                cy.visit('/')
                cy.get('.new').type (text).should ('have.value', text)
                .click()
            })
        })
这是我如何为我的模式设置按钮

 <div className="my-modal">
         <h1>Welcome!</h1>
            <p>Please enter your name</p>
               <form>  
                 <input 
                     autoFocus
                     className="new task"
                     placeholder="Name"
                     type="text" 
                     name="firstName" 
                     onChange={this.inputChange}>
                 </input>
               </form>
               <button  
                  className="modal-btn"
                  type="button" 
                   disabled={!this.state.firstName} 
                   onClick={this.displayNameHandler}>
                   Submit
               </button>
    </div>

看起来您正在单击输入字段而不是按钮。尝试:

cy.get('.modal-btn').click()

看起来您正在单击输入字段而不是按钮。尝试:

cy.get('.modal-btn').click()

您还可以尝试根据按钮文本单击Submit按钮


您还可以尝试根据按钮文本单击Submit按钮