Best JavaScript code snippet using appium-xcuitest-driver
cerabox.js
Source:cerabox.js
...721 'width':width,722 'height':height,723 'opacity':1724 };725 if (window.getSize().x > this.vars.cerabox.getSize().x+40 && window.getSize().x > width+40) {726 this.vars.cerabox.setStyles({727 'left':((window.getSize().x/2)) + 'px',728 'right':'auto'729 });730 morphObject['margin-left'] = ((-width/2)+document.id(document.body).getScroll().x) + 'px';731 }732 else {733 this.vars.cerabox.setStyles({734 'margin-left':'0',735 'left':'auto',736 'right':'20px'737 });738 }739 if (window.getSize().y > this.vars.cerabox.getSize().y+40 && window.getSize().y > height+40) {740 this.vars.cerabox.setStyles({741 'top':((window.getSize().y/2)) + 'px'742 });743 morphObject['margin-top'] = ((-height/2)+document.id(document.body).getScroll().y) + 'px';744 }745 else {746 if (height+40 > (document.id(document.body).getScrollSize().y-document.id(document.body).getScroll().y)) {747 this.vars.cerabox.setStyles({748 'margin-top':'0',749 'top':(document.id(document.body).getScrollSize().y-(height+60)>20?document.id(document.body).getScrollSize().y-(height+60):20) + 'px'750 });751 }752 else {753 this.vars.cerabox.setStyles({754 'margin-top':'0',755 'top':document.id(document.body).getScroll().y + 20 + 'px'756 });757 }758 }759 return this.vars.cerabox.set('morph', {duration: 150})760 .morph(morphObject).get('morph');761 },762 763 /**764 * Initialize show function765 */766 _showInit: function() {767 //if (this.vars.busy)768 //return;769 770 // Make sure it doesnt time out when started a new request and prev loader is gone771 clearInterval(this.timeOuter);772 clearInterval(this.loaderTimer);773 document.id('cerabox-loading').setStyle('display', 'none');774 },775 776 /**777 * Open cerabox window778 * 779 * @param int width780 * @param int height781 * @param string[optional] animation 'ease'|'fade'782 * @param array[optional] index item783 */784 _openWindow: function(width, height, animation, index) {785 if (this.vars.cerabox.getElement('.cerabox-content iframe'))786 this.vars.cerabox.getElement('.cerabox-content iframe').setStyles({'width':width,'height':height});787 788 this.vars.currentIndex = index = index ? index : this.vars.currentIndex;789 var currentItem = this.vars.items[index[0]][index[1]];790 var ceraBox = this;791 if (this.vars.windowOpen==true) {792 this.vars.cerabox.getElement('.cerabox-content')793 .set('opacity',0)794 .set('tween', {duration: 200}).tween('opacity','1')795 .get('tween')796 .addEvent('complete', function(){797 this.removeEvents('complete');798 ceraBox.vars.busy = false;799 ceraBox._addNavButtons(index);800 // onChange event801 if (null!==ceraBox.options.events._onChange)802 ceraBox.options.events._onChange.call(ceraBox, currentItem, ceraBox.vars.items[index[0]]);803 else804 ceraBox.options.events.onChange.call(ceraBox, currentItem, ceraBox.vars.items[index[0]]);805 });806 return;807 }808 809 this.vars.cerabox.getElement('.cerabox-content').set('opacity','1');810 // onOpen event811 if (null!==this.options.events._onOpen)812 this.options.events._onOpen.call(this, currentItem, this.vars.items[index[0]]);813 else814 this.options.events.onOpen.call(this, currentItem, this.vars.items[index[0]]);815 // Holds the position to morph to816 var morphObject = {};817 if (window.getSize().x > width+40) {818 Object.append(morphObject, {819 'margin-left':(width>0?((-width/2)+document.id(document.body).getScroll().x):0) + 'px',820 'left':((window.getSize().x/2)) + 'px',821 'right':'auto'822 });823 }824 else {825 Object.append(morphObject, {826 'margin-left':'0',827 'left':((window.getSize().x - (width+20))+document.id(document.body).getScroll().x) + 'px',828 'right':'20px'829 });830 }831 if (window.getSize().y > height+40) {832 Object.append(morphObject, {833 'margin-top':(height>0?((-height/2)+document.id(document.body).getScroll().y):0) + 'px',834 'top':((window.getSize().y/2)) + 'px',835 'bottom':'auto'836 });837 }838 else {839 if (height+40 > (document.id(document.body).getScrollSize().y-document.id(document.body).getScroll().y)) {840 Object.append(morphObject, {841 'margin-top':'0',842 'top':(document.id(document.body).getScrollSize().y-(height+60)>20?document.id(document.body).getScrollSize().y-(height+60):20) + 'px'843 });844 }845 else {846 Object.append(morphObject, {847 'margin-top':'0',848 'top':document.id(document.body).getScroll().y + 20 + 'px'849 });850 }851 }852 switch (animation) {853 case 'ease':854 Object.append(morphObject, {855 'width':width,856 'height':height,857 'opacity':'1'858 });859 this.vars.cerabox.setStyles({860 'display':'block',861 'left':currentItem.getPosition().x + 'px',862 'top':currentItem.getPosition().y + 'px',863 'width':currentItem.getSize().x + 'px',864 'height':currentItem.getSize().y + 'px',865 'margin':0,866 'opacity':0867 }).set('morph', {duration: 200}).morph(morphObject).get('morph')868 .addEvent('complete', function(){869 this.removeEvents('complete');870 ceraBox.vars.busy = false;871 ceraBox._addNavButtons(index);872 // onChange event873 if (null!==ceraBox.options.events._onAnimationEnd)874 ceraBox.options.events._onAnimationEnd.call(ceraBox, currentItem, ceraBox.vars.items[index[0]]);875 else876 ceraBox.options.events.onAnimationEnd.call(ceraBox, currentItem, ceraBox.vars.items[index[0]]);877 });878 break;879 case 'fade':880 default:881 Object.append(morphObject, {882 'display':'block',883 'width':width,884 'height':height,885 'opacity':0886 });887 this.vars.cerabox.setStyles(morphObject).set('tween', {duration: 200}).tween('opacity', '1')888 .get('tween')889 .addEvent('complete', function(){890 this.removeEvents('complete');891 ceraBox.vars.busy = false;892 ceraBox._addNavButtons(index);893 // onChange event894 if (null!==ceraBox.options.events._onAnimationEnd)895 ceraBox.options.events._onAnimationEnd.call(ceraBox, currentItem, ceraBox.vars.items[index[0]]);896 else897 ceraBox.options.events.onAnimationEnd.call(ceraBox, currentItem, ceraBox.vars.items[index[0]]);898 });899 break;900 }901 currentItem.blur();902 this.vars.windowOpen = true;903 },904 905 /**906 * Display transparen overlay907 */908 _displayOverlay: function() {909 document.id('cerabox-background').setStyles({'display':'block','opacity':'.5','height':document.id(document.body).getScrollSize().y + 'px','width':document.id(document.body).getScrollSize().x + 'px'});910 },911 912 /**913 * Display loading spinner914 */915 _displayLoader: function(loaderAtItem, currentItem) {916 // loaderAtItem917 if (true===loaderAtItem && !this.vars.windowOpen)918 document.id('cerabox-loading').setStyles({919 'position': 'absolute',920 'top': (((currentItem.getSize().y/2) - (document.id('cerabox-loading').getStyle('height').toInt()/2)) + currentItem.getPosition().y) + 'px',921 'left': (((currentItem.getSize().x/2) - (document.id('cerabox-loading').getStyle('width').toInt()/2)) + currentItem.getPosition().x) + 'px',922 'margin-left': 0,923 'margin-top': 0924 });925 else926 document.id('cerabox-loading').set('style','');927 document.id('cerabox-loading').setStyle('display','block');928 this._loaderAnimation();929 },930 931 /**932 * Loader animation933 * 934 * @param int frame935 */936 _loaderAnimation: function(frame) {937 if (!frame)938 frame=0;939 document.id('cerabox-loading').getElement('div').setStyle('top', (frame * -40) + 'px');940 frame = (frame + 1) % 12;941 942 if (document.id('cerabox-loading').getStyle('display')!='none')943 this._loaderAnimation.delay(60, this, frame);944 },945 946 /**947 * Get size element object948 * 949 * @param object element950 * @return object951 */952 _getSizeElement: function(element, fullSize) {953 var eleWidth = 0, eleHeight = 0;954 955 if (element.tagName == 'IFRAME') {956 try {957 eleWidth = (element.get('width')?this._sizeStringToInt(element.get('width'),'x'):(element.getStyle('width').toInt()>1?this._sizeStringToInt(element.getStyle('width'),'x'):958 (element.contentWindow.document.getScrollWidth()?element.contentWindow.document.getScrollWidth():window.getSize().x * 0.75)));959 }960 catch(err) {961 eleWidth = window.getSize().x * 0.75;962 this._log(err); // IE6 fix963 }964 965 try {966 eleHeight = (element.get('height')?this._sizeStringToInt(element.get('height'),'y'):(element.getStyle('height').toInt()>1?this._sizeStringToInt(element.getStyle('height'),'y'):967 (element.contentWindow.document.getScrollHeight()?element.contentWindow.document.getScrollHeight():window.getSize().y * 0.75)));968 }969 catch(err) {970 eleHeight = window.getSize().y * 0.75;971 this._log(err); // IE6 fix972 }973 974 if (Browser.ie) {975 eleHeight = eleHeight + 20;976 }977 978 if (false===fullSize) { 979 if ((window.getSize().y - 100)<eleHeight) {980 eleWidth = eleWidth + (Browser.Platform.mac?15:17);981 }982 return {width: (window.getSize().x - 50)<eleWidth?(window.getSize().x - 50):eleWidth, height: (window.getSize().y - 100)<eleHeight?(window.getSize().y - 100):eleHeight};983 } else984 return {width: eleWidth, height: eleHeight}; 985 }986 987 eleWidth = (element.get('width')?this._sizeStringToInt(element.get('width'),'x'):(element.getStyle('width')&&element.getStyle('width')!='auto'?this._sizeStringToInt(element.getStyle('width'),'x'):window.getSize().x - 50));988 eleHeight = (element.get('height')?this._sizeStringToInt(element.get('height'),'y'):(element.getStyle('height')&&element.getStyle('height')!='auto'?this._sizeStringToInt(element.getStyle('height'),'y'):window.getSize().y - 100));989 990 if (false===fullSize) {991 var r = Math.min(Math.min(window.getSize().x - 50, eleWidth) / eleWidth, Math.min(window.getSize().y - 100, eleHeight) / eleHeight);992 return {width: Math.round(r * eleWidth), height: Math.round(r * eleHeight)};993 }994 else995 return {width: eleWidth, height: eleHeight};996 },997 998 /**999 * Get the pixels of given element size1000 * 1001 * @param string size1002 * @param string dimension 'x'|'y'1003 */1004 _sizeStringToInt: function(size, dimension) {1005 return (typeof size == 'string' && size.test('%')?window.getSize()[dimension]*(size.toInt()/100):size.toInt());1006 },1007 1008 /**1009 * Resizing window1010 */1011 _resize: function() {1012 if(this.vars.windowOpen==true) {1013 document.id('cerabox-background').setStyles({'height':window.getSize().y + 'px','width':window.getSize().x + 'px'});1014 if (window.getSize().x > this.vars.cerabox.getSize().x+40) {1015 this.vars.cerabox.setStyles({1016 'margin-left':(this.vars.cerabox.getSize().x>0?((-this.vars.cerabox.getSize().x/2)+document.id(document.body).getScroll().x):0) + 'px',1017 'left':((window.getSize().x/2)) + 'px',1018 'right':'auto'1019 });1020 }1021 else {1022 this.vars.cerabox.setStyles({1023 'margin-left':'0',1024 'left':'auto',1025 'right':'20px'1026 });1027 }1028 if (window.getSize().y > this.vars.cerabox.getSize().y+40) {1029 this.vars.cerabox.setStyles({1030 'margin-top':(this.vars.cerabox.getSize().y>0?((-this.vars.cerabox.getSize().y/2)+document.id(document.body).getScroll().y):0) + 'px',1031 'top':((window.getSize().y/2)) + 'px',1032 'bottom':'auto'1033 });1034 }1035 else {1036 if (this.vars.cerabox.getSize().y+40 > (document.id(document.body).getScrollSize().y-document.id(document.body).getScroll().y)) {1037 this.vars.cerabox.setStyles({1038 'margin-top':'0',1039 'top':(document.id(document.body).getScrollSize().y-(this.vars.cerabox.getSize().y+60)>20?document.id(document.body).getScrollSize().y-(this.vars.cerabox.getSize().y+60):20) + 'px'1040 });1041 }1042 else {1043 this.vars.cerabox.setStyles({1044 'margin-top':'0',1045 'top':document.id(document.body).getScroll().y + 20 + 'px'...
demo-virtual-desktop-init.js
Source:demo-virtual-desktop-init.js
...6 id:"admin_navigation_window",7 loadMethod: 'fullajax',8 contentURL: link.get("href"),9 title:link.get("html"),10 width: window.getSize().x*0.7,11 height: window.getSize().y*0.712 });13 }14 if ($('admin_navigation_link')){15 $('admin_navigation_link').addEvent('click', function(e){16 new Event(e).stop();17 MochaUI.navigationWindow($('admin_navigation_link'));18 });19 }2021 MochaUI.templatesWindow=function(link){22 new MochaUI.Window({23 id:"admin_templates_window",24 loadMethod: 'fullajax',25 contentURL: link.get("href"),26 title:link.get("html"),27 width: window.getSize().x*0.7,28 height: window.getSize().y*0.729 });30 }31 if ($('admin_templates_link')){32 $('admin_templates_link').addEvent('click', function(e){33 new Event(e).stop();34 MochaUI.templatesWindow($('admin_templates_link'));35 });36 }3738 MochaUI.pagepartsWindow=function(link){39 new MochaUI.Window({40 id:"admin_pageparts_window",41 loadMethod: 'fullajax',42 contentURL: link.get("href"),43 title:link.get("html"),44 width: window.getSize().x*0.7,45 height: window.getSize().y*0.746 });47 }48 if ($('admin_pageparts_link')){49 $('admin_pageparts_link').addEvent('click', function(e){50 new Event(e).stop();51 MochaUI.pagepartsWindow($('admin_pageparts_link'));52 });53 }5455 MochaUI.htmlWindow=function(link){56 new MochaUI.Window({57 id:"admin_html_window",58 loadMethod: 'fullajax',59 contentURL: link.get("href"),60 title:link.get("html"),61 width: window.getSize().x*0.7,62 height: window.getSize().y*0.763 });64 }65 if ($('admin_html_link')){66 $('admin_html_link').addEvent('click', function(e){67 new Event(e).stop();68 MochaUI.htmlWindow($('admin_html_link'));69 });70 }7172 MochaUI.newsWindow=function(link){73 new MochaUI.Window({74 id:"admin_news_window",75 loadMethod: 'fullajax',76 contentURL: link.get("href"),77 title:link.get("html"),78 width: window.getSize().x*0.7,79 height: window.getSize().y*0.780 });81 }82 if ($('admin_news_link')){83 $('admin_news_link').addEvent('click', function(e){84 new Event(e).stop();85 MochaUI.newsWindow($('admin_news_link'));86 });87 }8889 MochaUI.htmlrotateWindow=function(link){90 new MochaUI.Window({91 id:"admin_htmlrotate_window",92 loadMethod: 'fullajax',93 contentURL: link.get("href"),94 title:link.get("html"),95 width: window.getSize().x*0.7,96 height: window.getSize().y*0.797 });98 }99 if ($('admin_htmlrotate_link')){100 $('admin_htmlrotate_link').addEvent('click', function(e){101 new Event(e).stop();102 MochaUI.htmlrotateWindow($('admin_htmlrotate_link'));103 });104 }105106 //orders107 MochaUI.ordersWindow=function(link){108 new MochaUI.Window({109 id:"admin_orders_window",110 loadMethod: 'fullajax',111 contentURL: link.get("href"),112 title:link.get("html"),113 width: window.getSize().x*0.7,114 height: window.getSize().y*0.7115 });116 }117 if ($('admin_orders_link')){118 $('admin_orders_link').addEvent('click', function(e){119 new Event(e).stop();120 MochaUI.ordersWindow($('admin_orders_link'));121 });122 }123}124125FCK_fix=function(){126 if (FCKeditorAPI){127 for (fckeditorName in FCKeditorAPI.__Instances){128 var _fck_nst=FCKeditorAPI.GetInstance(fckeditorName);
...
sketchalert.js
Source:sketchalert.js
...104 }105 this.mask.show();106 this.mask.position();107 var alert_bg = new Element("div",{'class':'alert-mask'});108 $(this.mask).setStyles({width:window.getSize().x,top:0,left:0,height:window.getSize().y,"position":"fixed",'z-index':99999});109 $(alert_bg).inject($(this.mask));110 $(alert_bg).setStyles({width:window.getSize().x,top:0,left:0,height:window.getSize().y,'opacity':0.6});111 $(this.elm).inject($(this.mask));112 if($(this.elm).getElement(".alert-close")){113 $(this.elm).getElement(".alert-close").addEvent("click",this.hide.bind(this));114 }115 this.canHide = false;116 if(this.options.isLoading==true){117 $(this.elm).setStyles({'visibility':'visible','top':50,'left':($(window).getSize().x/2) - ($(this.elm).getSize().x/2)});118 $(this.elm).morph({opacity:1,"margin-top":[-50,0]});119 }else{120 $(this.elm).setStyles({'visibility':'visible','top':50,'left':($(window).getSize().x/2) - ($(this.elm).getSize().x/2)});121 $(this.elm).morph({opacity:1,"margin-top":[-50,0]});122 }123 this.timer = this.hide.bind(this).delay(this.options.timed);124 }...
preload.js
Source:preload.js
1global.layarequire = require;2global.require = null;3delete global.require;4var electron = require("electron");5const remote = electron.remote;6const Menu = remote.Menu;7const MenuItem = remote.MenuItem;8const ipcRenderer = electron.ipcRenderer;9var fs = require("fs");10var path = require("path");11global.layaideconfig = null;12var debugconfigdata;13try {14 var data = localStorage.getItem("debugconfigdata");15 if (data) {16 debugconfigdata = JSON.parse(data);17 } else {18 debugconfigdata = {19 "width": 320,20 "height": 480,21 "direction": 022 };23 }24} catch (e) {25 // statements26 debugconfigdata = {27 "width": 320,28 "height": 480,29 "direction": 030 };31}32document.addEventListener("keydown", function(oEvent) {33 if (oEvent.code == "F5") {34 remote.getCurrentWindow().reload();35 } else if (oEvent.code == "F12") {36 remote.getCurrentWindow().openDevTools();37 }38})39window.addEventListener("resize", function(e) {40 /* body... */41 try {42 // statements43 debugconfigdata.width = remote.getCurrentWindow().getSize()[0];44 debugconfigdata.height = remote.getCurrentWindow().getSize()[1];45 localStorage.setItem("debugconfigdata", JSON.stringify(debugconfigdata));46 } catch (e) {47 // statements48 }49})50window.addEventListener("error", function(event) {51 console.error(event.error.stack);52})53 // process.noAsar = true;54initMenu();55function initMenu() {56 remote.getCurrentWindow().setSize(debugconfigdata.width, debugconfigdata.height);57 remote.getCurrentWindow().show()58 var template = [{59 label: 'è§å¾',60 submenu: [{61 label: 'éæ°å è½½(F5)',62 click: function(item, focusedWindow) {63 remote.getCurrentWindow().reload();64 }65 }, {66 label: 'æå¼å¼åè
å·¥å
·(F12)',67 accelerator: (function() {68 return 'F12';69 })(),70 click: function(item, focusedWindow) {71 ipcRenderer.sendSync("opendev", "opendev"); //åæ¥æ¶æ¯çæ¹å¼72 remote.getCurrentWindow().webContents.toggleDevTools();73 //remote.getCurrentWindow().emit("opendev");74 }75 }, ]76 }, {77 label: 'å辨ç',78 submenu: [{79 label: 'Apple iPhone4',80 checked: false,81 type: "radio",82 click: function() {83 update_debug_w_h(320, 480);84 }85 }, {86 label: 'Apple iPhone5',87 checked: false,88 type: "radio",89 click: function() {90 update_debug_w_h(320, 568);91 }92 }, {93 label: 'Apple iPhone6',94 checked: false,95 type: "radio",96 click: function() {97 update_debug_w_h(375, 627);98 }99 }, {100 label: 'Apple iPhone6 Plus',101 checked: false,102 type: "radio",103 click: function() {104 update_debug_w_h(414, 763);105 }106 }, {107 label: 'Apple iPad',108 checked: false,109 type: "radio",110 click: function() {111 update_debug_w_h(768, 1024);112 }113 }]114 }, {115 label: 'å±å¹æ¹å',116 submenu: [{117 label: '横å±',118 checked: debugconfigdata.direction,119 type: "radio",120 click: function() {121 debugconfigdata.direction = 0;122 if (remote.getCurrentWindow().getSize()[0] > remote.getCurrentWindow().getSize()[1]) {123 } else {124 remote.getCurrentWindow().setSize(remote.getCurrentWindow().getSize()[1], remote.getCurrentWindow().getSize()[0])125 //update_debug_w_h(remote.getCurrentWindow().getSize()[1], remote.getCurrentWindow().getSize()[0]);126 }127 //update_debug_w_h(remote.getCurrentWindow().getSize()[0], remote.getCurrentWindow().getSize()[1]);128 }129 }, {130 label: 'ç«å±',131 checked: !debugconfigdata.direction,132 type: "radio",133 click: function() {134 debugconfigdata.direction = 1;135 if (remote.getCurrentWindow().getSize()[0] > remote.getCurrentWindow().getSize()[1]) {136 update_debug_w_h(remote.getCurrentWindow().getSize()[1], remote.getCurrentWindow().getSize()[0]);137 } else {138 //remote.getCurrentWindow().setSize(remote.getCurrentWindow().getSize()[1], remote.getCurrentWindow().getSize()[0])139 }140 //update_debug_w_h(remote.getCurrentWindow().getSize()[0], remote.getCurrentWindow().getSize()[1]);141 }142 }, ]143 }, {144 label: '帮å©',145 role: 'help',146 submenu: [{147 label: 'é®ç社åº',148 click: function() {149 require('electron').shell.openExternal("http://ask.layabox.com/question")150 }151 }, ]152 }, ];153 var menu = Menu.buildFromTemplate(template);154 Menu.setApplicationMenu(menu);155}156function update_debug_w_h(w = 320, h = 560) {157 if (debugconfigdata.direction) {158 remote.getCurrentWindow().setSize(w, h);159 } else {160 remote.getCurrentWindow().setSize(h, w);161 }162 debugconfigdata.width = w;163 debugconfigdata.height = h;164 // body... ...
index.js
Source:index.js
1const {app, BrowserWindow, Tray, process, Menu, globalShortcut, shell} = require('electron');2let mainWindow, tray;3app.on('ready', () => {4 const screen = require('electron').screen;5 mainWindow = new BrowserWindow({6 height: 480,7 width: 275,8 frame: false,9 resizable: false,10 transparent: true11 });12 mainWindow.loadURL('file://' + __dirname + '/index.html');13 // Hide window in taskbar14 mainWindow.setSkipTaskbar(true);15 mainWindow.setAlwaysOnTop(true);16 globalShortcut.register('CommandOrControl+`', () => {17 if (mainWindow.isVisible()) {18 mainWindow.hide();19 } else {20 mainWindow.show();21 var display = screen.getPrimaryDisplay();22 // Position at top-right23 mainWindow.setPosition(display.bounds.width - mainWindow.getSize()[0], 0);24 mainWindow.setAlwaysOnTop(true);25 }26 });27 tray = new Tray(__dirname + '/tray.png');28 tray.setToolTip('Twitch overlay activated. Press Ctrl + ` to show.');29 const trayContextMenu = Menu.buildFromTemplate([30 {label: `TwitchOverlay v${app.getVersion()}`, enabled: false},31 {type: "separator"},32 {label: "Website", click: () => {shell.openExternal('https://overlay.twitchbot.io')}},33 {label: "Source code", click: () => {shell.openExternal('https://github.com/devakira/twitchoverlay')}},34 {type: "separator"},35 {label: "Toggle Chat", click: () => {36 mainWindow.webContents.executeJavaScript(`renderer.toggleChat()`);37 }},38 {label: "Settings", click: () => {mainWindow.loadURL('file://' + __dirname + '/settings.html');}},39 {type: "separator"},40 {label: "Quit Application", role: "quit"}41 ]);42 tray.setContextMenu(trayContextMenu);43 const trayBounds = tray.getBounds();44 var display = screen.getPrimaryDisplay();45 // Position at top-right46 mainWindow.setPosition(display.bounds.width - mainWindow.getSize()[0], 0);47 tray.on('click', () => {48 mainWindow.show();49 var display = screen.getPrimaryDisplay();50 // Position at top-right51 mainWindow.setPosition(display.bounds.width - mainWindow.getSize()[0], 0);52 mainWindow.setAlwaysOnTop(true);53 });54 mainWindow.on('blur', () => {55 mainWindow.setAlwaysOnTop(true);56 });57 mainWindow.on('closed', () => {58 app.quit();59 });60 mainWindow.on('resize', () => {61 var display = screen.getPrimaryDisplay();62 // Position at top-right63 mainWindow.setPosition(display.bounds.width - mainWindow.getSize()[0], 0);64 mainWindow.setAlwaysOnTop(true);65 });66 mainWindow.on('enter-html-full-screen', () => {67 mainWindow.setPosition(0, 0);68 });69 mainWindow.on('leave-html-full-screen', () => {70 var display = screen.getPrimaryDisplay();71 // Position at top-right72 mainWindow.setPosition(display.bounds.width - mainWindow.getSize()[0], 0);73 });74 mainWindow.webContents.on('new-window', function(event, url){75 event.preventDefault();76 shell.openExternal(url);77 });78});79app.on("window-all-closed", () => {80 if (process.platform !== "darwin") {81 app.quit();82 }...
manager.js
Source:manager.js
1/**2 * External dependencies3 */4import chai from 'chai';5import chaiAsPromised from 'chai-as-promised';6import { By, WebDriver } from 'selenium-webdriver';7import test from 'selenium-webdriver/testing';8/**9 * Internal dependencies10 */11import { WebDriverHelper as helper } from '../src/index';12chai.use( chaiAsPromised );13const assert = chai.assert;14const expect = chai.expect;15const mochaTimeout = 30000;16let manager;17let driver;18test.describe( 'WebDriverManager', function() {19 this.timeout( mochaTimeout );20 // Set baseUrl and try getPageUrl21 test.before( function() {22 manager = global.__MANAGER__;23 driver = global.__DRIVER__;24 manager.config.baseUrl = 'https://wp-e2e-test-form-page.herokuapp.com';25 driver.get( manager.getPageUrl( '/page-path/' ) );26 helper.waitTillPresentAndDisplayed(27 driver,28 By.css( 'body' )29 );30 } );31 test.it( 'creates instance of WebDriver', () => {32 assert( driver instanceof WebDriver );33 } );34 test.it( 'has https://wp-e2e-test-form-page.herokuapp.com/ as the default base URL', () => {35 assert( 'https://wp-e2e-test-form-page.herokuapp.com' === manager.getBaseUrl() );36 } );37 test.it( 'can returns full url via manager.getPageUrl', () => {38 assert( 'https://wp-e2e-test-form-page.herokuapp.com/page-path/', manager.getPageUrl( '/page-path/' ) );39 } );40 test.it( 'has desktop as default screen size config', () => {41 assert( 'desktop' === manager.getConfigScreenSize() );42 } );43 test.it( 'uses desktop screen size by default', () => {44 return expect( driver.manage().window().getSize() ).45 to.eventually.deep.equal( manager.getScreenSizeAsObject( 'desktop' ) );46 } );47 test.describe( 'Resize browser by device type', () => {48 test.it( 'can resize browser to mobile size', () => {49 manager.resizeBrowser( 'mobile' );50 return expect( driver.manage().window().getSize() ).51 to.eventually.deep.equal( manager.getScreenSizeAsObject( 'mobile' ) );52 } );53 test.it( 'can resize browser to tablet size', () => {54 manager.resizeBrowser( 'tablet' );55 return expect( driver.manage().window().getSize() ).56 to.eventually.deep.equal( manager.getScreenSizeAsObject( 'tablet' ) );57 } );58 test.it( 'can resize browser to desktop size', () => {59 manager.resizeBrowser( 'desktop' );60 return expect( driver.manage().window().getSize() ).61 to.eventually.deep.equal( manager.getScreenSizeAsObject( 'desktop' ) );62 } );63 test.it( 'can resize browser to laptop size', () => {64 manager.resizeBrowser( 'laptop' );65 return expect( driver.manage().window().getSize() ).66 to.eventually.deep.equal( manager.getScreenSizeAsObject( 'laptop' ) );67 } );68 } );69 test.it( 'just visited https://wp-e2e-test-form-page.herokuapp.com/page-path/', () => {70 return assert.eventually.equal(71 driver.getCurrentUrl(),72 'https://wp-e2e-test-form-page.herokuapp.com/page-path/'73 );74 } );...
main.js
Source:main.js
1const electron = require('electron')2 // Module to control application life.3const {4 app,5 globalShortcut6} = require('electron')7// Module to create native browser window.8const BrowserWindow = electron.BrowserWindow9// Keep a global reference of the window object, if you don't, the window will10// be closed automatically when the JavaScript object is garbage collected.11let mainWindow12function createWindow() {13 // Create the browser window.14 //BrowserWindow.addDevToolsExtension('./ext/uBlock0.chromium');15 mainWindow = new BrowserWindow({16 width: 1097,17 height: 550,18 frame: false,19 title: "SoundCloudGo",20 menu: null,21 icon: __dirname + '/images/old.png',22 webPreferences: {23 plugins: true,24 webSecurity: false,25 allowDisplayingInsecureContent: true,26 experimentalFeatures: true27 }28 })29 // make thumbnail30 mainWindow.setThumbnailClip({ x: 0, y: mainWindow.getSize()[1] - 46, width: mainWindow.getSize()[0], height: 46 })31 //set progress32 //mainWindow.setProgressBar(0.5)33 // and load the index.html of the app.34 mainWindow.loadURL(`file://${__dirname}/index.html`)35 // Open the DevTools.36 mainWindow.webContents.openDevTools()37 // Emitted when the window is closed.38 mainWindow.on('closed', function() {39 // Dereference the window object, usually you would store windows40 // in an array if your app supports multi windows, this is the time41 // when you should delete the corresponding element.42 mainWindow = null43 })44 // emitted when the window is resized45 mainWindow.on("resize", function() {46 mainWindow.setThumbnailClip({ x: 0, y: mainWindow.getSize()[1] - 46, width: mainWindow.getSize()[0], height: 46 })47 })48}49// This method will be called when Electron has finished50// initialization and is ready to create browser windows.51// Some APIs can only be used after this event occurs.52app.on('ready', createWindow)53// Quit when all windows are closed.54app.on('window-all-closed', function() {55 // On OS X it is common for applications and their menu bar56 // to stay active until the user quits explicitly with Cmd + Q57 if (process.platform !== 'darwin') {58 app.quit()59 }60})61app.on('activate', function() {62 // On OS X it's common to re-create a window in the app when the63 // dock icon is clicked and there are no other windows open.64 if (mainWindow === null) {65 createWindow()66 }67})68// In this file you can include the rest of your app's specific main process...
cell.js
Source:cell.js
1( function( window, factory ) {2 'use strict';3 // universal module definition4 if ( typeof define == 'function' && define.amd ) {5 // AMD6 define( [7 'get-size/get-size'8 ], function( getSize ) {9 return factory( window, getSize );10 });11 } else if ( typeof exports == 'object' ) {12 // CommonJS13 module.exports = factory(14 window,15 require('get-size')16 );17 } else {18 // browser global19 window.Flickity = window.Flickity || {};20 window.Flickity.Cell = factory(21 window,22 window.getSize23 );24 }25}( window, function factory( window, getSize ) {26'use strict';27function Cell( elem, parent ) {28 this.element = elem;29 this.parent = parent;30 this.create();31}32var isIE8 = 'attachEvent' in window;33Cell.prototype.create = function() {34 this.element.style.position = 'absolute';35 // IE8 prevent child from changing focus http://stackoverflow.com/a/17525223/18218336 if ( isIE8 ) {37 this.element.setAttribute( 'unselectable', 'on' );38 }39 this.x = 0;40 this.shift = 0;41};42Cell.prototype.destroy = function() {43 // reset style44 this.element.style.position = '';45 var side = this.parent.originSide;46 this.element.style[ side ] = '';47};48Cell.prototype.getSize = function() {49 this.size = getSize( this.element );50};51Cell.prototype.setPosition = function( x ) {52 this.x = x;53 this.setDefaultTarget();54 this.renderPosition( x );55};56Cell.prototype.setDefaultTarget = function() {57 var marginProperty = this.parent.originSide == 'left' ? 'marginLeft' : 'marginRight';58 this.target = this.x + this.size[ marginProperty ] +59 this.size.width * this.parent.cellAlign;60};61Cell.prototype.renderPosition = function( x ) {62 // render position of cell with in slider63 var side = this.parent.originSide;64 this.element.style[ side ] = this.parent.getPositionValue( x );65};66/**67 * @param {Integer} factor - 0, 1, or -168**/69Cell.prototype.wrapShift = function( shift ) {70 this.shift = shift;71 this.renderPosition( this.x + this.parent.slideableWidth * shift );72};73Cell.prototype.remove = function() {74 this.element.parentNode.removeChild( this.element );75};76return Cell;...
Using AI Code Generation
1var wd = require('wd');2var chai = require('chai');3var chaiAsPromised = require('chai-as-promised');4chai.use(chaiAsPromised);5var expect = chai.expect;6var should = chai.should();7var assert = chai.assert;8var desiredCaps = {9};10var driver = wd.promiseChainRemote('localhost', 4723);11driver.init(desiredCaps);12driver.getWindowSize().then(function (size) {13 console.log("Window size is " + size.width + " x " + size.height);14});15driver.quit();
Using AI Code Generation
1const wdio = require('webdriverio');2const opts = {3 capabilities: {4 },5};6async function getSize() {7 const client = await wdio.remote(opts);8 const size = await client.getWindowSize();9 console.log(size);10}11getSize();12{ width: 375, height: 667 }
Using AI Code Generation
1const wd = require('wd');2const chai = require('chai');3const chaiAsPromised = require('chai-as-promised');4const { exec } = require('child_process');5chai.use(chaiAsPromised);6chai.should();7const PORT = 4723;
Using AI Code Generation
1const wdio = require("webdriverio");2const opts = {3 capabilities: {4 },5};6const client = wdio.remote(opts);7async function main() {8 await client.init();9 const windowSize = await client.getWindowSize();10 console.log(windowSize);11 await client.deleteSession();12}13main();14from appium import webdriver15desired_caps = {16}17window_size = driver.get_window_size()18print(window_size)19driver.quit()20from appium import webdriver21desired_caps = {22}23window_size = driver.get_window_size()24print(window_size)25driver.quit()26const wdio = require("webdriverio");27const opts = {28 capabilities: {29 },30};31const client = wdio.remote(opts);32async function main() {33 await client.init();34 const windowSize = await client.getWindowSize();35 console.log(windowSize);36 await client.deleteSession();37}38main();39import io.appium.java_client.AppiumDriver;40import io.appium.java_client.MobileElement;
Using AI Code Generation
1var size = driver.getWindowSize();2console.log(size);3driver.setWindowSize(375, 667);4driver.maximizeWindow();5var position = driver.getWindowPosition();6console.log(position);7driver.setWindowPosition(0, 0);8driver.fullScreenWindow();9driver.closeWindow();10driver.switchToWindow('NATIVE_APP');11var handles = driver.getAllWindowHandles();12console.log(handles);13var handle = driver.getWindowHandle();14console.log(handle);15var orientation = driver.getOrientation();16console.log(orientation);17driver.setOrientation('LANDSCAPE');18var rotation = driver.getRotation();19console.log(rotation);20driver.setRotation(90);21var rect = driver.getWindowRect();22console.log(rect);23driver.setWindowRect(0, 0, 375, 667);24var rect = driver.getViewportRect();25console.log(rect);26var rect = driver.getWindowRect();27console.log(rect);28driver.setWindowRect(0, 0, 375, 667);
Using AI Code Generation
1const wdio = require("webdriverio");2const assert = require("assert");3const opts = {4 capabilities: {5 }6};7async function main() {8 const client = await wdio.remote(opts);9 const windowSize = await client.getWindowSize();10 console.log(windowSize);11 assert.strictEqual(windowSize.width, 414);12 assert.strictEqual(windowSize.height, 896);13 await client.deleteSession();14}15main();16[0-0] 2020-03-26T11:57:30.385Z INFO webdriver: DATA { capabilities: { alwaysMatch: { platformName: 'iOS', platformVersion: '13.3', deviceName: 'iPhone 11 Pro Max', app: '/Users/username/Library/Developer/Xcode/DerivedData/WebDriverAgent-brdadhpuduowllgivnnvuygpwhzy/Build/Products/Debug-iphonesimulator/IntegrationApp.app', automationName: 'XCUITest', browserName: 'safari' }, firstMatch: [ {} ] }, desiredCapabilities: { platformName: 'iOS', platformVersion: '13.3', deviceName: 'iPhone 11 Pro Max', app: '/Users/username/Library/Developer/Xcode/DerivedData/WebDriverAgent-brdadhpuduowllgivnnvuygpwhzy/Build/Products/Debug-iphonesimulator/IntegrationApp.app', automationName: 'XCUITest', browserName: 'safari' } }
Using AI Code Generation
1const {Builder, By, Key, until} = require('selenium-webdriver');2const {attach} = require('appium-selenium-driver');3const XCUITestDriver = require('appium-xcuitest-driver');4const desiredCaps = {5};6const driver = new Builder()7 .forBrowser('XCUITest')8 .build();9attach(driver, XCUITestDriver, desiredCaps);10driver.windowHandle().then((window) => {11 console.log(window);12 driver.window(window).getSize().then((size) => {13 console.log(size);14 });15});16driver.quit();17driver.windowHandle().then((window) => {18 console.log(window);19 driver.window(window).getSize().then((size) => {20 console.log(size);21 });22});23driver.windowHandle().then((window) => {24 console.log(window);25 driver.window(window).getSize().then((size) => {26 console.log(size);27 });28});29driver.executeScript('mobile: getDeviceScreenSize', {}).then((size) => {30 console.log(size);31});
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!