{"id":345021,"date":"2023-02-06T09:01:53","date_gmt":"2023-02-06T09:01:53","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=345021"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=345021","title":{"rendered":"<span>\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u043a\u043e\u043c\u0430\u043d\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u0438\u0437 XCTest<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<ul>\n<li>\n<p>\u0427\u0442\u043e \u044d\u0442\u043e \u0442\u0430\u043a\u043e\u0435?<\/p>\n<\/li>\n<li>\n<p>\u0418 \u044d\u0442\u043e \u043f\u043e\u043b\u0435\u0437\u043d\u043e, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e\u2026?<\/p>\n<\/li>\n<li>\n<p>\u041a\u0440\u0443\u0442\u043e, \u0432 \u0447\u0451\u043c \u043f\u0440\u0438\u043a\u043e\u043b?<\/p>\n<\/li>\n<li>\n<p>\u0425\u043e\u0440\u043e\u0448\u043e, \u043f\u043e\u043a\u0430\u0436\u0438 \u043c\u043d\u0435, \u043a\u0430\u043a \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c!<\/p>\n<\/li>\n<li>\n<p>\u042d\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043d\u0430 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0445 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430\u0445?<\/p>\n<\/li>\n<li>\n<p>\u0425\u043e\u0440\u043e\u0448\u043e, \u044d\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043d\u0430 CI?<\/p>\n<\/li>\n<li>\n<p>\u0411\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u043e \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u0435\u043d!<\/p>\n<\/li>\n<\/ul>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/14c\/ab6\/db4\/14cab6db413338ad100c5b9f4913c1a9.webp\" alt=\"\" title=\"\" width=\"1099\" height=\"618\"\/><figcaption><\/figcaption><\/figure>\n<h3>\u0427\u0442\u043e \u044d\u0442\u043e \u0442\u0430\u043a\u043e\u0435?<\/h3>\n<p>\u041a\u043e\u043c\u0430\u043d\u0434\u043d\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430 \u2014 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043c\u043e\u0449\u043d\u044b\u0439 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442. \u0415\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0437\u0430\u0446\u0438\u0438 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 \u0432\u0435\u0449\u0435\u0439 \u0437\u0434\u0435\u0441\u044c \u0438 \u0442\u0430\u043c. \u041e\u0447\u0435\u0432\u0438\u0434\u043d\u043e, \u0440\u0435\u0447\u044c \u0438\u0434\u0451\u0442 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u043e \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u044f\u0445\u00a0<strong>Shell<\/strong>, \u0438\u0437 \u043d\u0435\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0438 \u043b\u044e\u0431\u043e\u0439 \u0434\u0440\u0443\u0433\u043e\u0439 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442. \u041d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e.<\/p>\n<p><strong>XCTest<\/strong>, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0432\u043d\u0443\u0442\u0440\u0438 \u043f\u0435\u0441\u043e\u0447\u043d\u0438\u0446\u044b, \u044d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u0432\u044b \u0431\u0443\u043a\u0432\u0430\u043b\u044c\u043d\u043e \u043d\u0435 \u043c\u043e\u0436\u0435\u0442\u0435 \u0434\u0430\u0436\u0435 \u0432\u044b\u0441\u0443\u043d\u0443\u0442\u044c \u043d\u043e\u0441 \u0438\u0437 \u043a\u043e\u0440\u043e\u0431\u043a\u0438. \u041d\u0443, \u043f\u043e\u0447\u0442\u0438. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043e\u0431\u043e\u0439\u0434\u0451\u043c \u044d\u0442\u043e \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u0438 \u0443\u0437\u043d\u0430\u0435\u043c, \u043a\u0430\u043a \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u043a\u043e\u043c\u0430\u043d\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u0438\u0437 \u0442\u0435\u0441\u0442\u043e\u0432.<\/p>\n<h3>\u0418 \u044d\u0442\u043e \u043f\u043e\u043b\u0435\u0437\u043d\u043e, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e\u2026?<\/h3>\n<p>1. \u042d\u0442\u043e \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u0442 \u0441\u043e\u0432\u0435\u0440\u0448\u0435\u043d\u043d\u043e \u043d\u043e\u0432\u044b\u0439 \u043c\u0438\u0440 \u0444\u0443\u043d\u043a\u0446\u0438\u0439, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0445 \u0441 \u0441\u0438\u043c\u0443\u043b\u044f\u0442\u043e\u0440\u043e\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b \u0447\u0435\u0440\u0435\u0437\u00a0<strong>simctl\u00a0<\/strong>\u0438\u00a0<a href=\"https:\/\/github.com\/facebook\/idb\" rel=\"noopener noreferrer nofollow\">idb<\/a>, \u043d\u043e \u0435\u0449\u0435 \u043d\u0435 \u0447\u0435\u0440\u0435\u0437\u00a0<strong>XCTest\u00a0<\/strong>API. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<ul>\n<li>\n<p>\u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 push-\u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u0439;<\/p>\n<\/li>\n<li>\n<p>\u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0437\u0430\u0446\u0438\u044f \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0435\u0432, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0445 \u0441 \u043c\u0435\u0441\u0442\u043e\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0435\u043c;<\/p>\n<\/li>\n<li>\n<p>\u0432\u0438\u0434\u0435\u043e\u0437\u0430\u043f\u0438\u0441\u044c \u043d\u0435\u0443\u0434\u0430\u0447\u043d\u044b\u0445 \u0438\u0441\u043f\u044b\u0442\u0430\u043d\u0438\u0439.<\/p>\n<\/li>\n<\/ul>\n<p>2. \u042d\u0442\u043e \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u00a0<a href=\"https:\/\/github.com\/alteral\/mockserver-driven-development#standalone-mock-server\" rel=\"noopener noreferrer nofollow\">\u0430\u0432\u0442\u043e\u043d\u043e\u043c\u043d\u044b\u0439 \u0444\u0438\u043a\u0442\u0438\u0432\u043d\u044b\u0439 \u0441\u0435\u0440\u0432\u0435\u0440<\/a>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0439 \u0431\u044d\u043a\u044d\u043d\u0434 \u0434\u043b\u044f \u0446\u0435\u043b\u0435\u0439 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f.<\/p>\n<p>3. \u042d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u043b\u044e\u0431\u044b\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 macOS \u0447\u0435\u0440\u0435\u0437\u00a0<a href=\"https:\/\/github.com\/alteral\/mockserver-driven-development#standalone-mock-server\" rel=\"noopener noreferrer nofollow\">Applescript\u00a0<\/a>\u0438\u0437 \u0432\u0430\u0448\u0438\u0445\u00a0<strong>XCTests<\/strong>.<\/p>\n<p>4. \u042d\u0442\u043e \u0434\u0430\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0435 \u0441 \u0418\u043d\u0442\u0435\u0440\u043d\u0435\u0442\u043e\u043c, \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e\u00a0<a href=\"https:\/\/github.com\/microsoft\/playwright\" rel=\"noopener noreferrer nofollow\">playwright\u00a0<\/a>\u0438\u043b\u0438\u00a0<a href=\"https:\/\/github.com\/SeleniumHQ\/selenium\" rel=\"noopener noreferrer nofollow\">selenium\u00a0<\/a>\u0432\u043c\u0435\u0441\u0442\u043e \u043e\u0442\u043a\u0440\u044b\u0442\u0438\u044f Safari \u043d\u0430 iOS.<\/p>\n<p>5. \u042d\u0442\u043e \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u0435\u0442 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0433\u0438\u0431\u043a\u0438\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u044d\u043a\u0441\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u0441\u0451, \u0447\u0442\u043e \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435, \u0438\u0437 \u0442\u0435\u0441\u0442\u0430 \u043d\u0430 \u0445\u043e\u0441\u0442-\u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440 (\u0441\u043a\u0440\u0438\u043d\u0448\u043e\u0442\u044b, \u043c\u0430\u043a\u0435\u0442\u044b, \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0438 \u0442. \u0434.).<\/p>\n<p>6. \u0418 \u043c\u043d\u043e\u0433\u043e\u0435 \u0434\u0440\u0443\u0433\u043e\u0435.<\/p>\n<h3>\u041a\u0440\u0443\u0442\u043e, \u0432 \u0447\u0451\u043c \u043f\u0440\u0438\u043a\u043e\u043b?<\/h3>\n<p>\u041d\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c HTTP-\u0441\u0435\u0440\u0432\u0435\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0441\u043b\u0443\u0448\u0438\u0432\u0430\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441\u044b. \u0417\u0430\u0442\u0435\u043c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441 \u0438\u0437\u00a0<strong>XCTest\u00a0<\/strong>\u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440 \u0438 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0432\u0441\u0451, \u0447\u0442\u043e \u0437\u0430\u0445\u043e\u0442\u0438\u043c. \u0421\u0435\u0440\u0432\u0435\u0440 \u043c\u043e\u0436\u0435\u0442 \u0434\u0430\u0436\u0435 \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u0432\u044b\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u043e\u0431\u0440\u0430\u0442\u043d\u043e \u0432\u00a0<strong>XCTest<\/strong>, \u0435\u0441\u043b\u0438 \u044d\u0442\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e.<\/p>\n<h3>\u0425\u043e\u0440\u043e\u0448\u043e, \u043f\u043e\u043a\u0430\u0436\u0438 \u043c\u043d\u0435, \u043a\u0430\u043a \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c!<\/h3>\n<h3>\u041f\u0440\u0438\u043c\u0435\u0440 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u044f<\/h3>\n<p><strong>GIVEN\u00a0<\/strong>we have a server running\u00a0<strong>on localhost<\/strong>:\u00a0<strong>4567<\/strong>\u00a0(\u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0441\u0435\u0440\u0432\u0435\u0440, \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0449\u0438\u0439 \u043d\u0430 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u043c \u0445\u043e\u0441\u0442\u0435: 4567)<\/p>\n<p><strong>AND\u00a0<\/strong>we sent a request to\u00a0<strong>\/terminal<\/strong>\u00a0endpoint from XCTest with the desired command (\u0438 \u043c\u044b \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u043b\u0438 \u0437\u0430\u043f\u0440\u043e\u0441 \u043d\u0430 \u043a\u043e\u043d\u0435\u0447\u043d\u0443\u044e \u0442\u043e\u0447\u043a\u0443 \/terminal \u0438\u0437 XCTest \u0441 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u043e\u0439)<\/p>\n<p><strong>WHEN server\u00a0<\/strong>receives the request (\u0441\u0435\u0440\u0432\u0435\u0440 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u0437\u0430\u043f\u0440\u043e\u0441)<\/p>\n<p><strong>AND server\u00a0<\/strong>executes the command (\u0438 \u0441\u0435\u0440\u0432\u0435\u0440 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u043a\u043e\u043c\u0430\u043d\u0434\u0443)<\/p>\n<p><strong>THEN server\u00a0<\/strong>returns the result back to XCTest (\u0442\u043e\u0433\u0434\u0430 \u0441\u0435\u0440\u0432\u0435\u0440 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043e\u0431\u0440\u0430\u0442\u043d\u043e \u0432 XCTest)<\/p>\n<p><strong>AND\u00a0<\/strong>XCTest verifies the result (\u0438 XCTest \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442)<\/p>\n<h3>\u041f\u0440\u043e\u0445\u043e\u0434\u0438\u043c \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0439<\/h3>\n<p>1. \u0412\u044b\u0431\u0435\u0440\u0438\u0442\u0435 \u043b\u044e\u0431\u043e\u0439 \u0432\u0435\u0431-\u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a \u043f\u043e \u0432\u0430\u0448\u0435\u043c\u0443 \u0432\u044b\u0431\u043e\u0440\u0443 (\u043e\u043d\u0438 \u043f\u043e\u0447\u0442\u0438 \u0432\u0441\u0435 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b \u0434\u043b\u044f \u043d\u0430\u0448\u0435\u0433\u043e \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f)<\/p>\n<pre><code class=\"swift\">{    \"js\": \"express\", \/\/ https:\/\/github.com\/expressjs\/express    \"rb\": \"sinatra\", \/\/ https:\/\/github.com\/sinatra\/sinatra    \"py\": \"flask\", \/\/ https:\/\/github.com\/pallets\/flask    \"go\": \"gin\", \/\/ https:\/\/github.com\/gin-gonic\/gin    \"..\": \"...\" \/\/ ...  }<\/code><\/pre>\n<p>2. \u0421\u043e\u0437\u0434\u0430\u0439\u0442\u0435 HTTP-\u0441\u0435\u0440\u0432\u0435\u0440 (\u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u044f \u0432\u0437\u044f\u043b { &#171;js&#187;: &#171;express&#187; })<\/p>\n<ul>\n<li>\n<p>\u041a\u043e\u043c\u0430\u043d\u0434\u043d\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430:<\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"swift\">npm install express touch server.js open server.js<\/code><\/pre>\n<ul>\n<li>\n<p>server.js:<\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"swift\">const process = require(\"child_process\");   const express = require(\"express\");   const app = express();   const port = 4567;    app.use(express.json());    app.listen(port);    app.post(\"\/terminal\", (req, res) => {     const output = exec(req.body.command, req.query.async).toString(\"utf8\").trim();     res.send(output);   });    function exec(command, async) {     if (async === \"true\") {       return process.exec(command);     } else {       return process.execSync(command);     }   }<\/code><\/pre>\n<p>3. \u0417\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u0435 \u0441\u0435\u0440\u0432\u0435\u0440<\/p>\n<p>4. \u0421\u043e\u0437\u0434\u0430\u0439\u0442\u0435 \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0439 \u0444\u0430\u0439\u043b<\/p>\n<pre><code class=\"swift\">import XCTest   class SampleUITests: XCTestCase {      let host = \"http:\/\/localhost\"      let port: UInt16 = 4567       func testMacintoshVersion() {          let macOsVersion = exec(\"sw_vers -productVersion\")          XCTAssertEqual(macOsVersion.split(separator: \".\").first, \"12\")      }       func exec(_ command: String, async: Bool = false) -> String {          let urlString = \"\\(host):\\(port)\/terminal?async=\\(async)\"          guard let url = URL(string: urlString) else { return \"\" }           var request = URLRequest(url: url)          request.httpMethod = \"POST\"          request.setValue(\"application\/json\", forHTTPHeaderField: \"Content-Type\")          request.httpBody = try? JSONSerialization.data(withJSONObject: [\"command\": command], options: [])          var output = \"\"           if async {              \/\/ Do not wait for the command to complete              URLSession.shared.dataTask(with: request).resume()          } else {              \/\/ Wait for the command to complete              let semaphore = DispatchSemaphore(value: 0)              let task = URLSession.shared.dataTask(with: request) { data, response, error in                  if let data = data, let string = String(data: data, encoding: .utf8) {                      output = string                      semaphore.signal()                  }              }              task.resume()              semaphore.wait()          }          return output      }  }<\/code><\/pre>\n<p>5. \u0417\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u0435 \u0442\u0435\u0441\u0442<\/p>\n<p>6. \u041d\u0430\u0441\u0442\u0440\u043e\u0439\u0442\u0435 \u0441\u043a\u0440\u0438\u043f\u0442\u044b \u043f\u043e\u0434 \u0441\u0432\u043e\u0438 \u043d\u0443\u0436\u0434\u044b \u0438 \u043d\u0430\u0441\u043b\u0430\u0436\u0434\u0430\u0439\u0442\u0435\u0441\u044c \u0432\u0437\u043b\u043e\u043c\u043e\u043c!<\/p>\n<h3>\u042d\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043d\u0430 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0445 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430\u0445?<\/h3>\n<p>\u042d\u043c\u043c, \u0434\u0430, \u043d\u043e \u043d\u0435 \u0438\u0437 \u043a\u043e\u0440\u043e\u0431\u043a\u0438. \u0412\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0443\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u0441\u0435\u0440\u0432\u0435\u0440 \u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d \u0441 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430.\u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0435\u0441\u0442\u044c \u0434\u0432\u0430 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430:<\/p>\n<ul>\n<li>\n<p>\u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0439\u0442\u0435\u0441\u044c \u043a Wi-Fi \u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0439\u0442\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f IP-\u0430\u0434\u0440\u0435\u0441 \u0440\u0430\u0431\u043e\u0447\u0435\u0433\u043e \u0441\u0442\u043e\u043b\u0430 \u0432\u043c\u0435\u0441\u0442\u043e\u00a0<strong>\u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0445\u043e\u0441\u0442\u0430<\/strong>.<\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u044c\u0442\u0435 \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0432\u0430\u0448\u0435\u043c\u0443 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u043c\u0443 \u0441\u0435\u0440\u0432\u0435\u0440\u0443 \u0432 \u0418\u043d\u0442\u0435\u0440\u043d\u0435\u0442\u0435 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0447\u0435\u0440\u0435\u0437\u00a0<a href=\"https:\/\/github.com\/inconshreveable\/ngrok\" rel=\"noopener noreferrer nofollow\">ngrok<\/a>).<\/p>\n<\/li>\n<\/ul>\n<h3>\u0425\u043e\u0440\u043e\u0448\u043e, \u0430 \u044d\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043d\u0430 CI?<\/h3>\n<p>\u041a\u043e\u043d\u0435\u0447\u043d\u043e, \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043a\u0430\u043a \u0447\u0430\u0441\u044b!<\/p>\n<p>\u041f\u0440\u043e\u0441\u0442\u043e \u0443\u0431\u0435\u0434\u0438\u0442\u0435\u0441\u044c, \u0447\u0442\u043e \u0441\u0435\u0440\u0432\u0435\u0440 \u0437\u0430\u043f\u0443\u0449\u0435\u043d \u0432 \u0444\u043e\u043d\u043e\u0432\u043e\u043c \u0440\u0435\u0436\u0438\u043c\u0435 \u043d\u0430 CI:<\/p>\n<pre><code class=\"swift\">node server.js &amp;<\/code><\/pre>\n<h3>\u0411\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u043e \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u0435\u043d!<\/h3>\n<p>\u041c\u044b \u0412\u0430\u043c \u0431\u043e\u043b\u0435\u0435 \u0447\u0435\u043c \u0440\u0430\u0434\u044b!<\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p> <!----> <!----><\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/714784\/\"> https:\/\/habr.com\/ru\/post\/714784\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<ul>\n<li>\n<p>\u0427\u0442\u043e \u044d\u0442\u043e \u0442\u0430\u043a\u043e\u0435?<\/p>\n<\/li>\n<li>\n<p>\u0418 \u044d\u0442\u043e \u043f\u043e\u043b\u0435\u0437\u043d\u043e, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e\u2026?<\/p>\n<\/li>\n<li>\n<p>\u041a\u0440\u0443\u0442\u043e, \u0432 \u0447\u0451\u043c \u043f\u0440\u0438\u043a\u043e\u043b?<\/p>\n<\/li>\n<li>\n<p>\u0425\u043e\u0440\u043e\u0448\u043e, \u043f\u043e\u043a\u0430\u0436\u0438 \u043c\u043d\u0435, \u043a\u0430\u043a \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c!<\/p>\n<\/li>\n<li>\n<p>\u042d\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043d\u0430 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0445 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430\u0445?<\/p>\n<\/li>\n<li>\n<p>\u0425\u043e\u0440\u043e\u0448\u043e, \u044d\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043d\u0430 CI?<\/p>\n<\/li>\n<li>\n<p>\u0411\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u043e \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u0435\u043d!<\/p>\n<\/li>\n<\/ul>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<h3>\u0427\u0442\u043e \u044d\u0442\u043e \u0442\u0430\u043a\u043e\u0435?<\/h3>\n<p>\u041a\u043e\u043c\u0430\u043d\u0434\u043d\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430 \u2014 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043c\u043e\u0449\u043d\u044b\u0439 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442. \u0415\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0437\u0430\u0446\u0438\u0438 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 \u0432\u0435\u0449\u0435\u0439 \u0437\u0434\u0435\u0441\u044c \u0438 \u0442\u0430\u043c. \u041e\u0447\u0435\u0432\u0438\u0434\u043d\u043e, \u0440\u0435\u0447\u044c \u0438\u0434\u0451\u0442 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u043e \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u044f\u0445\u00a0<strong>Shell<\/strong>, \u0438\u0437 \u043d\u0435\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0438 \u043b\u044e\u0431\u043e\u0439 \u0434\u0440\u0443\u0433\u043e\u0439 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442. \u041d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e.<\/p>\n<p><strong>XCTest<\/strong>, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0432\u043d\u0443\u0442\u0440\u0438 \u043f\u0435\u0441\u043e\u0447\u043d\u0438\u0446\u044b, \u044d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u0432\u044b \u0431\u0443\u043a\u0432\u0430\u043b\u044c\u043d\u043e \u043d\u0435 \u043c\u043e\u0436\u0435\u0442\u0435 \u0434\u0430\u0436\u0435 \u0432\u044b\u0441\u0443\u043d\u0443\u0442\u044c \u043d\u043e\u0441 \u0438\u0437 \u043a\u043e\u0440\u043e\u0431\u043a\u0438. \u041d\u0443, \u043f\u043e\u0447\u0442\u0438. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043e\u0431\u043e\u0439\u0434\u0451\u043c \u044d\u0442\u043e \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u0438 \u0443\u0437\u043d\u0430\u0435\u043c, \u043a\u0430\u043a \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u043a\u043e\u043c\u0430\u043d\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u0438\u0437 \u0442\u0435\u0441\u0442\u043e\u0432.<\/p>\n<h3>\u0418 \u044d\u0442\u043e \u043f\u043e\u043b\u0435\u0437\u043d\u043e, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e\u2026?<\/h3>\n<p>1. \u042d\u0442\u043e \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u0442 \u0441\u043e\u0432\u0435\u0440\u0448\u0435\u043d\u043d\u043e \u043d\u043e\u0432\u044b\u0439 \u043c\u0438\u0440 \u0444\u0443\u043d\u043a\u0446\u0438\u0439, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0445 \u0441 \u0441\u0438\u043c\u0443\u043b\u044f\u0442\u043e\u0440\u043e\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b \u0447\u0435\u0440\u0435\u0437\u00a0<strong>simctl\u00a0<\/strong>\u0438\u00a0<a href=\"https:\/\/github.com\/facebook\/idb\" rel=\"noopener noreferrer nofollow\">idb<\/a>, \u043d\u043e \u0435\u0449\u0435 \u043d\u0435 \u0447\u0435\u0440\u0435\u0437\u00a0<strong>XCTest\u00a0<\/strong>API. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<ul>\n<li>\n<p>\u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 push-\u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u0439;<\/p>\n<\/li>\n<li>\n<p>\u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0437\u0430\u0446\u0438\u044f \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0435\u0432, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0445 \u0441 \u043c\u0435\u0441\u0442\u043e\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0435\u043c;<\/p>\n<\/li>\n<li>\n<p>\u0432\u0438\u0434\u0435\u043e\u0437\u0430\u043f\u0438\u0441\u044c \u043d\u0435\u0443\u0434\u0430\u0447\u043d\u044b\u0445 \u0438\u0441\u043f\u044b\u0442\u0430\u043d\u0438\u0439.<\/p>\n<\/li>\n<\/ul>\n<p>2. \u042d\u0442\u043e \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u00a0<a href=\"https:\/\/github.com\/alteral\/mockserver-driven-development#standalone-mock-server\" rel=\"noopener noreferrer nofollow\">\u0430\u0432\u0442\u043e\u043d\u043e\u043c\u043d\u044b\u0439 \u0444\u0438\u043a\u0442\u0438\u0432\u043d\u044b\u0439 \u0441\u0435\u0440\u0432\u0435\u0440<\/a>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0439 \u0431\u044d\u043a\u044d\u043d\u0434 \u0434\u043b\u044f \u0446\u0435\u043b\u0435\u0439 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f.<\/p>\n<p>3. \u042d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u043b\u044e\u0431\u044b\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 macOS \u0447\u0435\u0440\u0435\u0437\u00a0<a href=\"https:\/\/github.com\/alteral\/mockserver-driven-development#standalone-mock-server\" rel=\"noopener noreferrer nofollow\">Applescript\u00a0<\/a>\u0438\u0437 \u0432\u0430\u0448\u0438\u0445\u00a0<strong>XCTests<\/strong>.<\/p>\n<p>4. \u042d\u0442\u043e \u0434\u0430\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0435 \u0441 \u0418\u043d\u0442\u0435\u0440\u043d\u0435\u0442\u043e\u043c, \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e\u00a0<a href=\"https:\/\/github.com\/microsoft\/playwright\" rel=\"noopener noreferrer nofollow\">playwright\u00a0<\/a>\u0438\u043b\u0438\u00a0<a href=\"https:\/\/github.com\/SeleniumHQ\/selenium\" rel=\"noopener noreferrer nofollow\">selenium\u00a0<\/a>\u0432\u043c\u0435\u0441\u0442\u043e \u043e\u0442\u043a\u0440\u044b\u0442\u0438\u044f Safari \u043d\u0430 iOS.<\/p>\n<p>5. \u042d\u0442\u043e \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u0435\u0442 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0433\u0438\u0431\u043a\u0438\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u044d\u043a\u0441\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u0441\u0451, \u0447\u0442\u043e \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435, \u0438\u0437 \u0442\u0435\u0441\u0442\u0430 \u043d\u0430 \u0445\u043e\u0441\u0442-\u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440 (\u0441\u043a\u0440\u0438\u043d\u0448\u043e\u0442\u044b, \u043c\u0430\u043a\u0435\u0442\u044b, \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0438 \u0442. \u0434.).<\/p>\n<p>6. \u0418 \u043c\u043d\u043e\u0433\u043e\u0435 \u0434\u0440\u0443\u0433\u043e\u0435.<\/p>\n<h3>\u041a\u0440\u0443\u0442\u043e, \u0432 \u0447\u0451\u043c \u043f\u0440\u0438\u043a\u043e\u043b?<\/h3>\n<p>\u041d\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c HTTP-\u0441\u0435\u0440\u0432\u0435\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0441\u043b\u0443\u0448\u0438\u0432\u0430\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441\u044b. \u0417\u0430\u0442\u0435\u043c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441 \u0438\u0437\u00a0<strong>XCTest\u00a0<\/strong>\u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440 \u0438 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0432\u0441\u0451, \u0447\u0442\u043e \u0437\u0430\u0445\u043e\u0442\u0438\u043c. \u0421\u0435\u0440\u0432\u0435\u0440 \u043c\u043e\u0436\u0435\u0442 \u0434\u0430\u0436\u0435 \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u0432\u044b\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u043e\u0431\u0440\u0430\u0442\u043d\u043e \u0432\u00a0<strong>XCTest<\/strong>, \u0435\u0441\u043b\u0438 \u044d\u0442\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e.<\/p>\n<h3>\u0425\u043e\u0440\u043e\u0448\u043e, \u043f\u043e\u043a\u0430\u0436\u0438 \u043c\u043d\u0435, \u043a\u0430\u043a \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c!<\/h3>\n<h3>\u041f\u0440\u0438\u043c\u0435\u0440 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u044f<\/h3>\n<p><strong>GIVEN\u00a0<\/strong>we have a server running\u00a0<strong>on localhost<\/strong>:\u00a0<strong>4567<\/strong>\u00a0(\u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0441\u0435\u0440\u0432\u0435\u0440, \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0449\u0438\u0439 \u043d\u0430 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u043c \u0445\u043e\u0441\u0442\u0435: 4567)<\/p>\n<p><strong>AND\u00a0<\/strong>we sent a request to\u00a0<strong>\/terminal<\/strong>\u00a0endpoint from XCTest with the desired command (\u0438 \u043c\u044b \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u043b\u0438 \u0437\u0430\u043f\u0440\u043e\u0441 \u043d\u0430 \u043a\u043e\u043d\u0435\u0447\u043d\u0443\u044e \u0442\u043e\u0447\u043a\u0443 \/terminal \u0438\u0437 XCTest \u0441 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u043e\u0439)<\/p>\n<p><strong>WHEN server\u00a0<\/strong>receives the request (\u0441\u0435\u0440\u0432\u0435\u0440 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u0437\u0430\u043f\u0440\u043e\u0441)<\/p>\n<p><strong>AND server\u00a0<\/strong>executes the command (\u0438 \u0441\u0435\u0440\u0432\u0435\u0440 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u043a\u043e\u043c\u0430\u043d\u0434\u0443)<\/p>\n<p><strong>THEN server\u00a0<\/strong>returns the result back to XCTest (\u0442\u043e\u0433\u0434\u0430 \u0441\u0435\u0440\u0432\u0435\u0440 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043e\u0431\u0440\u0430\u0442\u043d\u043e \u0432 XCTest)<\/p>\n<p><strong>AND\u00a0<\/strong>XCTest verifies the result (\u0438 XCTest \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442)<\/p>\n<h3>\u041f\u0440\u043e\u0445\u043e\u0434\u0438\u043c \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0439<\/h3>\n<p>1. \u0412\u044b\u0431\u0435\u0440\u0438\u0442\u0435 \u043b\u044e\u0431\u043e\u0439 \u0432\u0435\u0431-\u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a \u043f\u043e \u0432\u0430\u0448\u0435\u043c\u0443 \u0432\u044b\u0431\u043e\u0440\u0443 (\u043e\u043d\u0438 \u043f\u043e\u0447\u0442\u0438 \u0432\u0441\u0435 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b \u0434\u043b\u044f \u043d\u0430\u0448\u0435\u0433\u043e \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f)<\/p>\n<pre><code class=\"swift\">{    \"js\": \"express\", \/\/ https:\/\/github.com\/expressjs\/express    \"rb\": \"sinatra\", \/\/ https:\/\/github.com\/sinatra\/sinatra    \"py\": \"flask\", \/\/ https:\/\/github.com\/pallets\/flask    \"go\": \"gin\", \/\/ https:\/\/github.com\/gin-gonic\/gin    \"..\": \"...\" \/\/ ...  }<\/code><\/pre>\n<p>2. \u0421\u043e\u0437\u0434\u0430\u0439\u0442\u0435 HTTP-\u0441\u0435\u0440\u0432\u0435\u0440 (\u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u044f \u0432\u0437\u044f\u043b { &#171;js&#187;: &#171;express&#187; })<\/p>\n<ul>\n<li>\n<p>\u041a\u043e\u043c\u0430\u043d\u0434\u043d\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430:<\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"swift\">npm install express touch server.js open server.js<\/code><\/pre>\n<ul>\n<li>\n<p>server.js:<\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"swift\">const process = require(\"child_process\");   const express = require(\"express\");   const app = express();   const port = 4567;    app.use(express.json());    app.listen(port);    app.post(\"\/terminal\", (req, res) => {     const output = exec(req.body.command, req.query.async).toString(\"utf8\").trim();     res.send(output);   });    function exec(command, async) {     if (async === \"true\") {       return process.exec(command);     } else {       return process.execSync(command);     }   }<\/code><\/pre>\n<p>3. \u0417\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u0435 \u0441\u0435\u0440\u0432\u0435\u0440<\/p>\n<p>4. \u0421\u043e\u0437\u0434\u0430\u0439\u0442\u0435 \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0439 \u0444\u0430\u0439\u043b<\/p>\n<pre><code class=\"swift\">import XCTest   class SampleUITests: XCTestCase {      let host = \"http:\/\/localhost\"      let port: UInt16 = 4567       func testMacintoshVersion() {          let macOsVersion = exec(\"sw_vers -productVersion\")          XCTAssertEqual(macOsVersion.split(separator: \".\").first, \"12\")      }       func exec(_ command: String, async: Bool = false) -> String {          let urlString = \"\\(host):\\(port)\/terminal?async=\\(async)\"          guard let url = URL(string: urlString) else { return \"\" }           var request = URLRequest(url: url)          request.httpMethod = \"POST\"          request.setValue(\"application\/json\", forHTTPHeaderField: \"Content-Type\")          request.httpBody = try? JSONSerialization.data(withJSONObject: [\"command\": command], options: [])          var output = \"\"           if async {              \/\/ Do not wait for the command to complete              URLSession.shared.dataTask(with: request).resume()          } else {              \/\/ Wait for the command to complete              let semaphore = DispatchSemaphore(value: 0)              let task = URLSession.shared.dataTask(with: request) { data, response, error in                  if let data = data, let string = String(data: data, encoding: .utf8) {                      output = string                      semaphore.signal()                  }              }              task.resume()              semaphore.wait()          }          return output      }  }<\/code><\/pre>\n<p>5. \u0417\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u0435 \u0442\u0435\u0441\u0442<\/p>\n<p>6. \u041d\u0430\u0441\u0442\u0440\u043e\u0439\u0442\u0435 \u0441\u043a\u0440\u0438\u043f\u0442\u044b \u043f\u043e\u0434 \u0441\u0432\u043e\u0438 \u043d\u0443\u0436\u0434\u044b \u0438 \u043d\u0430\u0441\u043b\u0430\u0436\u0434\u0430\u0439\u0442\u0435\u0441\u044c \u0432\u0437\u043b\u043e\u043c\u043e\u043c!<\/p>\n<h3>\u042d\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043d\u0430 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0445 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430\u0445?<\/h3>\n<p>\u042d\u043c\u043c, \u0434\u0430, \u043d\u043e \u043d\u0435 \u0438\u0437 \u043a\u043e\u0440\u043e\u0431\u043a\u0438. \u0412\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0443\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u0441\u0435\u0440\u0432\u0435\u0440 \u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d \u0441 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430.\u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0435\u0441\u0442\u044c \u0434\u0432\u0430 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430:<\/p>\n<ul>\n<li>\n<p>\u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0439\u0442\u0435\u0441\u044c \u043a Wi-Fi \u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0439\u0442\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f IP-\u0430\u0434\u0440\u0435\u0441 \u0440\u0430\u0431\u043e\u0447\u0435\u0433\u043e \u0441\u0442\u043e\u043b\u0430 \u0432\u043c\u0435\u0441\u0442\u043e\u00a0<strong>\u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0445\u043e\u0441\u0442\u0430<\/strong>.<\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u044c\u0442\u0435 \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0432\u0430\u0448\u0435\u043c\u0443 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u043c\u0443 \u0441\u0435\u0440\u0432\u0435\u0440\u0443 \u0432 \u0418\u043d\u0442\u0435\u0440\u043d\u0435\u0442\u0435 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0447\u0435\u0440\u0435\u0437\u00a0<a href=\"https:\/\/github.com\/inconshreveable\/ngrok\" rel=\"noopener noreferrer nofollow\">ngrok<\/a>).<\/p>\n<\/li>\n<\/ul>\n<h3>\u0425\u043e\u0440\u043e\u0448\u043e, \u0430 \u044d\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043d\u0430 CI?<\/h3>\n<p>\u041a\u043e\u043d\u0435\u0447\u043d\u043e, \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043a\u0430\u043a \u0447\u0430\u0441\u044b!<\/p>\n<p>\u041f\u0440\u043e\u0441\u0442\u043e \u0443\u0431\u0435\u0434\u0438\u0442\u0435\u0441\u044c, \u0447\u0442\u043e \u0441\u0435\u0440\u0432\u0435\u0440 \u0437\u0430\u043f\u0443\u0449\u0435\u043d \u0432 \u0444\u043e\u043d\u043e\u0432\u043e\u043c \u0440\u0435\u0436\u0438\u043c\u0435 \u043d\u0430 CI:<\/p>\n<pre><code class=\"swift\">node server.js &amp;<\/code><\/pre>\n<h3>\u0411\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u043e \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u0435\u043d!<\/h3>\n<p>\u041c\u044b \u0412\u0430\u043c \u0431\u043e\u043b\u0435\u0435 \u0447\u0435\u043c \u0440\u0430\u0434\u044b!<\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p> <!----> <!----><\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/714784\/\"> https:\/\/habr.com\/ru\/post\/714784\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-345021","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/345021","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=345021"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/345021\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=345021"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=345021"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=345021"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}