UNPKG

14.8 kBJavaScriptView Raw
1!function(){"use strict";module.exports=new function(){require("./TestHelper");var e,t,n,o=require("./TestHelperPO"),r=require("./Logger.js"),i=require("fs"),s=require("bluebird"),l=protractor.ExpectedConditions;return{setChartElements:function(o){t=(e=o).element(by.css("div.highcharts-container")),n=t.element(by.css("svg")),r.info("chart elements set for section "+o)},setSVG:function(e){n=e,r.info("svg element set "+e)},getSVG:function(){return n},setContainer:function(e){t=e,r.info("container set "+e)},getContainer:function(){return t},isChartDisplayed:function(){return n.isPresent()},getAxisText:function(e){return r.info("get axis text using index "+e),this.getAxisTextByIndex(e)},getXaxisText:function(){return r.info("get x-axis text"),this.getAxisTextByIndex(1)},getYaxisText:function(){return r.info("get y-axis text"),this.getAxisTextByIndex(2)},getAxisTextByIndex:function(t){r.info("get axis text by index "+t);var o=protractor.promise.defer();return t-=1,this.waitForChartElement("svg g.highcharts-axis"),(n=e.element(by.css("svg"))).all(by.css("g.highcharts-axis")).filter(function(e,n){return n===t}).then(function(e){1===e.length?e[0].getText().then(function(e){o.fulfill(e)}):(o.reject(new Error("axis text not found for given index!")),r.info("axis text not found for given index!"))}),o.promise},getXaxisLabels:function(){return r.info("get x-axis labels"),this.getAxisLabels("x")},getYaxisLabels:function(){return r.info("get y-axis labels"),this.getAxisLabels("y")},getAxisLabels:function(e,t){r.info("get axis labels");var o=protractor.promise.defer();return void 0===t?t=0:t-=1,n.all(by.css("svg g.highcharts-"+e+"axis-labels")).get(t).all(by.css("text")).then(function(e){var t=new Array;return e.forEach(function(e,n){e.getText().then(function(e){e.trim().length>0&&t.push(e)})}),t}).then(function(t){t.length>0?o.fulfill(t):(o.reject(new Error(e+"-axis labels list is empty!")),r.info(e+"-axis labels list is empty!"))}),o.promise},getLegendsFromSection:function(){r.info("get legends from section div");var t=protractor.promise.defer();return this.waitForChartElement("div.highcharts-legend-item"),e.all(by.css("div.highcharts-legend-item")).then(function(e){var t=new Array;return e.forEach(function(e,n){e.getText().then(function(e){t.push(e)})}),t}).then(function(e){e.length>0?t.fulfill(e):t.reject("No legends!")}),t.promise},getChartData:function(e){var t=protractor.promise.defer();if("true"===process.env.highchart)return r.info("get data from section svg"),robot.setMouseDelay(0),o.isElementPresent(element(by.xpath('//*[@id="menu-second"]/ul/li[1]/a'))).then(function(){var o=robot.getMousePos();console.log("Mouse is at x:"+o.x+" y:"+o.y);var r=robot.getScreenSize().width,l=(new Array,new Array),a=e;console.log("w: "+r);var c=function(e,o){if(console.log("I start is: "+e),e<=r)console.log("i is: "+e+"width is: "+r),function(e,t){return new s(function(n,o){n(robot.moveMouse(e,t))})}(e,350).then(function(){new s(function(e,o){e(n.all(by.css("g.highcharts-tooltip")).then(function(e){if(void 0===e||!e)throw new Error("oh no! list is null");console.log("list: "+e),console.log("list length: "+e.length),e[0].getText().then(function(n){if(void 0===n||!n)throw new Error("oh no! text is null");console.log("in get tooltip 4"),e[0].getText().then(function(e){console.log("in get tooltip 5"+e);var n=e.replace(/,\s/g," ");n=n.replace(/[^\w\s("|,|:|(.\d)|-]/g,""),l.push(n),console.log("text is"+e),console.log("index_data is"+a),n.toString()===a.toString()&&browser.sleep(3e3).then(function(){return t.fulfill(!0),t.promise})}).catch(function(e){console.log("error in querrylist 1:"+e)})})}))}).then(function(t){void 0!==t&&t&&(console.log("text is:"+t),console.log("I in queryList: "+e)),c(e+1)}).catch(function(t){console.log("error in svg all:"+t),c(e+1)})});else{console.log("should not print");var h=l.filter(function(e,t){return l.indexOf(e)==t}),u=new Date,g=h.join();g=g.replace(/,/g,"\n"),i.writeFile("./testchartdata"+u+".csv",g,function(e){e?console.log(e):t.fulfill(g)})}console.log("Test")};return c(330),console.log("post for loop"),t.promise});throw r.info("Highchart disabled. Please enable highchart in .env to use functions. Make 'highchart=true'"),console.log("Highchart disabled. Please enable highchart in .env to use functions. Make 'highchart=true'"),new Error("Highchart disabled. Please enable highchart in .env to use functions. Make 'highchart=true'")},getApmChartData:function(e,n,l,a,c,h){var u=protractor.promise.defer();if(console.log("Here is the value for highchart: "+process.env.highchart),"true"===process.env.highchart){var g=require("robotjs");r.info("get data from section svg"),g.setMouseDelay(0);function f(e,t){return new s(function(n,o){n(g.moveMouse(e,t))})}return o.isElementPresent(element(by.xpath('//*[@id="highcharts-0"]'))).then(function(){g.getMousePos();var o=g.getScreenSize().width,r=(new Array,new Array),d=t.element(by.css("div.highcharts-tooltip"));console.log("w: "+o),f(e,n).then(function(){g.mouseClick(),null!=c&&null!=h&&g.scrollMouse(c,h)});var v=function(e,t){if(e<=o-l)f(e,n).then(function(){new s(function(e,t){e(d.all(by.css("span")).then(function(e){void 0!==e&&e&&e[0].getText().then(function(t){void 0!==t&&t&&e[0].getText().then(function(e){var t=e.split("\n"),n=t.join();if(t=n+"\n",r.push(t),n.toString()===a.toString())browser.sleep(3e3).then(function(){(r=[]).push(!0)});else{var o=string_1.replace(/\.[0-9]\d*/g," "),i=string_2.replace(/\.[0-9]\d*/g," ");o=o.toString(),i=i.toString(),null!=o&&null!=i&&o.valueOf()===i.valueOf()&&browser.sleep(3e3).then(function(){(r=[]).push(!0)})}})})}))}).then(function(){if("boolean"==typeof r[0])return u.fulfill(r[0]),u.promise;v(e+1)}).catch(function(t){v(e+1)})});else{var c=r.filter(function(e,t){return r.indexOf(e)==t}).join(" ");i.writeFile("./testcharhhihiiktdata.csv",c,function(e){e?console.log(e):u.fulfill(c)})}};return v(e),u.promise})}throw r.info("Highchart disabled. Please enable highchart in .env to use functions. Make 'highchart=true'"),console.error("Highchart disabled. Please enable highchart in .env to use functions. Make 'highchart=true'"),new Error("Highchart disabled. Please enable highchart in .env to use functions. Make 'highchart=true'")},getBMChartData:function(e,n,l,a,c,h){var u=protractor.promise.defer();if(console.log("Here is the value for highchart: "+process.env.highchart),"true"===process.env.highchart){var g=require("robotjs");r.info("get data from section svg"),g.setMouseDelay(0);function f(e,t){return new s(function(n,o){console.log("moving the mouse"),n(g.moveMouse(e,t))})}return o.isElementPresent(element(by.css("#container > div.highcharts-container"))).then(function(){g.getMousePos();var o=g.getScreenSize().width;console.log("width is "+o),new Array;var r=new Array,d=t.element(by.css("g.highcharts-tooltip"));console.log("w: "+o),f(e,n).then(function(){g.mouseClick(),console.log("Here is the start"),console.log("rollrange is "+c),console.log("rolldirection is "+h)});var v=function(e,t){if(e<=o-l)console.log("into step"+e),f(e,n).then(function(){new s(function(e,t){e(d.all(by.css("tspan")).then(function(e){void 0!==e&&e&&d.getText().then(function(t){if(void 0!==t&&t){var n=t.split("\n"),o=n.join();if(n=o+"\n",console.log("list length is "+e.length),n=n.replace(/\d+/g,"$&,"),console.log("editdata is : "+n),r.push(n),o.toString()===a.toString())browser.sleep(3e3).then(function(){(r=[]).push(!0)});else{var i=string_1.replace(/\.[0-9]\d*/g," "),s=string_2.replace(/\.[0-9]\d*/g," ");i=i.toString(),s=s.toString(),null!=i&&null!=s&&i.valueOf()===s.valueOf()&&browser.sleep(3e3).then(function(){(r=[]).push(!0)})}}})}))}).then(function(){if("boolean"==typeof r[0])return u.fulfill(r[0]),u.promise;v(e+10)}).catch(function(t){v(e+10)})});else{var c=r.filter(function(e,t){return r.indexOf(e)==t}).join(" ");i.writeFile("./testcharhhihiiktdata.csv",c,function(e){e?console.log(e):u.fulfill(c)})}};return v(e),u.promise})}throw r.info("Highchart disabled. Please enable highchart in .env to use functions. Make 'highchart=true'"),console.error("Highchart disabled. Please enable highchart in .env to use functions. Make 'highchart=true'"),new Error("Highchart disabled. Please enable highchart in .env to use functions. Make 'highchart=true'")},getOOChartData:function(e,n,l,a,c,h,u){var g=protractor.promise.defer();if("true"===process.env.highchart){r.info("get data from section svg"),e=e.split(","),robot.setMouseDelay(0);function f(e,t){return new s(function(n,o){n(robot.moveMouse(e,t))})}return o.isElementPresent(element(by.xpath('//*[@id="r2d1"]/div/section'))).then(function(){robot.getMousePos();var o=robot.getScreenSize().width,r=(new Array,new Array),d=new Array,v=0,p=t.element(by.css("div.highcharts-tooltip"));f(300,450).then(function(){robot.mouseClick(),robot.scrollMouse(h,u)});var b=function(t,h){t<=o-c?f(t,a).then(function(){new s(function(t,o){t(p.all(by.css("span")).then(function(t){void 0!==t&&t&&t[0].getText().then(function(o){void 0!==o&&o&&t[0].getText().then(function(t){var o=t.split("\n");o[3]=o[3].replace(/,/g," ");var i=(o[2]+o[3]).toString();o=(o[0]+" "+o[1]).toString()+","+(o[2]+o[3]).toString(),o+="\n",r.push(o),i!=e[0]&&i!=e[1]&&v!==n||d.push(!0)})})}))}).then(function(){if(!0===d[0]){var e=r.filter(function(e,t){return r.indexOf(e)==t}).join(" ");i.writeFile("./testOOhighchartdata.csv",e,function(t){t?console.log(t):g.fulfill(e)})}else b(t+1)}).catch(function(e){b(t+1)})}):(v++,b(l))};b(l)})}throw r.info("Highchart disabled. Please enable highchart in .env to use functions. Make 'highchart=true'"),console.error("Highchart disabled. Please enable highchart in .env to use functions. Make 'highchart=true'"),new Error("Highchart disabled. Please enable highchart in .env to use functions. Make 'highchart=true'")},getTooltipInfo:function(e,n,l,a,c,h,u,g){var f=protractor.promise.defer();if("true"===process.env.highchart){r.info("get data from section svg"),console.log("rollrange"+u),console.log("rolldirection"+g),robot.setMouseDelay(0);function d(e,t){return new s(function(n,o){n(robot.moveMouse(e,t))})}!function(e,t){new s(function(n,o){n(robot.scrollMouse(e,t))})}(u,g),e&&0!==e.length||(e=" "),n&&0!==n.length||(n=" ");var v=e.split(","),p=n.split(","),b=0;return o.isElementPresent(element(by.xpath('//*[@id="highcharts-0"]'))).then(function(){robot.getMousePos();var e=robot.getScreenSize().width,n=(new Array,new Array),o=t.element(by.css("div.highcharts-tooltip"));d(300,450).then(function(){robot.mouseClick()});var r=function(t,a){if(t<=e-h)d(t,c).then(function(){new s(function(e,t){e(o.all(by.css("span")).then(function(e){void 0!==e&&e&&e[0].getText().then(function(t){void 0!==t&&t&&e[0].getText().then(function(e){if(b<2){var t=new Array,o=e.split("\n");t.push(o[0].toString()),(v.length>1&&b>0||o[0].toString()===v[b].toString())&&browser.sleep(1e3).then(function(){var e=function(r,i){if(r<o.length&&i<p.length)!function(r){var s=o[r].split(":");s[0].toString()===p[i].toString()?(t.push(s[1].toString()),e(1,i+1)):r===o.length-1?!1===l?(t.push("no data"),e(1,i+1)):(n=[]).push(!1):e(r+1,i)}(r);else if(!1===l){if(n.push(t.join()),o[0].toString()===v[b].toString())return b++,n}else(n=[]).push(!0)};e(1,0)})}})})}))}).then(function(){if("boolean"==typeof n[0])return f.fulfill(n[0]),f.promise;if(!1===l&&b===v.length){var e=n.filter(function(e,t){return n.indexOf(e)==t});return f.fulfill(e),f.promise}r(t+1)}).catch(function(e){r(t+1)})});else{var u=n.filter(function(e,t){return n.indexOf(e)==t}).join(" ");i.writeFile("./testcharhhihiiktdata.csv",u,function(e){e?console.log(e):f.fulfill(n)})}};return r(a),f.promise})}throw r.info("Highchart disabled. Please enable highchart in .env to use functions. Make 'highchart=true'"),console.log("Highchart disabled. Please enable highchart in .env to use functions. Make 'highchart=true'"),new Error("Highchart disabled. Please enable highchart in .env to use functions. Make 'highchart=true'")},compareData:function(e,t){var n=protractor.promise.defer();return console.log("type of testdata "+typeof e),e=e.toString(),console.log("type of testdata "+typeof e),i.readFile(t,"utf8",function(t,o){if(t)throw t;for(var r=e.split("\n"),i=o.split("\n"),s=0,l=0,a=0;l<r.length&&a<i.length;){var c=r[l].toString().trim(),h=i[a].toString().trim();if(c.valueOf()!==h.valueOf()){var u=c.replace(/\.[0-9]\d*/g," "),g=h.replace(/\.[0-9]\d*/g," ");u=u.toString(),g=g.toString(),null==u||null==g||u.valueOf()!==g.valueOf()?(console.log("int_1 is "+u),console.log("int_2 is "+g),l++,a++):(s++,l++,a++)}else s++,l++,a++}var f=s/i.length;console.log("res is "+f),console.log("count is "+s),f>=.9?n.fulfill(!0):n.fulfill(!1)}),n.promise},getLegendsFromSVG:function(){r.info("get legends from section svg");var e=protractor.promise.defer();return this.waitForChartElement("svg g.highcharts-legend-item"),n.all(by.css("g.highcharts-legend-item")).then(function(t){var n=new Array;t.forEach(function(t,o){t.getText().then(function(t){n.push(t),e.fulfill(n)})})}),e.promise},getParallelAxiesOrder:function(){var e=protractor.promise.defer();r.info("get parallel axies order from left to right"),this.waitForChartElement(element.all("#chartSVG > g:nth-child(2) > g").get(1));var t=element.all(by.css("#chartSVG > g:nth-child(2) > g"));return t.count().then(function(n){console.log("axises length is"+n);var o=new Array,r=function(i,s){if(i<n-1)t.get(i).getAttribute("transform").then(function(e){console.log(" I am here");var t=new Array;e=e.toString(),console.log("translate is "+e);var n=e.indexOf("(");console.log("start is "+n);var s=e.indexOf(")");console.log("end is "+s);var l=e.substring(n+1,s),a=Number(l.split(",")[0]);console.log("x is "+a),element.all(by.css("#chartSVG > g:nth-child(2) > g #message")).get(i).getInnerHtml().then(function(e){var n=e.toString().replace(/<.*>/g,"");t.push(a),t.push(n),o.push(t),r(i+1)})});else{var l=o.sort(function(e,t){return e[0]-t[0]});e.fulfill(l)}};r(0)}),e.promise},verifyParellelTimerangecoverall:function(){var e=protractor.promise.defer();r.info("get parallel axies order from left to right"),this.waitForChartElement(element.all("#chartSVG > g:nth-child(2) > g").last()),element.all(by.css("#chartSVG > g:nth-child(2) > g"));var t=element(by.css("#chartSVG > g:nth-child(2) > g > rect.overlay"));return t.getAttribute("x").then(function(n){console.log("start "+n),element(by.css("#chartSVG > g:nth-child(2) > g > rect.selection")).getAttribute("x").then(function(o){n==o?t.getAttribute("width").then(function(t){console.log("end_position "+t),element(by.css("#chartSVG > g:nth-child(2) > g > rect.selection")).getAttribute("width").then(function(n){t==n&&e.fulfill(!1)})}):e.fulfill(!1)})}),e.promise},waitForChartElement:function(t){browser.wait(l.presenceOf(e.element(by.css(t))),6e4)}}}}();
\No newline at end of file