{"id":17478,"date":"2022-06-16T10:21:07","date_gmt":"2022-06-16T01:21:07","guid":{"rendered":"http:\/\/www.code-magagine.com\/?p=17478"},"modified":"2023-05-28T08:38:25","modified_gmt":"2023-05-27T23:38:25","slug":"%e3%80%90cypress%e3%80%91api%e4%b8%80%e8%a6%a7","status":"publish","type":"post","link":"http:\/\/www.code-magagine.com\/?p=17478","title":{"rendered":"\u3010Cypress\u3011\u30b3\u30de\u30f3\u30c9\u4e00\u89a7"},"content":{"rendered":"<h2>cy.intercept<\/h2>\n<div>API\u304c\u5b9f\u884c\u3055\u308c\u3066\u3044\u308b\u3053\u3068\u3092\u62c5\u4fdd\u3067\u304d\u308b\u3002\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u4f7f\u3046\u3053\u3068\u3067API\u306e\u5b9f\u884c\u3092\u540c\u671f\u7684\u306b\u5f85\u3064\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/div>\n<div>\n<pre class=\"lang:default decode:true \">cy.intercept('HTTP\u30e1\u30bd\u30c3\u30c9','\u30ea\u30af\u30a8\u30b9\u30c8URL').as('\u547d\u540d');\r\ncy.wait(\"@\u547d\u540d\u3057\u305fAPI\")<\/pre>\n<div>\n<h2>cy.visit<\/h2>\n<p>\u5bfe\u8c61\u306eURL\u306b\u30a2\u30af\u30bb\u30b9\u3059\u308b\u3002Cypress\u306e\u8a2d\u5b9a\u3067baseURL\u3092\u8a2d\u5b9a\u3059\u308b\u3068URL\u6307\u5b9a\u304c\u697d\u306b\u306a\u308b\u3002\uff08\u30d9\u30b9\u30c8\u30d7\u30e9\u30af\u30c6\u30a3\u30b9\u3068\u66f8\u304b\u308c\u3066\u3044\u308b\u3002\uff09<\/p>\n<div>https:\/\/docs.cypress.io\/guides\/references\/best-practices#Setting-a-global-baseUrl<\/div>\n<\/div>\n<\/div>\n<h2>cy.get<\/h2>\n<div>\u8981\u7d20\u306e\u53d6\u5f97\u304c\u3067\u304d\u307e\u3059\u3002<\/div>\n<div>\n<pre class=\"lang:default decode:true\">cy.get('#app')<\/pre>\n<h3>\u89aa\u8981\u7d20\u306e\u53d6\u5f97<\/h3>\n<p>\u5b50\u8981\u7d20\u306e\u8981\u7d20\u3092get\u3067\u53d6\u5f97\u3057\u3066parent\u3092\u4f7f\u3044\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true \">cy.get('.child').parent()<\/pre>\n<div>\n<div>\n<h2>\u30d5\u30a9\u30fc\u30e0\u8981\u7d20\u64cd\u4f5c<\/h2>\n<h3>\u30c6\u30ad\u30b9\u30c8\u306b\u5024\u3092\u5165\u529b<\/h3>\n<pre class=\"lang:default decode:true \">cy.get('#text').type('\u3053\u3093\u306b\u3061\u306f')<\/pre>\n<h3>\u30c6\u30ad\u30b9\u30c8\u8981\u7d20\u306e\u30af\u30ea\u30a2<\/h3>\n<pre class=\"lang:default decode:true \">cy.get('text').clear()<\/pre>\n<p><span style=\"font-size: 23px; font-weight: 900;\">\u30c1\u30a7\u30c3\u30af\u30dc\u30c3\u30af\u30b9\u306e\u30c1\u30a7\u30c3\u30af<\/span><\/p>\n<\/div>\n<\/div>\n<div>\n<pre class=\"lang:default decode:true\">cy.get('[value=\"check_1\"]').check()<\/pre>\n<\/div>\n<h3>\u30e9\u30b8\u30aa\u30dc\u30bf\u30f3\u306e\u9078\u629e<\/h3>\n<div>\n<pre class=\"lang:default decode:true \">cy.get('[type=\"radio\"]').first().check()<\/pre>\n<p>first\u3067\u30e9\u30b8\u30aa\u30dc\u30bf\u30f3\u306e\u6700\u521d\u306e\u8981\u7d20\u3092\u9078\u629e\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<\/div>\n<h3>\u30dc\u30bf\u30f3\u3092\u30af\u30ea\u30c3\u30af<\/h3>\n<div>\n<pre class=\"lang:default decode:true\"> cy.get('#button').click()<\/pre>\n<p><span style=\"font-size: 28px; font-weight: 900;\">\u30a2\u30b5\u30fc\u30b7\u30e7\u30f3<\/span><\/p>\n<\/div>\n<h3><span style=\"font-size: 28px; font-weight: 900;\">should()<\/span><\/h3>\n<\/div>\n<p>\u30a2\u30b5\u30fc\u30b7\u30e7\u30f3\u306e\u4e00\u3064\u3067\u3059\u3002\u3082\u3061\u308d\u3093\u3001visit\u3084click\u306a\u3069\u4ed6\u306eAPI\u3067\u3082\u30a2\u30b5\u30fc\u30b7\u30e7\u30f3\u306f\u3067\u304d\u307e\u3059(\u30c7\u30d5\u30a9\u30eb\u30c8\u30a2\u30b5\u30fc\u30b7\u30e7\u30f3\uff09\u304c\u3001<\/p>\n<pre class=\"lang:default decode:true\">cy.get('id\u540d\u306a\u3069').should(\"have.value\", \"hogehoge\");<\/pre>\n<div>\n<div>\n<h4>not.be.visible<\/h4>\n<p>DOM\u306f\u5b58\u5728\u3059\u308b\u304c<span style=\"color: #ff0000;\"><strong>\u300cdisplay:none\u300d<\/strong><\/span>\u306a\u3069\u306e\u30d7\u30ed\u30d1\u30c6\u30a3\u304c\u6307\u5b9a\u3055\u308c\u3066\u3044\u308b\u8981\u7d20\u306a\u3069\u306e\u30c1\u30a7\u30c3\u30af\u306b\u4f7f\u3048\u307e\u3059\u3002<\/p>\n<\/div>\n<h4>not.exist<\/h4>\n<div>DOM\u81ea\u4f53\u304c\u5b58\u5728\u3057\u306a\u3044\u3053\u3068\u306e\u30c1\u30a7\u30c3\u30af\u304c\u3067\u304d\u307e\u3059\u3002\u4f8b\u3048\u3070\u3001React\u306e\u6761\u4ef6\u5206\u5c90\u3067DOM\u81ea\u4f53\u3092\u6d88\u3059\u5834\u5408\u306e\u5224\u5b9a\u306a\u3069\u306b\u4f7f\u3048\u307e\u3059\u3002<\/div>\n<\/div>\n<h4>have.class<\/h4>\n<div>\n<div>CSS\u306eclass\u306e\u5185\u5bb9\u3092\u30c1\u30a7\u30c3\u30af\u3067\u304d\u307e\u3059\u3002<\/div>\n<div><\/div>\n<\/div>\n<div>\n<div>\n<h4>have.length<\/h4>\n<div>\u8981\u7d20\u306e\u500b\u6570\u306a\u3069\u3092\u30c1\u30a7\u30c3\u30af\u3067\u304d\u307e\u3059\u3002\u4f8b\u3048\u3070\u3001\u300cchildren()\u300d\u306a\u3069\u3067\u5b50\u8981\u7d20\u306e\u500b\u6570\u306a\u3069\u3092\u5224\u5b9a\u3059\u308b\u306e\u306b\u4f7f\u3048\u307e\u3059\u3002<\/div>\n<\/div>\n<\/div>\n<h2><span class=\"p\">.<\/span><span class=\"nx\">contains<\/span><span class=\"p\">(<\/span><span class=\"dl\">'\u5024<\/span><span class=\"dl\">'<\/span><span class=\"p\">)<\/span><\/h2>\n<div>\u8981\u7d20\u306b\u5024\u304c\u542b\u307e\u308c\u3066\u3044\u308b\u304b\u5224\u5b9a\u3057\u307e\u3059\u3002<\/div>\n","protected":false},"excerpt":{"rendered":"cy.intercept API\u304c\u5b9f\u884c\u3055\u308c\u3066\u3044\u308b\u3053\u3068\u3092\u62c5\u4fdd\u3067\u304d\u308b\u3002\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u4f7f\u3046\u3053\u3068\u3067API\u306e\u5b9f\u884c\u3092\u540c\u671f\u7684\u306b\u5f85\u3064\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002 cy.intercept('HTTP\u30e1\u30bd\u30c3\u30c9','\u30ea\u30af\u30a8\u30b9\u30c8URL').as('\u547d\u540d') [&hellip;]","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[57],"tags":[],"_links":{"self":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/17478"}],"collection":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=17478"}],"version-history":[{"count":10,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/17478\/revisions"}],"predecessor-version":[{"id":20772,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/17478\/revisions\/20772"}],"wp:attachment":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=17478"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=17478"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=17478"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}