text: "use strict";(self.webpackChunkwebsite=self.webpackChunkwebsite||[]).push([[7704],{4137:function(e,t,r){r.d(t,{Zo:function(){return u},kt:function(){return d}});var n=r(7294);function o(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function a(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function i(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?a(Object(r),!0).forEach((function(t){o(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):a(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function l(e,t){if(null==e)return{};var r,n,o=function(e,t){if(null==e)return{};var r,n,o={},a=Object.keys(e);for(n=0;n<a.length;n++)r=a[n],t.indexOf(r)>=0||(o[r]=e[r]);return o}(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(n=0;n<a.length;n++)r=a[n],t.indexOf(r)>=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(o[r]=e[r])}return o}var p=n.createContext({}),s=function(e){var t=n.useContext(p),r=t;return e&&(r="function"==typeof e?e(t):i(i({},t),e)),r},u=function(e){var t=s(e.components);return n.createElement(p.Provider,{value:t},e.children)},c={inlineCode:"code",wrapper:function(e){var t=e.children;return n.createElement(n.Fragment,{},t)}},m=n.forwardRef((function(e,t){var r=e.components,o=e.mdxType,a=e.originalType,p=e.parentName,u=l(e,["components","mdxType","originalType","parentName"]),m=s(r),d=o,f=m["".concat(p,".").concat(d)]||m[d]||c[d]||a;return r?n.createElement(f,i(i({ref:t},u),{},{components:r})):n.createElement(f,i({ref:t},u))}));function d(e,t){var r=arguments,o=t&&t.mdxType;if("string"==typeof e||o){var a=r.length,i=new Array(a);i[0]=m;var l={};for(var p in t)hasOwnProperty.call(t,p)&&(l[p]=t[p]);l.originalType=e,l.mdxType="string"==typeof e?e:o,i[1]=l;for(var s=2;s<a;s++)i[s]=r[s];return n.createElement.apply(null,i)}return n.createElement.apply(null,r)}m.displayName="MDXCreateElement"},8448:function(e,t,r){var n=r(7294);t.Z=function(e){var t=e.children,r=e.hidden,o=e.className;return n.createElement("div",{role:"tabpanel",hidden:r,className:o},t)}},7225:function(e,t,r){r.d(t,{Z:function(){return m}});var n=r(7462),o=r(7294),a=r(1048),i=r(2713);var l=function(){var e=(0,o.useContext)(i.Z);if(null==e)throw new Error('"useUserPreferencesContext" is used outside of "Layout" component.');return e},p=r(3309),s=r(6010),u="tabItem_vU9c";function c(e){var t,r,n,a=e.lazy,i=e.block,c=e.defaultValue,m=e.values,d=e.groupId,f=e.className,g=o.Children.map(e.children,(function(e){if((0,o.isValidElement)(e)&&void 0!==e.props.value)return e;throw new Error("Docusaurus error: Bad <Tabs> child <"+("string"==typeof e.type?e.type:e.type.name)+'>: all children of the <Tabs> component should be <TabItem>, and every <TabItem> should have a unique "value" prop.')})),k=null!=m?m:g.map((function(e){var t=e.props;return{value:t.value,label:t.label}})),h=(0,p.lx)(k,(function(e,t){return e.value===t.value}));if(h.length>0)throw new Error('Docusaurus error: Duplicate values "'+h.map((function(e){return e.value})).join(", ")+'" found in <Tabs>. Every value needs to be unique.');var v=null===c?c:null!=(t=null!=c?c:null==(r=g.find((function(e){return e.props.default})))?void 0:r.props.value)?t:null==(n=g[0])?void 0:n.props.value;if(null!==v&&!k.some((function(e){return e.value===v})))throw new Error('Docusaurus error: The <Tabs> has a defaultValue "'+v+'" but none of its children has the corresponding value. Available values are: '+k.map((function(e){return e.value})).join(", ")+". If you intend to show no default tab, use defaultValue={null} instead.");var N=l(),b=N.tabGroupChoices,y=N.setTabGroupChoices,w=(0,o.useState)(v),C=w[0],T=w[1],O=[],j=(0,p.o5)().blockElementScrollPositionUntilNextRender;if(null!=d){var E=b[d];null!=E&&E!==C&&k.some((function(e){return e.value===E}))&&T(E)}var x=function(e){var t=e.currentTarget,r=O.indexOf(t),n=k[r].value;n!==C&&(j(t),T(n),null!=d&&y(d,n))},R=function(e){var t,r=null;switch(e.key){case"ArrowRight":var n=O.indexOf(e.currentTarget)+1;r=O[n]||O[0];break;case"ArrowLeft":var o=O.indexOf(e.currentTarget)-1;r=O[o]||O[O.length-1]}null==(t=r)||t.focus()};return o.createElement("div",{className:"tabs-container"},o.createElement("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,s.Z)("tabs",{"tabs--block":i},f)},k.map((function(e){var t=e.value,r=e.label;return o.createElement("li",{role:"tab",tabIndex:C===t?0:-1,"aria-selected":C===t,className:(0,s.Z)("tabs__item",u,{"tabs__item--active":C===t}),key:t,ref:function(e){return O.push(e)},onKeyDown:R,onFocus:x,onClick:x},null!=r?r:t)}))),a?(0,o.cloneElement)(g.filter((function(e){return e.props.value===C}))[0],{className:"margin-vert--md"}):o.createElement("div",{className:"margin-vert--md"},g.map((function(e,t){return(0,o.cloneElement)(e,{key:t,hidden:e.props.value!==C})}))))}function m(e){var t=(0,a.Z)();return o.createElement(c,(0,n.Z)({key:String(t)},e))}},2713:function(e,t,r){var n=(0,r(7294).createContext)(void 0);t.Z=n},4821:function(e,t,r){r.r(t),r.d(t,{frontMatter:function(){return l},contentTitle:function(){return p},metadata:function(){return s},toc:function(){return u},default:function(){return m}});var n=r(7462),o=r(3366),a=(r(7294),r(4137)),i=(r(7225),r(8448),["components"]),l={id:"wdio-reportportal-reporter",title:"Report Portal Reporter",custom_edit_url:"https://github.com/borisosipov/wdio-reportportal-reporter/edit/master//README.md"},p=void 0,s={unversionedId:"wdio-reportportal-reporter",id:"wdio-reportportal-reporter",isDocsHomePage:!1,title:"Report Portal Reporter",description:"wdio-reportportal-reporter is a 3rd party package, for more information please see GitHub | npm",source:"@site/docs/_wdio-reportportal-reporter.md",sourceDirName:".",slug:"/wdio-reportportal-reporter",permalink:"/docs/wdio-reportportal-reporter",editUrl:"https://github.com/borisosipov/wdio-reportportal-reporter/edit/master//README.md",tags:[],version:"current",frontMatter:{id:"wdio-reportportal-reporter",title:"Report Portal Reporter",custom_edit_url:"https://github.com/borisosipov/wdio-reportportal-reporter/edit/master//README.md"},sidebar:"docs",previous:{title:"Sumologic Reporter",permalink:"/docs/sumologic-reporter"},next:{title:"Video Reporter",permalink:"/docs/wdio-video-reporter"}},u=[{value:"Installation",id:"installation",children:[],level:2},{value:"Configuration",id:"configuration",children:[{value:"Methods description",id:"methods-description",children:[],level:3}],level:2},{value:"Getting link to Report Portal UI launch page",id:"getting-link-to-report-portal-ui-launch-page",children:[],level:2},{value:"Reporting test to existing launch",id:"reporting-test-to-existing-launch",children:[],level:2},{value:"License",id:"license",children:[],level:2}],c={toc:u};function m(e){var t=e.components,r=(0,o.Z)(e,i);return(0,a.kt)("wrapper",(0,n.Z)({},c,r,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("blockquote",null,(0,a.kt)("p",{parentName:"blockquote"},"wdio-reportportal-reporter is a 3rd party package, for more information please see ",(0,a.kt)("a",{parentName:"p",href:"https://github.com/borisosipov/wdio-reportportal-reporter"},"GitHub")," | ",(0,a.kt)("a",{parentName:"p",href:"https://www.npmjs.com/package/wdio-reportportal-reporter"},"npm"))),(0,a.kt)("p",null,(0,a.kt)("img",{parentName:"p",src:"https://img.shields.io/npm/v/wdio-reportportal-reporter",alt:"npm"}),"\n",(0,a.kt)("img",{parentName:"p",src:"https://img.shields.io/npm/dm/wdio-reportportal-reporter",alt:"npm"})),(0,a.kt)("blockquote",null,(0,a.kt)("p",{parentName:"blockquote"},"A WebdriverIO reporter plugin to report results to Report Portal(",(0,a.kt)("a",{parentName:"p",href:"http://reportportal.io/"},"http://reportportal.io/"),").")),(0,a.kt)("h2",{id:"installation"},"Installation"),(0,a.kt)("p",null,"The easiest way is to keep ",(0,a.kt)("inlineCode",{parentName:"p"},"wdio-reportportal-reporter")," and ",(0,a.kt)("inlineCode",{parentName:"p"},"wdio-reportportal-service")," as a devDependency in your ",(0,a.kt)("inlineCode",{parentName:"p"},"package.json"),"."),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-json"},'{\n  "devDependencies": {\n    "wdio-reportportal-reporter": "^7.0.0",\n    "wdio-reportportal-service": "^7.0.0"\n  }\n}\n')),(0,a.kt)("p",null,"Instructions on how to install ",(0,a.kt)("inlineCode",{parentName:"p"},"WebdriverIO")," can be found ",(0,a.kt)("a",{parentName:"p",href:"https://webdriver.io/docs/gettingstarted.html"},"here"),"."),(0,a.kt)("h2",{id:"configuration"},"Configuration"),(0,a.kt)("p",null,"Configure the output directory in your wdio.conf.js file:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-js"},"const reportportal = require('wdio-reportportal-reporter');\nconst RpService = require(\"wdio-reportportal-service\");\n\nconst conf = {\n  reportPortalClientConfig: { // report portal settings\n    token: '00000000-0000-0000-0000-00000000000',\n    endpoint: 'https://reportportal-url/api/v1',\n    launch: 'launch_name',\n    project: 'project_name',\n    mode: 'DEFAULT',\n    debug: false,\n    description: \"Launch description text\",\n    attributes: [{key:\"tag\", value: \"foo\"}],\n    headers: {\"foo\": \"bar\"}, // optional headers for internal http client\n    restClientConfig: { // axios like http client config - https://github.com/axios/axios#request-config\n      proxy: {\n        protocol: 'https',\n        host: '127.0.0.1',\n        port: 9000,\n        auth: {\n          username: 'mikeymike',\n          password: 'rapunz3l'\n        }\n      },\n      timeout: 60000\n    }\n  },\n  reportSeleniumCommands: false, // add selenium commands to log\n  seleniumCommandsLogLevel: 'debug', // log level for selenium commands\n  autoAttachScreenshots: false, // automatically add screenshots\n  screenshotsLogLevel: 'info', // log level for screenshots\n  parseTagsFromTestTitle: false, // parse strings like `@foo` from titles and add to Report Portal\n  cucumberNestedSteps: false, // report cucumber steps as Report Portal steps\n  autoAttachCucumberFeatureToScenario: false, // requires cucumberNestedSteps to be true for use\n  sanitizeErrorMessages: true, // strip color ascii characters from error stacktrace\n  sauceLabOptions : {\n    enabled: true, // automatically add SauseLab ID to rp tags.\n    sldc: \"US\" // automatically add SauseLab region to rp tags.\n  }\n};\n\nexports.config = {\n  // ...\n  services: [[RpService, {}]],\n  reporters: [[reportportal, conf]],\n  // ...\n};\n")),(0,a.kt)("h1",{id:"additional-api"},"Additional API"),(0,a.kt)("p",null,"Api methods can be accessed using:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-js"},"const reporter = require('wdio-reportportal-reporter')\n")),(0,a.kt)("h3",{id:"methods-description"},"Methods description"),(0,a.kt)("ul",null,(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"reporter.addAttribute({key, value}) ")," \u2013 add an attribute to current test.",(0,a.kt)("ul",{parentName:"li"},(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"key")," (",(0,a.kt)("em",{parentName:"li"},"string"),", optional) -  attribute key. It must be non-empty string."),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"value")," (",(0,a.kt)("em",{parentName:"li"},"string"),", required)\u2013  attribute value. It must be non-empty string."))),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"reporter.sendLog(level, message) ")," \u2013 send log to current suite\\test item.",(0,a.kt)("ul",{parentName:"li"},(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"level")," (",(0,a.kt)("em",{parentName:"li"},"string"),") - log level. Values ","['trace', 'debug', 'info', 'warn', 'error']","."),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"message")," (",(0,a.kt)("em",{parentName:"li"},"string"),")\u2013 log message content."))),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"reporter.sendFile(level, name, content, [type])")," \u2013 send file to current suite\\test item.",(0,a.kt)("ul",{parentName:"li"},(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"level")," (",(0,a.kt)("em",{parentName:"li"},"string"),") - log level. Values ","['trace', 'debug', 'info', 'warn', 'error']","."),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"name")," (",(0,a.kt)("em",{parentName:"li"},"string"),")\u2013 file name."),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"content")," (",(0,a.kt)("em",{parentName:"li"},"string"),") \u2013 attachment content"),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"type")," (",(0,a.kt)("em",{parentName:"li"},"string"),", optional) \u2013 attachment MIME-type, ",(0,a.kt)("inlineCode",{parentName:"li"},"image/png")," by default"),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"message")," (",(0,a.kt)("em",{parentName:"li"},"string"),")\u2013 log message content."))),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"reporter.sendLogToTest(test, level, message)")," - send log to specific test.",(0,a.kt)("ul",{parentName:"li"},(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"test")," (",(0,a.kt)("em",{parentName:"li"},"object"),") - test object from ",(0,a.kt)("inlineCode",{parentName:"li"},"afterTest\\afterStep")," wdio hook"),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"level")," (",(0,a.kt)("em",{parentName:"li"},"string"),") - log level. Values ","['trace', 'debug', 'info', 'warn', 'error']","."),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"message")," (",(0,a.kt)("em",{parentName:"li"},"string"),")\u2013 log message content."))),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"reporter.sendFileToTest(test, level, name, content, [type])")," \u2013 send file to to specific test.",(0,a.kt)("ul",{parentName:"li"},(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"test")," (",(0,a.kt)("em",{parentName:"li"},"object"),") - test object from ",(0,a.kt)("inlineCode",{parentName:"li"},"afterTest\\afterStep")," wdio hook"),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"level")," (",(0,a.kt)("em",{parentName:"li"},"string"),") - log level. Values ","['trace', 'debug', 'info', 'warn', 'error']","."),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"name")," (",(0,a.kt)("em",{parentName:"li"},"string"),")\u2013 file name."),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"content")," (",(0,a.kt)("em",{parentName:"li"},"string"),") \u2013 attachment content"),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"type")," (",(0,a.kt)("em",{parentName:"li"},"string"),", optional) \u2013 attachment MIME-type, ",(0,a.kt)("inlineCode",{parentName:"li"},"image/png")," by default"),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("inlineCode",{parentName:"li"},"message")," (",(0,a.kt)("em",{parentName:"li"},"string"),")\u2013 log message content.")))),(0,a.kt)("p",null,"Pay attention: ",(0,a.kt)("inlineCode",{parentName:"p"},"sendLog"),"\\",(0,a.kt)("inlineCode",{parentName:"p"},"sendFile")," sends log to ",(0,a.kt)("strong",{parentName:"p"},"current running test item"),". It means if you send log without active test(e.g from hooks or on suite level) it will not be reported Report Portal UI."),(0,a.kt)("p",null,"Methods ",(0,a.kt)("inlineCode",{parentName:"p"},"sendLogToTest"),"\\",(0,a.kt)("inlineCode",{parentName:"p"},"sendFileToTest")," are useful when you need to send screenshots or logs to the failed test item from wdio afterTest hook."),(0,a.kt)("p",null,"Mocha example:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-js"},"const reportportal = require('wdio-reportportal-reporter');\nconst path = require('path');\nconst fs = require('fs');\n\nexports.config = {\n...\n  afterTest(test) {\n    if (test.passed === false) {\n      const filename = \"screnshot.png\";\n      const outputFile = path.join(__dirname, filename);\n      browser.saveScreenshot(outputFile);\n      reportportal.sendFileToTest(test, 'info', filename, fs.readFileSync(outputFile));\n    }\n  }\n...\n")),(0,a.kt)("p",null,"Jasmine example:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-js"},"const reportportal = require('wdio-reportportal-reporter');\nconst path = require('path');\nconst fs = require('fs');\n\nexports.config = {\n...\n  afterTest(test) {\n    if (test.passed === false) {\n      const filename = \"screnshot.png\";\n      const outputFile = path.join(__dirname, filename);\n      browser.saveScreenshot(outputFile);\n      //!!\n      Object.assign(test, {title: test.description}}\n      reportportal.sendFileToTest(test, 'info', filename, fs.readFileSync(outputFile));\n    }\n  }\n...\n")),(0,a.kt)("p",null,'WDIO Cucumber "5.14.3+" Example:'),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-js"},"const reportportal = require('wdio-reportportal-reporter');\n\nexports.config = {\n...\n   afterStep: function (uri, feature, { error, result, duration, passed }, stepData, context) {\n     if (!passed) {\n        let failureObject = {};\n        failureObject.type = 'afterStep';\n        failureObject.error = error;\n        failureObject.title = `${stepData.step.keyword}${stepData.step.text}`;\n        const screenShot = global.browser.takeScreenshot();\n        let attachment = Buffer.from(screenShot, 'base64');\n        reportportal.sendFileToTest(failureObject, 'error', \"screnshot.png\", attachment);\n    }\n  }\n...\n}\n")),(0,a.kt)("h2",{id:"getting-link-to-report-portal-ui-launch-page"},"Getting link to Report Portal UI launch page"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-js"},'const RpService = require("wdio-reportportal-service");\n...\n    onComplete: async function (_, config) {\n        const link = await RpService.getLaunchUrl(config);\n        console.log(`Report portal link ${link}`)\n    }\n...\n')),(0,a.kt)("p",null,"or more complicated way"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-js"},"const RpService = require(\"wdio-reportportal-service\");\n...\n    onComplete: async function (_, config) {\n        const protocol = 'http:';\n        const hostname = 'example.com';\n        const port = ':8080'; // or empty string for default 80/443 ports\n        const link = await RpService.getLaunchUrlByParams(protocol, hostname, port, config);\n        console.log(`Report portal link ${link}`)\n    }\n...\n")),(0,a.kt)("h2",{id:"reporting-test-to-existing-launch"},"Reporting test to existing launch"),(0,a.kt)("p",null,"If you want report test to existing active launch you may pass it to reporter by environment variable ",(0,a.kt)("inlineCode",{parentName:"p"},"REPORT_PORTAL_LAUNCH_ID"),"\nYou are responsible for finishing launch as well as starting such launch."),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-sh"},"$ export REPORT_PORTAL_LAUNCH_ID=SomeLaunchId\n$ npm run wdio\n")),(0,a.kt)("h2",{id:"license"},"License"),(0,a.kt)("p",null,"This project is licensed under the MIT License - see the ",(0,a.kt)("a",{parentName:"p",href:"https://github.com/BorisOsipov/wdio-reportportal-reporter/blob/master/LICENSE"},"LICENSE.md")," file for details"))}m.isMDXComponent=!0}}]);