How to use initialiseInstance method in Webdriverio

Best JavaScript code snippet using webdriverio-monorepo

runner.js

Source:runner.js Github

copy

Full Screen

...36 capabilities = this.configParser.getCapabilities(m.cid);37 this.addCommandHooks(config);38 this.initialiseServices(config);39 this.framework = this.initialiseFramework(config);40 global.browser = this.initialiseInstance(m.isMultiremote, capabilities);41 this.initialisePlugins(config);42 /**43 * store end method before it gets fiberised by wdio-sync44 */45 this.endSession = global.browser.end.bind(global.browser);46 /**47 * initialisation successful, send start message48 */49 process.send({50 event: 'runner:start',51 cid: m.cid,52 specs: m.specs,53 capabilities: capabilities,54 config: config55 });56 /**57 * register runner events58 */59 global.browser.on('init', function (payload) {60 process.send({61 event: 'runner:init',62 cid: m.cid,63 specs: _this.specs,64 sessionID: payload.sessionID,65 options: payload.options,66 desiredCapabilities: payload.desiredCapabilities67 });68 _this.hasSessionID = true;69 });70 global.browser.on('command', function (payload) {71 var command = {72 event: 'runner:command',73 cid: m.cid,74 specs: _this.specs,75 method: payload.method,76 uri: payload.uri,77 data: payload.data78 };79 process.send(_this.addTestDetails(command));80 });81 global.browser.on('result', function (payload) {82 var result = {83 event: 'runner:result',84 cid: m.cid,85 specs: _this.specs,86 requestData: payload.requestData,87 requestOptions: payload.requestOptions,88 body: payload.body // ToDo figure out if this slows down the execution time89 };90 process.send(_this.addTestDetails(result));91 });92 global.browser.on('screenshot', function (payload) {93 var details = {94 event: 'runner:screenshot',95 cid: m.cid,96 specs: _this.specs,97 filename: payload.filename,98 data: payload.data99 };100 process.send(_this.addTestDetails(details));101 });102 global.browser.on('log', function () {103 for (var _len = arguments.length, data = Array(_len), _key = 0; _key < _len; _key++) {104 data[_key] = arguments[_key];105 }106 var details = {107 event: 'runner:log',108 cid: m.cid,109 specs: _this.specs,110 data: data111 };112 process.send(_this.addTestDetails(details));113 });114 process.on('test:start', function (test) {115 _this.currentTest = test;116 });117 global.browser.on('error', function (payload) {118 process.send({119 event: 'runner:error',120 cid: m.cid,121 specs: _this.specs,122 error: payload,123 capabilities: capabilities124 });125 });126 this.haltSIGINT = true;127 context$2$0.prev = 23;128 context$2$0.next = 26;129 return _regeneratorRuntime.awrap(global.browser.init());130 case 26:131 res = context$2$0.sent;132 global.browser.sessionId = res.sessionId;133 this.haltSIGINT = false;134 /**135 * make sure init and end can't get called again136 */137 global.browser.options.isWDIO = true;138 /**139 * kill session of SIGINT signal showed up while trying to140 * get a session ID141 */142 if (!this.sigintWasCalled) {143 context$2$0.next = 33;144 break;145 }146 context$2$0.next = 33;147 return _regeneratorRuntime.awrap(this.end(1));148 case 33:149 context$2$0.next = 35;150 return _regeneratorRuntime.awrap(this.framework.run(m.cid, config, m.specs, capabilities));151 case 35:152 this.failures = context$2$0.sent;153 context$2$0.next = 38;154 return _regeneratorRuntime.awrap(this.end(this.failures));155 case 38:156 context$2$0.next = 45;157 break;158 case 40:159 context$2$0.prev = 40;160 context$2$0.t0 = context$2$0['catch'](23);161 process.send({162 event: 'error',163 cid: this.cid,164 specs: this.specs,165 capabilities: capabilities,166 error: {167 message: context$2$0.t0.message,168 stack: context$2$0.t0.stack169 }170 });171 context$2$0.next = 45;172 return _regeneratorRuntime.awrap(this.end(1));173 case 45:174 case 'end':175 return context$2$0.stop();176 }177 }, null, this, [[23, 40]]);178 }179 /**180 * end test runner instance and exit process181 */182 }, {183 key: 'end',184 value: function end() {185 var failures = arguments.length <= 0 || arguments[0] === undefined ? 0 : arguments[0];186 return _regeneratorRuntime.async(function end$(context$2$0) {187 while (1) switch (context$2$0.prev = context$2$0.next) {188 case 0:189 if (!this.hasSessionID) {190 context$2$0.next = 4;191 break;192 }193 global.browser.options.isWDIO = false;194 context$2$0.next = 4;195 return _regeneratorRuntime.awrap(this.endSession());196 case 4:197 process.send({198 event: 'runner:end',199 failures: failures,200 cid: this.cid,201 specs: this.specs202 });203 process.exit(failures === 0 ? 0 : 1);204 case 6:205 case 'end':206 return context$2$0.stop();207 }208 }, null, this);209 }210 }, {211 key: 'addTestDetails',212 value: function addTestDetails(payload) {213 if (this.currentTest) {214 payload.title = this.currentTest.title;215 payload.parent = this.currentTest.parent;216 }217 return payload;218 }219 }, {220 key: 'addCommandHooks',221 value: function addCommandHooks(config) {222 var _this2 = this;223 config.beforeCommand.push(function (command, args) {224 var payload = {225 event: 'runner:beforecommand',226 cid: _this2.cid,227 specs: _this2.specs,228 command: command,229 args: args230 };231 process.send(_this2.addTestDetails(payload));232 });233 config.afterCommand.push(function (command, args, result, err) {234 var payload = {235 event: 'runner:aftercommand',236 cid: _this2.cid,237 specs: _this2.specs,238 command: command,239 args: args,240 result: result,241 err: err242 };243 process.send(_this2.addTestDetails(payload));244 });245 }246 }, {247 key: 'sigintHandler',248 value: function sigintHandler() {249 if (this.sigintWasCalled) {250 return;251 }252 this.sigintWasCalled = true;253 if (this.haltSIGINT) {254 return;255 }256 global.browser.removeAllListeners();257 this.end(1);258 }259 }, {260 key: 'initialiseFramework',261 value: function initialiseFramework(config) {262 if (typeof config.framework !== 'string') {263 throw new Error('You haven\'t defined a valid framework. ' + 'Please checkout http://webdriver.io/guide/testrunner/frameworks.html');264 }265 var frameworkLibrary = 'wdio-' + config.framework.toLowerCase() + '-framework';266 try {267 return require(frameworkLibrary).adapterFactory;268 } catch (e) {269 if (!e.message.match('Cannot find module \'' + frameworkLibrary + '\'')) {270 throw new Error('Couldn\'t initialise framework "' + frameworkLibrary + '".\n' + e.stack);271 }272 throw new Error('Couldn\'t load "' + frameworkLibrary + '" framework. You need to install ' + ('it with `$ npm install ' + frameworkLibrary + '`!\n' + e.stack));273 }274 }275 }, {276 key: 'initialiseInstance',277 value: function initialiseInstance(isMultiremote, capabilities) {278 var config = this.configParser.getConfig();279 if (!isMultiremote) {280 config.desiredCapabilities = capabilities;281 return (0, _.remote)(config);282 }283 var options = {};284 var _iteratorNormalCompletion = true;285 var _didIteratorError = false;286 var _iteratorError = undefined;287 try {288 for (var _iterator = _getIterator(_Object$keys(capabilities)), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {289 var browserName = _step.value;290 options[browserName] = (0, _deepmerge2['default'])(config, capabilities[browserName]);291 options[browserName].desiredCapabilities = capabilities[browserName];...

Full Screen

Full Screen

index.js

Source:index.js Github

copy

Full Screen

...134 */135 async _initSession (config, caps) {136 let browser = null137 try {138 browser = global.browser = global.driver = await initialiseInstance(config, caps, this.isMultiremote)139 } catch (e) {140 log.error(e)141 this.emit('error', e)142 return browser143 }144 browser.config = config145 /**146 * register global helper method to fetch elements147 */148 global.$ = (selector) => browser.$(selector)149 global.$$ = (selector) => browser.$$(selector)150 /**151 * register command event152 */153 // console.log(this)154 browser.on('command', (command) => this.reporter.emit(155 'client:beforeCommand',156 Object.assign(command, { sessionId: browser.sessionId })157 ))158 /**159 * register result event160 */161 browser.on('result', (result) => this.reporter.emit(162 'client:afterCommand',163 Object.assign(result, { sessionId: browser.sessionId })164 ))165 return browser166 }167 /**168 * fetch logs provided by browser driver169 */170 async _fetchDriverLogs (config, excludeDriverLogs) {171 /**172 * only fetch logs if173 */174 if (175 /**176 * a log directory is given in config177 */178 !config.outputDir ||179 /**180 * the session wasn't killed during start up phase181 */182 !global.browser.sessionId ||183 /**184 * driver supports it185 */186 typeof global.browser.getLogs === 'undefined'187 ) {188 return189 }190 let logTypes191 try {192 logTypes = await global.browser.getLogTypes()193 } catch (errIgnored) {194 /**195 * getLogTypes is not supported by browser196 */197 return198 }199 logTypes = filterLogTypes(excludeDriverLogs, logTypes)200 log.debug(`Fetching logs for ${logTypes.join(', ')}`)201 return Promise.all(logTypes.map(async (logType) => {202 let logs203 try {204 logs = await global.browser.getLogs(logType)205 } catch (e) {206 return log.warn(`Couldn't fetch logs for ${logType}: ${e.message}`)207 }208 /**209 * don't write to file if no logs were captured210 */211 if (logs.length === 0) {212 return213 }214 const stringLogs = logs.map((log) => JSON.stringify(log)).join('\n')215 return util.promisify(fs.writeFile)(216 path.join(config.outputDir, `wdio-${this.cid}-${logType}.log`),217 stringLogs,218 'utf-8'219 )220 }))221 }222 /**223 * kill worker session224 */225 async _shutdown (failures) {226 await this.reporter.waitForSync()227 this.emit('exit', failures === 0 ? 0 : 1)228 return failures229 }230 /**231 * end WebDriver session, a config object can be applied if object has changed232 * within a hook by the user233 */234 async endSession (payload) {235 /**236 * Attach to browser session before killing it in Multiremote237 */238 if (!global.browser && payload && payload.argv && payload.argv.watch) {239 if (payload.argv.isMultiremote) {240 this.isMultiremote = true241 global.browser = await attachToMultiremote(payload.argv.instances, payload.argv.caps)242 } else {243 global.browser = await initialiseInstance(payload.argv.config, payload.argv.caps, false)244 }245 }246 /**247 * make sure instance(s) exist and have `sessionId`248 */249 const hasSessionId = global.browser && (this.isMultiremote250 /**251 * every multiremote instance should exist and should have `sessionId`252 */253 ? !global.browser.instances.some(i => global.browser[i] && !global.browser[i].sessionId)254 /**255 * browser object should have `sessionId` in regular mode256 */257 : global.browser.sessionId)...

Full Screen

Full Screen

utils.test.js

Source:utils.test.js Github

copy

Full Screen

...81 })82 })83 describe('initialiseInstance', () => {84 it('should attach to an existing session if sessionId is within config', () => {85 initialiseInstance({86 sessionId: 123,87 foo: 'bar'88 }, [89 { browserName: 'chrome' }90 ])91 expect(attach).toBeCalledWith({92 sessionId: 123,93 foo: 'bar',94 capabilities: [{ browserName: 'chrome' }]95 })96 expect(multiremote).toHaveBeenCalledTimes(0)97 expect(remote).toHaveBeenCalledTimes(0)98 })99 it('should run multiremote tests if flag is given', () => {100 const capabilities = { someBrowser: { browserName: 'chrome' } }101 initialiseInstance(102 { foo: 'bar' },103 capabilities,104 true105 )106 expect(attach).toHaveBeenCalledTimes(0)107 expect(multiremote).toBeCalledWith({108 someBrowser: {109 browserName: 'chrome',110 foo: 'bar'111 }112 })113 expect(remote).toHaveBeenCalledTimes(0)114 })115 it('should create normal remote session', () => {116 initialiseInstance({117 foo: 'bar'118 },119 {120 browserName: 'chrome',121 maxInstances: 123122 })123 expect(attach).toHaveBeenCalledTimes(0)124 expect(multiremote).toHaveBeenCalledTimes(0)125 expect(remote).toBeCalledWith({126 foo: 'bar',127 capabilities: { browserName: 'chrome' }128 })129 })130 afterEach(() => {...

Full Screen

Full Screen

utils.js

Source:utils.js Github

copy

Full Screen

...40 * @param {Object} capabilities desired session capabilities41 * @param {boolean} isMultiremote isMultiremote42 * @return {Promise} resolves with browser object43 */44async function initialiseInstance(config, capabilities, isMultiremote) {45 /**46 * check if config has sessionId and attach it to a running session if so47 */48 if (config.sessionId) {49 log.debug(`attach to session with id ${config.sessionId}`);50 config.capabilities = sanitizeCaps(capabilities);51 /**52 * propagate connection details defined by services or user in capabilities53 */54 const { protocol, hostname, port, path } = capabilities;55 return webdriverio_1.attach({ ...config, ...{ protocol, hostname, port, path } });56 }57 if (!isMultiremote) {58 log.debug('init remote session');...

Full Screen

Full Screen

jquery.enableTinyMce.js

Source:jquery.enableTinyMce.js Github

copy

Full Screen

1(function($) {23 // attach this new method to jQuery4 $.fn.extend({56 enableTinyMce: function(options) {78 var settings = $.extend({9 script_location: "../../Scripts/tiny_mce/tiny_mce.js",10 overrideHeight: "400",11 overrideWidth: "400",12 overrideOnchange: "",13 //http://www.matthewkenny.com/2009/05/tinymce-and-jquery-validation/14 initInstanceCallback: 15 function (editor) {16 //Get the textarea17 var container = $('#' + editor.editorId);1819 //Get the form submit buttons for the textarea20 $(editor.formElement).find("input[type=submit]").click(21 function (event) {22 container.val(editor.getContent());23 }24 );25 }26 }, options);272829 // iterate through each of the objects passed in to generate the calendar30 return this.each(function(index, item) {3132 // add the rich text editor33 $(item).tinymce({34 script_url: settings.script_location,35 // General options36 theme: "advanced",37 plugins: "safari,style,save,searchreplace,print,contextmenu,paste",3839 // Theme options40 theme_advanced_buttons1: "print,|,bold,italic,underline,|,fontsizeselect,search,replace,|,pastetext,pasteword,|,undo,redo,|,bullist,numlist,|,myButton",41 theme_advanced_buttons2: "",42 theme_advanced_buttons3: "",43 theme_advanced_toolbar_location: "top",44 theme_advanced_toolbar_align: "left",45 theme_advanced_statusbar_location: "bottom",46 theme_advanced_resizing: false,4748 // dimensions stuff49 height: settings.overrideHeight,50 width: settings.overrideWidth,5152 // Example content CSS (should be your site CSS)53 //content_css: "css/Main.css",5455 // Drop lists for link/image/media/template dialogs56 template_external_list_url: "js/template_list.js",57 external_link_list_url: "js/link_list.js",58 external_image_list_url: "js/image_list.js",59 media_external_list_url: "js/media_list.js",6061 onchange_callback : settings.overrideOnchange,62 init_instance_callback: settings.initInstanceCallback63 });6465 });6667 } // end of gooCal68 }); // end of $.fn.extend69})(jQuery);70717273//tinyMCE.init({74// mode: 'textareas',75// theme: 'advanced',76// theme_advanced_buttons1: 'bold,italic,underline',77// theme_advanced_buttons2: '',78// theme_advanced_buttons3: '',79// theme_advanced_toolbar_location: 'top',80// theme_advanced_toolbar_align: 'left',81// theme_advanced_statusbar_location: 'bottom',82// init_instance_callback: "initialiseInstance"83//}); ...

Full Screen

Full Screen

form.js

Source:form.js Github

copy

Full Screen

...49 });50 window.history.pushState('forward', null, './'+newGetId);51 }52});53function initialiseInstance(editor)54{55 console.log('AAAA: ' + editor.getContent());56 //Get the textarea57 var container = $('#' + editor.editorId);58 //Get the form submit buttons for the textarea59 $('#btn-admin-member-submit').click(function(event){60 console.log('AAAA: ' + editor.getContent());61 if(editor.getContent()==""){62 $('#ckview').validationEngine('showPrompt', '* 必須項目です', 'red', 'centerRight');63 return false;64 }else{65 $('#ckview').validationEngine('hide')66 }67 });...

Full Screen

Full Screen

setup-tinymce.js

Source:setup-tinymce.js Github

copy

Full Screen

1function initialiseInstance(editor) {2 //This script taken from www.matthewkenny.com 3 var container = $('#' + editor.editorId);4 $(editor.formElement).find("input[type=submit]").click(5 function (event) {6 tinyMCE.triggerSave();7 $("#" + editor.id).valid();8 container.val(editor.getContent());9 }10 );11}12tinymce.init({13 selector: 'textarea.content',14 plugins: 'print preview fullpage importcss searchreplace autolink autosave save directionality visualblocks visualchars fullscreen image link media codesample table charmap hr pagebreak nonbreaking anchor insertdatetime advlist lists wordcount imagetools textpattern noneditable help charmap quickbars emoticons code ',15 menubar: 'file edit view insert format tools table ',...

Full Screen

Full Screen

index-initSession.test.js

Source:index-initSession.test.js Github

copy

Full Screen

1import WDIORunner from '../src'2jest.mock('../src/utils', () => ({3 __esModule: true,4 initialiseInstance(err) {5 if (err) {6 throw new Error(err)7 }8 return {9 '$'() { },10 '$$'() { },11 sessionId: 'id',12 events: {},13 on(eventName, callback) {14 this.events[eventName] = callback15 }16 }17 }18}))...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriverio = require('webdriverio');2var options = { desiredCapabilities: { browserName: 'chrome' } };3var client = webdriverio.remote(options);4 .init()5 .getTitle().then(function(title) {6 console.log('Title was: ' + title);7 })8 .end();9var webdriverio = require('webdriverio');10var client = webdriverio.remote(options);11 .init()12 .getTitle().then(function(title) {13 console.log('Title was: ' + title);14 })15 .end();16var webdriverio = require('webdriverio');17var options = { desiredCapabilities: { browserName: 'chrome' } };18var client = webdriverio.remote(options);19 .init()20 .getTitle().then(function(title) {21 console.log('Title was: ' + title);22 })23 .end();

Full Screen

Using AI Code Generation

copy

Full Screen

1const webdriverio = require('webdriverio');2const options = {3 desiredCapabilities: {4 }5};6 .remote(options)7 .init()8 .getTitle().then(function(title) {9 console.log('Title was: ' + title);10 })11 .end();12const webdriverio = require('webdriverio');13const options = {14 desiredCapabilities: {15 }16};17 .remote(options)18 .init()19 .end();

Full Screen

Using AI Code Generation

copy

Full Screen

1require('chromedriver');2const webdriverio = require('webdriverio');3const options = { desiredCapabilities: { browserName: 'chrome' } };4const client = webdriverio.remote(options);5 .init()6 .setValue('input[type="text"]', 'webdriverio')7 .click('input[value="Google Search"]')8 .getTitle().then(function(title) {9 console.log('Title is: ' + title);10 })11 .end();

Full Screen

Using AI Code Generation

copy

Full Screen

1const webdriverio = require('webdriverio');2const options = {3 desiredCapabilities: {4 }5};6 .remote(options)7 .init()8 .getTitle().then(function(title) {9 console.log('Title was: ' + title);10 })11 .end();

Full Screen

Using AI Code Generation

copy

Full Screen

1import { initialiseInstance } from 'webdriverio';2import { config } from './config';3(async () => {4 const browser = initialiseInstance(config);5 console.log(await browser.getTitle());6 await browser.deleteSession();7})();8export const config = {9 capabilities: {10 }11};12export.config = {13 capabilities: [{14 }]15};

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriverio = require('webdriverio');2webdriverio.initialiseInstance().then(function(client){3 console.log("webdriverio instance initialised");4 client.getTitle().then(function(title) {5 console.log('Title was: ' + title);6 });7 client.end();8});9var webdriverio = require('webdriverio');10var options = {11 desiredCapabilities: {12 }13};14var client = webdriverio.remote(options);15var initialiseInstance = function(){16 return new Promise(function(resolve, reject){17 client.init().then(function(){18 resolve(client);19 });20 });21};22module.exports = {23};24module.exports = {25};26module.exports = {27};28module.exports = {29};30module.exports = {31};

Full Screen

Using AI Code Generation

copy

Full Screen

1const Webdriverio = require('webdriverio');2const webdriverio = new Webdriverio();3webdriverio.initialiseInstance()4const Webdriverio = require('webdriverio');5const webdriverio = new Webdriverio();6webdriverio.initialiseInstance()7const Webdriverio = require('webdriverio');8const webdriverio = new Webdriverio();9webdriverio.initialiseInstance()10- [Abhishek Kumar](

Full Screen

WebdriverIO Tutorial

Wondering what could be a next-gen browser and mobile test automation framework that is also simple and concise? Yes, that’s right, it's WebdriverIO. Since the setup is very easy to follow compared to Selenium testing configuration, you can configure the features manually thereby being the center of attraction for automation testing. Therefore the testers adopt WedriverIO to fulfill their needs of browser testing.

Learn to run automation testing with WebdriverIO tutorial. Go from a beginner to a professional automation test expert with LambdaTest WebdriverIO tutorial.

Chapters

  1. Running Your First Automation Script - Learn the steps involved to execute your first Test Automation Script using WebdriverIO since the setup is very easy to follow and the features can be configured manually.

  2. Selenium Automation With WebdriverIO - Read more about automation testing with WebdriverIO and how it supports both browsers and mobile devices.

  3. Browser Commands For Selenium Testing - Understand more about the barriers faced while working on your Selenium Automation Scripts in WebdriverIO, the ‘browser’ object and how to use them?

  4. Handling Alerts & Overlay In Selenium - Learn different types of alerts faced during automation, how to handle these alerts and pops and also overlay modal in WebdriverIO.

  5. How To Use Selenium Locators? - Understand how Webdriver uses selenium locators in a most unique way since having to choose web elements very carefully for script execution is very important to get stable test results.

  6. Deep Selectors In Selenium WebdriverIO - The most popular automation testing framework that is extensively adopted by all the testers at a global level is WebdriverIO. Learn how you can use Deep Selectors in Selenium WebdriverIO.

  7. Handling Dropdown In Selenium - Learn more about handling dropdowns and how it's important while performing automated browser testing.

  8. Automated Monkey Testing with Selenium & WebdriverIO - Understand how you can leverage the amazing quality of WebdriverIO along with selenium framework to automate monkey testing of your website or web applications.

  9. JavaScript Testing with Selenium and WebdriverIO - Speed up your Javascript testing with Selenium and WebdriverIO.

  10. Cross Browser Testing With WebdriverIO - Learn more with this step-by-step tutorial about WebdriverIO framework and how cross-browser testing is done with WebdriverIO.

Run Webdriverio automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful