{"id":4048,"date":"2024-11-10T08:34:04","date_gmt":"2024-11-10T00:34:04","guid":{"rendered":"https:\/\/fwq.ai\/blog\/4048\/"},"modified":"2024-11-10T08:34:04","modified_gmt":"2024-11-10T00:34:04","slug":"%e5%a6%82%e4%bd%95%e5%90%8c%e6%97%b6%e8%bf%90%e8%a1%8c-cypress-run-%e5%92%8c-cypress-open","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/4048\/","title":{"rendered":"\u5982\u4f55\u540c\u65f6\u8fd0\u884c cypress run \u548c cypress open"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173121662687496.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u540c\u65f6\u8fd0\u884c cypress run \u548c cypress open\u63d2\u56fe\" alt=\"\u5982\u4f55\u540c\u65f6\u8fd0\u884c cypress run \u548c cypress open\u63d2\u56fe\" \/><br \/> cypress \u662f\u4e00\u4e2a\u4e3a web \u5e94\u7528\u7a0b\u5e8f\u6784\u5efa\u7684\u5f3a\u5927\u7684\u7aef\u5230\u7aef\u6d4b\u8bd5\u6846\u67b6\u3002\u5b83\u65e8\u5728\u4f7f\u6d4b\u8bd5\u53d8\u5f97\u7b80\u5355\u53ef\u9760\uff0c\u4f7f\u5f00\u53d1\u4eba\u5458\u548c qa \u5de5\u7a0b\u5e08\u80fd\u591f\u6d4b\u8bd5\u4ece\u7b80\u5355\u4ea4\u4e92\u5230\u590d\u6742\u7528\u6237\u5de5\u4f5c\u6d41\u7a0b\u7684\u6240\u6709\u5185\u5bb9\u3002\u501f\u52a9 cypress\uff0c\u60a8\u53ef\u4ee5\u521b\u5efa\u6a21\u62df\u7528\u6237\u64cd\u4f5c\u3001\u9a8c\u8bc1\u524d\u7aef\u884c\u4e3a\u5e76\u4ee5\u6700\u5c11\u7684\u8bbe\u7f6e\u786e\u4fdd ui \u529f\u80fd\u7684\u6d4b\u8bd5\u3002<\/p>\n<h2> \u8d5b\u666e\u62c9\u65af\u6709\u4ec0\u4e48\u7528\u9014\uff1f <\/h2>\n<p>cypress \u4e3b\u8981\u7528\u4e8e web \u5e94\u7528\u7a0b\u5e8f\u4e2d\u7684\u7aef\u5230\u7aef\u6d4b\u8bd5\uff0c\u4f46\u5b83\u5bf9\u4e8e\u524d\u7aef\u73af\u5883\u4e2d\u7684\u96c6\u6210\u548c\u5355\u5143\u6d4b\u8bd5\u4e5f\u5f88\u6709\u6548\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u89c1\u7528\u4f8b\uff1a<\/p>\n<ul>\n<li>\n<p><strong>\u81ea\u52a8\u5316\u7528\u6237\u6d41\u7a0b<\/strong>\uff1a\u6d4b\u8bd5\u590d\u6742\u7684\u7528\u6237\u6d41\u7a0b\uff0c\u4f8b\u5982\u8eab\u4efd\u9a8c\u8bc1\u3001\u548c\u7535\u5b50\u5546\u52a1\u4ea4\u6613\u3002<\/p>\n<\/li>\n<li>\n<p><strong>\u6d4b\u8bd5\u54cd\u5e94\u5f0f\u8bbe\u8ba1<\/strong>\uff1acypress \u5141\u8bb8\u8de8\u4e0d\u540c\u89c6\u53e3\u5927\u5c0f\u8fdb\u884c\u6d4b\u8bd5\uff0c\u4f7f\u5176\u6210\u4e3a\u54cd\u5e94\u5f0f\u8bbe\u8ba1\u6d4b\u8bd5\u7684\u7406\u60f3\u9009\u62e9\u3002<\/p>\n<\/li>\n<li>\n<p><strong>\u56de\u5f52\u6d4b\u8bd5<\/strong>\uff1a\u901a\u8fc7\u81ea\u52a8\u5316\u6d4b\u8bd5\u7528\u4f8b\uff0c\u60a8\u53ef\u4ee5\u5feb\u901f\u9a8c\u8bc1\u65b0\u7684\u4ee3\u7801\u66f4\u6539\u662f\u5426\u6ca1\u6709\u5f15\u5165\u9519\u8bef\u3002<\/p>\n<\/li>\n<li>\n<p><strong>ui \u7ec4\u4ef6\u6d4b\u8bd5<\/strong>\uff1acypress \u53ef\u4ee5\u4e0e storybook \u7b49\u5de5\u5177\u4e00\u8d77\u4f7f\u7528\u6765\u5355\u72ec\u9a8c\u8bc1\u524d\u7aef\u7ec4\u4ef6\uff0c\u786e\u4fdd\u5b83\u4eec\u5728\u5404\u79cd\u573a\u666f\u4e2d\u6309\u9884\u671f\u8fd0\u884c\u3002<\/p>\n<\/li>\n<\/ul>\n<p>cypress \u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u4eea\u8868\u677f\u548c cli\uff0c\u53ef\u4ee5\u65e0\u7f1d\u96c6\u6210\u5230 ci\/cd \u7ba1\u9053\u4e2d\uff0c\u4f7f\u5176\u6210\u4e3a\u73b0\u4ee3 web \u5f00\u53d1\u4e2d\u81ea\u52a8\u5316\u3001\u6301\u7eed\u6d4b\u8bd5\u7684\u9996\u9009\u3002<\/p>\n<h2> \u4f7f\u7528 cypress \u8fd0\u884c\u6d4b\u8bd5 <\/h2>\n<p>\u53ef\u4ee5\u901a\u8fc7\u4e24\u79cd\u4e3b\u8981\u65b9\u5f0f\u5728 cypress \u4e2d\u8fd0\u884c\u6d4b\u8bd5\uff1a\u4f7f\u7528\u6d4b\u8bd5\u8fd0\u884c\u5668 (gui) \u548c\u547d\u4ee4\u884c\u754c\u9762 (cli)\u3002<\/p>\n<p>\u8fd9\u662f\u4e24\u79cd\u65b9\u6cd5\u7684\u5feb\u901f\u6307\u5357\uff1a<\/p>\n<h3> \u4f7f\u7528\u6d4b\u8bd5\u8fd0\u884c\u5668 (gui)\uff1a <\/h3>\n<p>\u8981\u4ee5\u4ea4\u4e92\u65b9\u5f0f\u4f7f\u7528 cypress test runner \u4e0e <strong>cypress real world \u5e94\u7528\u7a0b\u5e8f<\/strong>\uff0c\u8bf7\u6309\u7167\u4ee5\u4e0b\u6b65\u9aa4\u64cd\u4f5c\u3002\u8be5\u5e94\u7528\u7a0b\u5e8f\u63d0\u4f9b\u4e86\u8d5b\u666e\u62c9\u65af\u5b9e\u9645\u6d4b\u8bd5\u7684\u53ef\u9760\u793a\u4f8b\uff0c\u4ee5\u53ca\u3001\u767b\u5f55\u548c\u4ea4\u6613\u6d41\u7a0b\u7684\u573a\u666f\u3002<\/p>\n<p>\u6211\u4eec\u4ee5 cypress \u7684\u793a\u4f8b\u5e94\u7528\u7a0b\u5e8f\u201ccypress real world app\u201d\u4e3a\u4f8b\u3002<\/p>\n<p><strong>\u5728\u672c\u5730\u8bbe\u7f6e\u5e76\u8fd0\u884c cypress real world \u5e94\u7528\u7a0b\u5e8f\uff1a<\/strong><\/p>\n<p>\u8fd9\u4e9b\u662f\u8bbe\u7f6e\u793a\u4f8b\u5e94\u7528\u7a0b\u5e8f\u7684\u521d\u59cb\u6b65\u9aa4<\/p>\n<pre>git clone https:\/\/github.com\/cypress-io\/cypress-realworld-app\ncd cypress-realworld-app\nyarn\n\n\/\/run the app\nyarn dev\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u6253\u5f00 cypress \u6d4b\u8bd5\u8fd0\u884c\u5668\uff1a<\/strong><\/p>\n<p>\u73b0\u5728\uff0c\u4ee5\u4ea4\u4e92\u6a21\u5f0f\u6253\u5f00<strong>cypress test runner<\/strong>\uff1a<\/p>\n<p>\u8fd0\u884c\u547d\u4ee4\uff1a<\/p>\n<pre>npx cypress open\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd9\u5c06\u542f\u52a8 cypress test runner gui\uff0c\u60a8\u53ef\u4ee5\u5728\u5176\u4e2d\u67e5\u770b\u5e76\u9009\u62e9\u8981\u8fd0\u884c\u7684\u6d4b\u8bd5\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173121662651860.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u540c\u65f6\u8fd0\u884c cypress run \u548c cypress open\u63d2\u56fe1\" alt=\"\u5982\u4f55\u540c\u65f6\u8fd0\u884c cypress run \u548c cypress open\u63d2\u56fe1\" \/><\/p>\n<p>\u5355\u51fb e2e \u540e\uff0c\u60a8\u53ef\u4ee5\u770b\u5230\u6b64\u4eea\u8868\u677f\uff0c\u5176\u4e2d\u5728 cypress\/tests \u4e0b\u5305\u542b\u5b8c\u6574\u7684\u6d4b\u8bd5\u5217\u8868\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173121662633603.png\" style=\"max-width:90%\" class=\"aligncenter\" title=\"\u5982\u4f55\u540c\u65f6\u8fd0\u884c cypress run \u548c cypress open\u63d2\u56fe2\" alt=\"\u5982\u4f55\u540c\u65f6\u8fd0\u884c cypress run \u548c cypress open\u63d2\u56fe2\" \/><\/p>\n<p>\u8ba9\u6211\u4eec\u5728 cypress\/tests\/ui\/custom.spec.ts \u4e0b\u7684\u76ee\u5f55\u4e2d\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a custom.spec.ts \u7684\u65b0\u6d4b\u8bd5<\/p>\n<pre>describe(\"user sign-up and login\", function () {\n    beforeeach(function () {\n      \/\/ seed the database before each test\n      cy.task(\"db:seed\");\n\n      \/\/ intercept signup and login api calls\n      cy.intercept(\"post\", \"\/users\").as(\"signup\");\n      cy.intercept(\"post\", \"\/graphql\").as(\"gqlrequests\");\n    });\n\n    it(\"should redirect unauthenticated user to signin page\", function () {\n      cy.visit(\"\/personal\");\n      cy.location(\"pathname\").should(\"equal\", \"\/signin\");\n    });\n\n    it(\"should allow a visitor to sign-up, login, and logout\", function () {\n        const userinfo = {\n          firstname: \"bob\",\n          lastname: \"ross\",\n          username: \"painterjoy90\",\n          password: \"s3cret\",\n        };\n\n      \/\/ sign-up user\n      cy.visit(\"\/signup\");\n\n      cy.getbysel(\"signup-first-name\").type(userinfo.firstname);\n      cy.getbysel(\"signup-last-name\").type(userinfo.lastname);\n      cy.getbysel(\"signup-username\").type(userinfo.username);\n      cy.getbysel(\"signup-password\").type(userinfo.password);\n      cy.getbysel(\"signup-confirmpassword\").type(userinfo.password);\n      cy.visualsnapshot(\"about to sign up\");\n      cy.getbysel(\"signup-submit\").click();\n      cy.wait(\"@signup\");\n\n      \/\/ login user\n      cy.visit(\"\/signin\");\n      cy.login(userinfo.username, userinfo.password);\n\n\n      \/\/ verify successful login\n      cy.location(\"pathname\").should(\"equal\", \"\/\");\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ol>\n<li>\n<p><strong>\u8bbe\u7f6e\uff08beforeeach\uff09<\/strong>\uff1a\u5728\u6bcf\u6b21\u6d4b\u8bd5\u4e4b\u524d\uff0c\u6570\u636e\u5e93\u90fd\u4f1a\u4ee5\u4e00\u81f4\u7684\u72b6\u6001\u5f00\u59cb\uff0c\u5e76\u62e6\u622a\u6ce8\u518c\u548c graphql \u8bf7\u6c42\u7684 api \u8c03\u7528\u4ee5\u8fdb\u884c\u76d1\u63a7\u3002<\/p>\n<\/li>\n<li>\n<p><strong>\u6d4b\u8bd5<\/strong>\uff1a<\/p>\n<\/li>\n<\/ol>\n<pre>* **redirect for unauthenticated user**: checks if an unauthenticated user visiting a restricted page (`\/personal`) is redirected to the `\/signin` page.\n\n* **sign-up, login**: a new user is signed up, logged in, and logged out. the test verifies the user can register, sign in by being redirected to `\/signin`.\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u6bcf\u9879\u6d4b\u8bd5\u90fd\u80fd\u786e\u4fdd\u5b89\u5168\u4e14\u7528\u6237\u53cb\u597d\u7684\u5e10\u6237\u7ba1\u7406\u7684\u5173\u952e\u529f\u80fd\u3002<\/p>\n<p><em>\u6ce8\u610f\uff1a\u5c1d\u8bd5\u6dfb\u52a0\u6ce8\u9500\u548c\u7528\u6237\u540d\u4e0d\u6b63\u786e\u7684\u6d41\u7a0b<\/em><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173121662710203.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u540c\u65f6\u8fd0\u884c cypress run \u548c cypress open\u63d2\u56fe3\" alt=\"\u5982\u4f55\u540c\u65f6\u8fd0\u884c cypress run \u548c cypress open\u63d2\u56fe3\" \/><\/p>\n<h3> <strong>\u4ece cli \u8fd0\u884c\u6d4b\u8bd5<\/strong>\uff1a <\/h3>\n<p>\u5728 ci \u73af\u5883\u6216\u6279\u91cf\u6d4b\u8bd5\u6267\u884c\u4e2d\uff0ccli \u63d0\u4f9b\u4e86\u4e00\u79cd\u7b80\u5316\u7684\u65b9\u6cd5\u3002\u8fd0\u884c\u6240\u6709\u6d4b\u8bd5\u6216\u6307\u5b9a\u5355\u72ec\u7684\u6d4b\u8bd5\u6587\u4ef6\uff1a<\/p>\n<pre>npx cypress run\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<pre>npx cypress run --spec \"cypress\/tests\/ui\/custom.spec.ts\"\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173121662776516.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u540c\u65f6\u8fd0\u884c cypress run \u548c cypress open\u63d2\u56fe4\" alt=\"\u5982\u4f55\u540c\u65f6\u8fd0\u884c cypress run \u548c cypress open\u63d2\u56fe4\" \/><\/p>\n<h2> \u8d5b\u666e\u62c9\u65af\u7684\u597d\u5904 <\/h2>\n<p>\u8d5b\u666e\u62c9\u65af\u4ee5\u5176\u5feb\u901f\u6267\u884c\u3001\u6613\u4e8e\u8bbe\u7f6e\u548c\u5f3a\u5927\u7684\u6d4b\u8bd5\u529f\u80fd\u800c\u95fb\u540d\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u4e3b\u8981\u597d\u5904\uff1a<\/p>\n<ul>\n<li>\n<p><strong>\u5b9e\u65f6\u91cd\u65b0\u52a0\u8f7d\u548c\u4ea4\u4e92\u5f0f\u6d4b\u8bd5<\/strong>\uff1acypress \u901a\u8fc7\u5728\u53d1\u751f\u66f4\u6539\u65f6\u91cd\u65b0\u52a0\u8f7d\u6d4b\u8bd5\u6765\u63d0\u4f9b\u5373\u65f6\u53cd\u9988\uff0c\u8ba9\u5f00\u53d1\u4eba\u5458\u7acb\u5373\u4e86\u89e3\u5e94\u7528\u7a0b\u5e8f\u7684\u884c\u4e3a\u3002<\/p>\n<\/li>\n<li>\n<p><strong>\u65e0\u788e\u7247\u6d4b\u8bd5<\/strong>\uff1a\u51ed\u501f\u5176\u72ec\u7279\u7684\u67b6\u6784\uff0ccypress \u51cf\u5c11\u4e86\u6d4b\u8bd5\u4e2d\u7684\u788e\u7247\uff0c\u4f7f\u60a8\u7684\u6d4b\u8bd5\u7ed3\u679c\u66f4\u52a0\u53ef\u9760\u3002<\/p>\n<\/li>\n<li>\n<p><strong>\u81ea\u52a8\u7b49\u5f85<\/strong>\uff1acypress \u7b49\u5f85\u5143\u7d20\u52a0\u8f7d\u3001\u54cd\u5e94\u548c\u6e32\u67d3\uff0c\u56e0\u6b64\u60a8\u4e0d\u9700\u8981\u6dfb\u52a0\u663e\u5f0f\u7b49\u5f85\u3002<\/p>\n<\/li>\n<li>\n<p><strong>\u5185\u7f6e\u65ad\u8a00\u548c\u6a21\u62df<\/strong>\uff1acypress \u9644\u5e26\u4e86\u4e00\u7ec4\u4e30\u5bcc\u7684\u65ad\u8a00\u548c\u5de5\u5177\uff0c\u7528\u4e8e\u6a21\u62df api \u54cd\u5e94\u548c\u6a21\u62df\u7528\u6237\u4ea4\u4e92\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u5c31\u50cf cypress \u901a\u8fc7\u81ea\u52a8\u5316\u7528\u6237\u4ea4\u4e92\u6765\u652f\u6301\u9ad8\u6548\u7684 e2e \u6d4b\u8bd5\u4e00\u6837\uff0ckeploy \u901a\u8fc7\u4e13\u6ce8\u4e8e\u540e\u7aef\u4e3a\u6d4b\u8bd5\u5e26\u6765\u4e86\u5f3a\u5927\u7684\u7ef4\u5ea6\u3002<\/p>\n<p>cypress \u64c5\u957f\u9a8c\u8bc1\u524d\u7aef\u548c\u7528\u6237\u4f53\u9a8c\uff0c\u800c keploy \u5219\u901a\u8fc7\u81ea\u52a8\u751f\u6210\u548c\u7ef4\u62a4 api \u6d4b\u8bd5\u6765\u8865\u5145\u5b83\uff0c\u800c\u65e0\u9700\u989d\u5916\u7684\u811a\u672c\u3002<\/p>\n<p>keploy \u5bf9\u4e8e\u6355\u83b7\u73b0\u5b9e\u4e16\u754c\u7684\u4ea4\u4e92\u5e76\u5c06\u5176\u8f6c\u5316\u4e3a\u53ef\u6267\u884c\u6d4b\u8bd5\u7279\u522b\u6709\u6548\uff0c\u786e\u4fdd\u968f\u7740\u5e94\u7528\u7a0b\u5e8f\u89c4\u6a21\u7684\u6269\u5927\u540e\u7aef\u4e00\u81f4\u6027\u548c\u6570\u636e\u53ef\u9760\u6027\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173121662847422.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u540c\u65f6\u8fd0\u884c cypress run \u548c cypress open\u63d2\u56fe5\" alt=\"\u5982\u4f55\u540c\u65f6\u8fd0\u884c cypress run \u548c cypress open\u63d2\u56fe5\" \/><\/p>\n<ul>\n<li>\n<p><strong>\u81ea\u52a8\u5316\u6d4b\u8bd5\u5e73\u53f0<\/strong>\uff1akeploy \u4e13\u6ce8\u4e8e\u4e3a\u540e\u7aef\u670d\u52a1\u81ea\u52a8\u751f\u6210\u6d4b\u8bd5\uff0c\u7279\u522b\u662f api \u548c\u6570\u636e\u5e93\u4ea4\u4e92\u3002<\/p>\n<\/li>\n<li>\n<p><strong>\u6355\u83b7\u548c\u91cd\u653e<\/strong>\uff1akeploy \u6355\u83b7\u771f\u5b9e\u4e16\u754c\u7684\u6d41\u91cf\u5e76\u5728\u6d4b\u8bd5\u73af\u5883\u4e2d\u91cd\u653e\uff0c\u521b\u5efa\u771f\u5b9e\u7684\u6d4b\u8bd5\u7528\u4f8b\u3002<\/p>\n<\/li>\n<li>\n<p><strong>\u65e0\u4ee3\u7801\u6d4b\u8bd5\u751f\u6210<\/strong>\uff1a\u4e13\u4e3a\u8f7b\u677e\u800c\u8bbe\u8ba1\uff0c\u5b83\u65e0\u9700\u81ea\u5b9a\u4e49\u811a\u672c\u5373\u53ef\u751f\u6210\u6d4b\u8bd5\u3002<\/p>\n<\/li>\n<\/ul>\n<p><strong>\u4f7f\u7528 keploy \u8fdb\u884c\u7aef\u5230\u7aef\u6d4b\u8bd5\uff1a<\/strong><\/p>\n<ul>\n<li>\n<p><strong>\u4ee5 api \u4e3a\u4e2d\u5fc3\u7684 e2e \u6d4b\u8bd5<\/strong>\uff1a\u81ea\u52a8\u5316\u540e\u7aef\u7ec4\u4ef6\u7684\u7aef\u5230\u7aef\u6d4b\u8bd5\uff0c\u786e\u4fdd\u540e\u7aef\u529f\u80fd\u4f5c\u4e3a\u4e00\u4e2a\u5355\u5143\u8fdb\u884c\u9a8c\u8bc1\u3002<\/p>\n<\/li>\n<li>\n<p><strong>\u9519\u8bef\u68c0\u6d4b\u548c\u91cd\u653e<\/strong>\uff1a\u6355\u83b7 api \u8bf7\u6c42\/\u54cd\u5e94\u3001\u91cd\u653e\u4ea4\u4e92\u5e76\u5c3d\u65e9\u68c0\u6d4b\u56de\u5f52\u3002<\/p>\n<\/li>\n<li>\n<p><strong>\u4e00\u81f4\u7684\u6570\u636e\u9a8c\u8bc1<\/strong>\uff1a\u8ddf\u8e2a\u6570\u636e\u6d41\u4e2d\u7684\u54cd\u5e94\u548c\u53d8\u5316\uff0c\u786e\u4fdd\u8de8\u90e8\u7f72\u7684\u51c6\u786e\u6027\u3002<\/p>\n<\/li>\n<li>\n<p><strong>\u65e0\u7f1d\u96c6\u6210<\/strong>\uff1a\u8f7b\u677e\u4e0e ci\/cd \u7ba1\u9053\u96c6\u6210\uff0c\u5e2e\u52a9\u56e2\u961f\u81ea\u52a8\u5316\u5bf9\u540e\u7aef\u53d8\u66f4\u8fdb\u884c\u7aef\u5230\u7aef\u68c0\u67e5\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u8fd9\u4e2a\u9886\u57df\u6709\u5f88\u591a\u5de5\u5177\uff0c\u6bcf\u4e2a\u5de5\u5177\u90fd\u63d0\u4f9b\u9002\u5408\u4e0d\u540c\u7c7b\u578b\u6d4b\u8bd5\u73af\u5883\u7684\u529f\u80fd\uff0c\u4ece puppeteer \u4e2d\u7684\u6d4f\u89c8\u5668\u7279\u5b9a\u6d4b\u8bd5\u5230 playwright \u548c selenium \u4e2d\u7684\u8de8\u6d4f\u89c8\u5668\u517c\u5bb9\u6027\u3002<\/p>\n<p>\u9009\u62e9\u6b63\u786e\u7684\u5de5\u5177\u6700\u7ec8\u53d6\u51b3\u4e8e\u60a8\u7684\u6d4b\u8bd5\u9700\u6c42\u548c\u5e94\u7528\u7a0b\u5e8f\u8981\u6c42\u3002<\/p>\n<h2> \u5e38\u95ee\u95ee\u9898 <\/h2>\n<h3> <strong>cypress \u53ef\u4ee5\u7528\u4e8e\u540e\u7aef\u6d4b\u8bd5\u5417\uff1f<\/strong> <\/h3>\n<p>cypress \u4e3b\u8981\u662f\u4e00\u4e2a\u524d\u7aef\u6d4b\u8bd5\u5de5\u5177\u3002\u867d\u7136\u5b83\u53ef\u4ee5\u4e0e\u540e\u7aef api \u548c\u6a21\u62df\u54cd\u5e94\u4ea4\u4e92\uff0c\u4f46\u5b83\u5e76\u4e0d\u662f\u4e3a\u5e7f\u6cdb\u7684\u540e\u7aef\u6d4b\u8bd5\u800c\u8bbe\u8ba1\u7684\u3002\u5bf9\u4e8e\u7279\u5b9a\u4e8e\u540e\u7aef\u7684\u6d4b\u8bd5\uff0ckeploy \u7b49\u5de5\u5177\u53ef\u4ee5\u901a\u8fc7\u4e3a\u670d\u52a1\u5668\u7aef\u529f\u80fd\u63d0\u4f9b\u5355\u5143\u548c\u96c6\u6210\u6d4b\u8bd5\u529f\u80fd\u6765\u8865\u5145 cypress\u3002<\/p>\n<h3> <strong>cypress \u652f\u6301\u8de8\u6d4f\u89c8\u5668\u6d4b\u8bd5\u5417\uff1f<\/strong> <\/h3>\n<p>\u662f\u7684\uff0ccypress \u652f\u6301 chrome\u3001edge \u548c firefox\u3002\u7136\u800c\uff0c\u4e0e selenium \u6216 playwright \u7b49\u63d0\u4f9b\u66f4\u5e7f\u6cdb\u7684\u8de8\u6d4f\u89c8\u5668\u517c\u5bb9\u6027\u7684\u5de5\u5177\u76f8\u6bd4\uff0c\u5b83\u7684\u652f\u6301\u6709\u9650\u3002<\/p>\n<h3> <strong>cypress \u5982\u4f55\u5904\u7406 api \u6d4b\u8bd5\uff1f<\/strong> <\/h3>\n<p>cypress \u53ef\u4ee5\u901a\u8fc7\u76f4\u63a5\u4ece\u6d4b\u8bd5\u4ee3\u7801\u53d1\u51fa http \u8bf7\u6c42\u6765\u6267\u884c api \u6d4b\u8bd5\u3002\u60a8\u53ef\u4ee5\u4f7f\u7528 cy.request() \u6765\u9a8c\u8bc1 api \u54cd\u5e94\uff0c\u4ece\u800c\u53ef\u4ee5\u8f7b\u677e\u5730\u5728\u540c\u4e00\u7aef\u5230\u7aef\u6d4b\u8bd5\u6846\u67b6\u4e2d\u6d4b\u8bd5 api\u3002<\/p>\n<h3> <strong>\u5982\u4f55\u8c03\u8bd5\u5931\u8d25\u7684 cypress \u6d4b\u8bd5\uff1f<\/strong> <\/h3>\n<p>cypress \u9ed8\u8ba4\u63d0\u4f9b\u8be6\u7ec6\u7684\u65e5\u5fd7\u548c\u5c4f\u5e55\u622a\u56fe\uff0c\u5e76\u4e14\u6d4b\u8bd5\u8fd0\u884c\u5668\u5141\u8bb8\u60a8\u4ee5\u53ef\u89c6\u65b9\u5f0f\u4e0e\u6d4b\u8bd5\u8fdb\u884c\u4ea4\u4e92\u3002\u60a8\u53ef\u4ee5\u6dfb\u52a0 .only \u6765\u9694\u79bb\u5931\u8d25\u7684\u6d4b\u8bd5\uff0c\u4f7f\u7528 cy.pause() \u505c\u6b62\u6267\u884c\uff0c\u5e76\u5229\u7528 chrome devtools \u8fdb\u884c\u8fdb\u4e00\u6b65\u8c03\u8bd5\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u540c\u65f6\u8fd0\u884c cypress run \u548c cypress open\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>cypress \u662f\u4e00\u4e2a\u4e3a web \u5e94\u7528\u7a0b\u5e8f\u6784\u5efa\u7684\u5f3a\u5927\u7684\u7aef\u5230\u7aef\u6d4b\u8bd5\u6846\u67b6\u3002\u5b83\u65e8\u5728\u4f7f\u6d4b\u8bd5\u53d8\u5f97\u7b80\u5355\u53ef\u9760\uff0c\u4f7f\u5f00\u53d1\u4eba\u5458\u548c qa \u5de5\u7a0b\u5e08\u80fd\u591f\u6d4b\u8bd5\u4ece\u7b80\u5355\u4ea4\u4e92\u5230\u590d\u6742\u7528\u6237\u5de5\u4f5c\u6d41\u7a0b\u7684\u6240\u6709\u5185\u5bb9\u3002\u501f\u52a9 cypress\uff0c\u60a8\u53ef\u4ee5\u521b\u5efa\u6a21\u62df\u7528\u6237\u64cd\u4f5c\u3001\u9a8c\u8bc1\u524d\u7aef\u884c\u4e3a\u5e76\u4ee5\u6700\u5c11\u7684\u8bbe\u7f6e\u786e\u4fdd ui \u529f\u80fd\u7684\u6d4b\u8bd5\u3002 \u8d5b\u666e\u62c9\u65af\u6709\u4ec0\u4e48\u7528\u9014\uff1f cypress \u4e3b\u8981\u7528\u4e8e web \u5e94\u7528\u7a0b\u5e8f\u4e2d\u7684\u7aef\u5230\u7aef\u6d4b\u8bd5\uff0c\u4f46\u5b83\u5bf9\u4e8e\u524d\u7aef\u73af\u5883\u4e2d\u7684\u96c6\u6210\u548c\u5355\u5143\u6d4b\u8bd5\u4e5f\u5f88\u6709\u6548\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u89c1\u7528\u4f8b\uff1a \u81ea\u52a8\u5316\u7528\u6237\u6d41\u7a0b\uff1a\u6d4b\u8bd5\u590d\u6742\u7684\u7528\u6237\u6d41\u7a0b\uff0c\u4f8b\u5982\u8eab\u4efd\u9a8c\u8bc1\u3001\u548c\u7535\u5b50\u5546\u52a1\u4ea4\u6613\u3002 \u6d4b\u8bd5\u54cd\u5e94\u5f0f\u8bbe\u8ba1\uff1acypress \u5141\u8bb8\u8de8\u4e0d\u540c\u89c6\u53e3\u5927\u5c0f\u8fdb\u884c\u6d4b\u8bd5\uff0c\u4f7f\u5176\u6210\u4e3a\u54cd\u5e94\u5f0f\u8bbe\u8ba1\u6d4b\u8bd5\u7684\u7406\u60f3\u9009\u62e9\u3002 \u56de\u5f52\u6d4b\u8bd5\uff1a\u901a\u8fc7\u81ea\u52a8\u5316\u6d4b\u8bd5\u7528\u4f8b\uff0c\u60a8\u53ef\u4ee5\u5feb\u901f\u9a8c\u8bc1\u65b0\u7684\u4ee3\u7801\u66f4\u6539\u662f\u5426\u6ca1\u6709\u5f15\u5165\u9519\u8bef\u3002 ui \u7ec4\u4ef6\u6d4b\u8bd5\uff1acypress \u53ef\u4ee5\u4e0e storybook \u7b49\u5de5\u5177\u4e00\u8d77\u4f7f\u7528\u6765\u5355\u72ec\u9a8c\u8bc1\u524d\u7aef\u7ec4\u4ef6\uff0c\u786e\u4fdd\u5b83\u4eec\u5728\u5404\u79cd\u573a\u666f\u4e2d\u6309\u9884\u671f\u8fd0\u884c\u3002 cypress \u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u4eea\u8868\u677f\u548c cli\uff0c\u53ef\u4ee5\u65e0\u7f1d\u96c6\u6210\u5230 ci\/cd \u7ba1\u9053\u4e2d\uff0c\u4f7f\u5176\u6210\u4e3a\u73b0\u4ee3 web \u5f00\u53d1\u4e2d\u81ea\u52a8\u5316\u3001\u6301\u7eed\u6d4b\u8bd5\u7684\u9996\u9009\u3002 \u4f7f\u7528 cypress \u8fd0\u884c\u6d4b\u8bd5 \u53ef\u4ee5\u901a\u8fc7\u4e24\u79cd\u4e3b\u8981\u65b9\u5f0f\u5728 cypress \u4e2d\u8fd0\u884c\u6d4b\u8bd5\uff1a\u4f7f\u7528\u6d4b\u8bd5\u8fd0\u884c\u5668 (gui) \u548c\u547d\u4ee4\u884c\u754c\u9762 (cli)\u3002 \u8fd9\u662f\u4e24\u79cd\u65b9\u6cd5\u7684\u5feb\u901f\u6307\u5357\uff1a \u4f7f\u7528\u6d4b\u8bd5\u8fd0\u884c\u5668 (gui)\uff1a \u8981\u4ee5\u4ea4\u4e92\u65b9\u5f0f\u4f7f\u7528 cypress test runner \u4e0e cypress real world \u5e94\u7528\u7a0b\u5e8f\uff0c\u8bf7\u6309\u7167\u4ee5\u4e0b\u6b65\u9aa4\u64cd\u4f5c\u3002\u8be5\u5e94\u7528\u7a0b\u5e8f\u63d0\u4f9b\u4e86\u8d5b\u666e\u62c9\u65af\u5b9e\u9645\u6d4b\u8bd5\u7684\u53ef\u9760\u793a\u4f8b\uff0c\u4ee5\u53ca\u3001\u767b\u5f55\u548c\u4ea4\u6613\u6d41\u7a0b\u7684\u573a\u666f\u3002 \u6211\u4eec\u4ee5 cypress \u7684\u793a\u4f8b\u5e94\u7528\u7a0b\u5e8f\u201ccypress real [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-4048","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/4048","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=4048"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/4048\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=4048"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=4048"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=4048"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}