Best JavaScript code snippet using webdriverio-monorepo
register.UI.js
Source:register.UI.js
...27 LoginPage.logOutFromApplication();28 //2. click on register link over email29 TestUtil.clickRegisterLinkInEmail();30 //close first two windows31 browser.switchToWindow(browser.getWindowHandles()[0]);32 browser.closeWindow();33 browser.switchToWindow(browser.getWindowHandles()[0]);34 browser.closeWindow();35 browser.switchToWindow(browser.getWindowHandles()[0]);36 //verify name and email is filled by Admin37 expect(RegisterPage.inputRegisterUserName.getAttribute('value')).to.be.equal('AutomationTesting'+ emailAccount.replace('@mailinator.com',""));38 expect(RegisterPage.inputRegisterUserEmail.getAttribute('value')).to.be.equal(emailAccount);39 });40 it('Should display error message for mandatory fields Name, Email and Password',()=>{41 //1. sent invite to user via invite user from app.42 //Open App43 LoginPage.open();44 //wait till Login page is loaded45 LoginPage.waitTillPageLoadComplete();46 //login as Admin47 LoginPage.loginAsAdmin();48 //navigate to user invite page49 LoginPage.navigateToUserInviteUsers();50 //wait till User Invite page is loaded51 UserInviteUserPage.waitTillPageLoadComplete();52 //create new email address53 let emailAccount = TestUtil.createNewEmailAccount();54 //create invite for new user by super admin55 UserInviteUserPage.inviteUserAsSuperAdmin(emailAccount);56 //click on send button57 UserInviteUserPage.clickSendInvitationButton();58 //logout as Super Admin from whom invite is send59 LoginPage.logOutFromApplication();60 //2. click on register link over email61 TestUtil.clickRegisterLinkInEmail();62 //close first two windows63 browser.switchToWindow(browser.getWindowHandles()[0]);64 browser.closeWindow();65 browser.switchToWindow(browser.getWindowHandles()[0]);66 browser.closeWindow();67 browser.switchToWindow(browser.getWindowHandles()[0]);68 //clear email and name values69 RegisterPage.clearRegisterUserNameEmail();70 //3. try to submit without mandatory fields.71 RegisterPage.clickAcceptInviteSaveButton();72 //verify error message for Name, Email and Password73 expect(RegisterPage.labelRegisterUserNameError.getText()).to.be.equal('The name field is required.');74 expect(RegisterPage.labelRegisterUserEmailError.getText()).to.be.equal('The email field is required.');75 expect(RegisterPage.labelRegisterUserPasswordError.getText()).to.be.equal('Password is required.');76 });77 it('Should display error message for Invalid Email format',()=>{78 //1. sent invite to user via invite user from app.79 //Open App80 LoginPage.open();81 //wait till Login page is loaded82 LoginPage.waitTillPageLoadComplete();83 //login as Admin84 LoginPage.loginAsAdmin();85 //navigate to user invite page86 LoginPage.navigateToUserInviteUsers();87 //wait till User Invite page is loaded88 UserInviteUserPage.waitTillPageLoadComplete();89 //create new email address90 let emailAccount = TestUtil.createNewEmailAccount();91 //create invite for new user by super admin92 UserInviteUserPage.inviteUserAsSuperAdmin(emailAccount);93 //click on send button94 UserInviteUserPage.clickSendInvitationButton();95 //logout as Super Admin from whom invite is send96 LoginPage.logOutFromApplication();97 //2. click on register link over email98 TestUtil.clickRegisterLinkInEmail();99 //close first two windows100 browser.switchToWindow(browser.getWindowHandles()[0]);101 browser.closeWindow();102 browser.switchToWindow(browser.getWindowHandles()[0]);103 browser.closeWindow();104 browser.switchToWindow(browser.getWindowHandles()[0]);105 //enter invalid email format106 RegisterPage.updateRegisterUserWithInvalidEmail();107 //click on send button108 RegisterPage.clickAcceptInviteSaveButton();109 //verify error message for invalid email format110 expect(RegisterPage.labelRegisterUserEmailError.getText()).to.be.equal('The email must be a valid email address.');111 });112 it('Should display error message for Already Registered Email',()=>{113 //1. sent invite to user via invite user from app.114 //Open App115 LoginPage.open();116 //wait till Login page is loaded117 LoginPage.waitTillPageLoadComplete();118 //login as Admin119 LoginPage.loginAsAdmin();120 //navigate to user invite page121 LoginPage.navigateToUserInviteUsers();122 //wait till User Invite page is loaded123 UserInviteUserPage.waitTillPageLoadComplete();124 //create new email address125 let emailAccount = TestUtil.createNewEmailAccount();126 //create invite for new user by super admin127 UserInviteUserPage.inviteUserAsSuperAdmin(emailAccount);128 //click on send button129 UserInviteUserPage.clickSendInvitationButton();130 //logout as Super Admin from whom invite is send131 LoginPage.logOutFromApplication();132 //2. click on register link over email133 TestUtil.clickRegisterLinkInEmail();134 //close first two windows135 browser.switchToWindow(browser.getWindowHandles()[0]);136 browser.closeWindow();137 browser.switchToWindow(browser.getWindowHandles()[0]);138 browser.closeWindow();139 browser.switchToWindow(browser.getWindowHandles()[0]);140 //enter invalid email format141 RegisterPage.updateRegisterUserWithRegisteredEmail();142 //click on send button143 RegisterPage.clickAcceptInviteSaveButton();144 //verify error message for invalid email format145 expect(RegisterPage.labelRegisterUserEmailError.getText()).to.be.equal('The email has already been taken.');146 });147 it('Should display an error message when password length is less than 8 characters',()=>{148 //1. sent invite to user via invite user from app.149 //Open App150 LoginPage.open();151 //wait till Login page is loaded152 LoginPage.waitTillPageLoadComplete();153 //login as Admin154 LoginPage.loginAsAdmin();155 //navigate to user invite page156 LoginPage.navigateToUserInviteUsers();157 //wait till User Invite page is loaded158 UserInviteUserPage.waitTillPageLoadComplete();159 //create new email address160 let emailAccount = TestUtil.createNewEmailAccount();161 //create invite for new user by super admin162 UserInviteUserPage.inviteUserAsSuperAdmin(emailAccount);163 //click on send button164 UserInviteUserPage.clickSendInvitationButton();165 //logout as Super Admin from whom invite is send166 LoginPage.logOutFromApplication();167 //2. click on register link over email168 TestUtil.clickRegisterLinkInEmail();169 //close first two windows170 browser.switchToWindow(browser.getWindowHandles()[0]);171 browser.closeWindow();172 browser.switchToWindow(browser.getWindowHandles()[0]);173 browser.closeWindow();174 browser.switchToWindow(browser.getWindowHandles()[0]);175 //enter password with 5 character length176 RegisterPage.enterRegisterUserPasswordWithLess8CharacterLength();177 //click on send button178 RegisterPage.clickAcceptInviteSaveButton();179 //verify error message for invalid email format180 expect(RegisterPage.labelRegisterUserPasswordError.getText()).to.be.equal('Password must be at least 8 characters in length.');181 });182 it('Should display an error message when password without lower characters',()=>{183 //1. sent invite to user via invite user from app.184 //Open App185 LoginPage.open();186 //wait till Login page is loaded187 LoginPage.waitTillPageLoadComplete();188 //login as Admin189 LoginPage.loginAsAdmin();190 //navigate to user invite page191 LoginPage.navigateToUserInviteUsers();192 //wait till User Invite page is loaded193 UserInviteUserPage.waitTillPageLoadComplete();194 //create new email address195 let emailAccount = TestUtil.createNewEmailAccount();196 //create invite for new user by super admin197 UserInviteUserPage.inviteUserAsSuperAdmin(emailAccount);198 //click on send button199 UserInviteUserPage.clickSendInvitationButton();200 //logout as Super Admin from whom invite is send201 LoginPage.logOutFromApplication();202 //2. click on register link over email203 TestUtil.clickRegisterLinkInEmail();204 //close first two windows205 browser.switchToWindow(browser.getWindowHandles()[0]);206 browser.closeWindow();207 browser.switchToWindow(browser.getWindowHandles()[0]);208 browser.closeWindow();209 browser.switchToWindow(browser.getWindowHandles()[0]);210 //enter password with 5 character length211 RegisterPage.enterRegisterUserPasswordWithoutLowerCharacters();212 //click on send button213 RegisterPage.clickAcceptInviteSaveButton();214 //verify error message for invalid email format215 let expectedOutput = 'Password be a combination of each of the following: lowercase letter, uppercase letter, number, and a special character (ex: ! @ # $ % ^ & * ).';216 expect(RegisterPage.labelRegisterUserPasswordError.getText()).to.be.equal(expectedOutput);217 });218 it('Should display an error message when password without upper characters',()=>{219 //1. sent invite to user via invite user from app.220 //Open App221 LoginPage.open();222 //wait till Login page is loaded223 LoginPage.waitTillPageLoadComplete();224 //login as Admin225 LoginPage.loginAsAdmin();226 //navigate to user invite page227 LoginPage.navigateToUserInviteUsers();228 //wait till User Invite page is loaded229 UserInviteUserPage.waitTillPageLoadComplete();230 //create new email address231 let emailAccount = TestUtil.createNewEmailAccount();232 //create invite for new user by super admin233 UserInviteUserPage.inviteUserAsSuperAdmin(emailAccount);234 //click on send button235 UserInviteUserPage.clickSendInvitationButton();236 //logout as Super Admin from whom invite is send237 LoginPage.logOutFromApplication();238 //2. click on register link over email239 TestUtil.clickRegisterLinkInEmail();240 //close first two windows241 browser.switchToWindow(browser.getWindowHandles()[0]);242 browser.closeWindow();243 browser.switchToWindow(browser.getWindowHandles()[0]);244 browser.closeWindow();245 browser.switchToWindow(browser.getWindowHandles()[0]);246 //enter password with 5 character length247 RegisterPage.enterRegisterUserPasswordWithoutUpperCharacters();248 //click on send button249 RegisterPage.clickAcceptInviteSaveButton();250 //verify error message for invalid email format251 let expectedOutput = 'Password be a combination of each of the following: lowercase letter, uppercase letter, number, and a special character (ex: ! @ # $ % ^ & * ).';252 expect(RegisterPage.labelRegisterUserPasswordError.getText()).to.be.equal(expectedOutput);253 });254 it('Should display an error message when password without special characters',()=>{255 //1. sent invite to user via invite user from app.256 //Open App257 LoginPage.open();258 //wait till Login page is loaded259 LoginPage.waitTillPageLoadComplete();260 //login as Admin261 LoginPage.loginAsAdmin();262 //navigate to user invite page263 LoginPage.navigateToUserInviteUsers();264 //wait till User Invite page is loaded265 UserInviteUserPage.waitTillPageLoadComplete();266 //create new email address267 let emailAccount = TestUtil.createNewEmailAccount();268 //create invite for new user by super admin269 UserInviteUserPage.inviteUserAsSuperAdmin(emailAccount);270 //click on send button271 UserInviteUserPage.clickSendInvitationButton();272 //logout as Super Admin from whom invite is send273 LoginPage.logOutFromApplication();274 //2. click on register link over email275 TestUtil.clickRegisterLinkInEmail();276 //close first two windows277 browser.switchToWindow(browser.getWindowHandles()[0]);278 browser.closeWindow();279 browser.switchToWindow(browser.getWindowHandles()[0]);280 browser.closeWindow();281 browser.switchToWindow(browser.getWindowHandles()[0]);282 //enter password with 5 character length283 RegisterPage.enterRegisterUserPasswordWithoutSpecialCharacters();284 //click on send button285 RegisterPage.clickAcceptInviteSaveButton();286 //verify error message for invalid email format287 let expectedOutput = 'Password be a combination of each of the following: lowercase letter, uppercase letter, number, and a special character (ex: ! @ # $ % ^ & * ).';288 expect(RegisterPage.labelRegisterUserPasswordError.getText()).to.be.equal(expectedOutput);289 });290 it('Should display an error message when password without number',()=>{291 //1. sent invite to user via invite user from app.292 //Open App293 LoginPage.open();294 //wait till Login page is loaded295 LoginPage.waitTillPageLoadComplete();296 //login as Admin297 LoginPage.loginAsAdmin();298 //navigate to user invite page299 LoginPage.navigateToUserInviteUsers();300 //wait till User Invite page is loaded301 UserInviteUserPage.waitTillPageLoadComplete();302 //create new email address303 let emailAccount = TestUtil.createNewEmailAccount();304 //create invite for new user by super admin305 UserInviteUserPage.inviteUserAsSuperAdmin(emailAccount);306 //click on send button307 UserInviteUserPage.clickSendInvitationButton();308 //logout as Super Admin from whom invite is send309 LoginPage.logOutFromApplication();310 //2. click on register link over email311 TestUtil.clickRegisterLinkInEmail();312 //close first two windows313 browser.switchToWindow(browser.getWindowHandles()[0]);314 browser.closeWindow();315 browser.switchToWindow(browser.getWindowHandles()[0]);316 browser.closeWindow();317 browser.switchToWindow(browser.getWindowHandles()[0]);318 //enter password with 5 character length319 RegisterPage.enterRegisterUserPasswordWithoutNumbers();320 //click on send button321 RegisterPage.clickAcceptInviteSaveButton();322 //verify error message for invalid email format323 let expectedOutput = 'Password be a combination of each of the following: lowercase letter, uppercase letter, number, and a special character (ex: ! @ # $ % ^ & * ).';324 expect(RegisterPage.labelRegisterUserPasswordError.getText()).to.be.equal(expectedOutput);325 });326 it('Should display an error message when confirm password is not match with password',()=>{327 //1. sent invite to user via invite user from app.328 //Open App329 LoginPage.open();330 //wait till Login page is loaded331 LoginPage.waitTillPageLoadComplete();332 //login as Admin333 LoginPage.loginAsAdmin();334 //navigate to user invite page335 LoginPage.navigateToUserInviteUsers();336 //wait till User Invite page is loaded337 UserInviteUserPage.waitTillPageLoadComplete();338 //create new email address339 let emailAccount = TestUtil.createNewEmailAccount();340 //create invite for new user by super admin341 UserInviteUserPage.inviteUserAsSuperAdmin(emailAccount);342 //click on send button343 UserInviteUserPage.clickSendInvitationButton();344 //logout as Super Admin from whom invite is send345 LoginPage.logOutFromApplication();346 //2. click on register link over email347 TestUtil.clickRegisterLinkInEmail();348 //close first two windows349 browser.switchToWindow(browser.getWindowHandles()[0]);350 browser.closeWindow();351 browser.switchToWindow(browser.getWindowHandles()[0]);352 browser.closeWindow();353 browser.switchToWindow(browser.getWindowHandles()[0]);354 //set value for Password 355 RegisterPage.enterRegisterUserPassword(RegisterUserData.newRegisterUser.password);356 //click on save button357 RegisterPage.clickAcceptInviteSaveButton();358 //verify error message for Confirm Password359 expect(RegisterPage.labelRegisterUserPasswordError.getText()).to.be.equal('The password confirmation does not match.');360 });361 it('Should display an error message for Invalid zip code',()=>{362 //1. sent invite to user via invite user from app.363 //Open App364 LoginPage.open();365 //wait till Login page is loaded366 LoginPage.waitTillPageLoadComplete();367 //login as Admin368 LoginPage.loginAsAdmin();369 //navigate to user invite page370 LoginPage.navigateToUserInviteUsers();371 //wait till User Invite page is loaded372 UserInviteUserPage.waitTillPageLoadComplete();373 //create new email address374 let emailAccount = TestUtil.createNewEmailAccount();375 //create invite for new user by super admin376 UserInviteUserPage.inviteUserAsSuperAdmin(emailAccount);377 //click on send button378 UserInviteUserPage.clickSendInvitationButton();379 //logout as Super Admin from whom invite is send380 LoginPage.logOutFromApplication();381 //2. click on register link over email382 TestUtil.clickRegisterLinkInEmail();383 //close first two windows384 browser.switchToWindow(browser.getWindowHandles()[0]);385 browser.closeWindow();386 browser.switchToWindow(browser.getWindowHandles()[0]);387 browser.closeWindow();388 browser.switchToWindow(browser.getWindowHandles()[0]);389 //fill new user details390 RegisterPage.enterNewRegisterUserDetails();391 //enter invalid Zip code392 RegisterPage.enterRegisterUserInvalidZipCode();393 //click on save button394 RegisterPage.clickAcceptInviteSaveButton();395 //verify error message for Confirm Password396 expect(RegisterPage.inputRegisterUserZipError.getText()).to.be.equal('The zip format is invalid.');397 });398 it('Should be able to register successfully and navigated to Login page',()=>{399 //1. sent invite to user via invite user from app.400 //Open App401 LoginPage.open();402 //wait till Login page is loaded403 LoginPage.waitTillPageLoadComplete();404 //login as Admin405 LoginPage.loginAsAdmin();406 //navigate to user invite page407 LoginPage.navigateToUserInviteUsers();408 //wait till User Invite page is loaded409 UserInviteUserPage.waitTillPageLoadComplete();410 //create new email address411 let emailAccount = TestUtil.createNewEmailAccount();412 //create invite for new user by super admin413 UserInviteUserPage.inviteUserAsSuperAdmin(emailAccount);414 //click on send button415 UserInviteUserPage.clickSendInvitationButton();416 //logout as Super Admin from whom invite is send417 LoginPage.logOutFromApplication();418 //2. click on register link over email419 TestUtil.clickRegisterLinkInEmail();420 //close first two windows421 browser.switchToWindow(browser.getWindowHandles()[0]);422 browser.closeWindow();423 browser.switchToWindow(browser.getWindowHandles()[0]);424 browser.closeWindow();425 browser.switchToWindow(browser.getWindowHandles()[0]);426 //fill new user details427 RegisterPage.enterNewRegisterUserDetails();428 //click on save button429 RegisterPage.clickAcceptInviteSaveButton();430 //verify error message for Confirm Password431 expect(browser.getUrl()).to.have.string('/login');432 });433 it('Should be able to register successfully and navigated to Login page',()=>{434 //1. sent invite to user via invite user from app.435 //Open App436 LoginPage.open();437 //wait till Login page is loaded438 LoginPage.waitTillPageLoadComplete();439 //login as Admin440 LoginPage.loginAsAdmin();441 //navigate to user invite page442 LoginPage.navigateToUserInviteUsers();443 //wait till User Invite page is loaded444 UserInviteUserPage.waitTillPageLoadComplete();445 //create new email address446 let emailAccount = TestUtil.createNewEmailAccount();447 //create invite for new user by super admin448 UserInviteUserPage.inviteUserAsSuperAdmin(emailAccount);449 //click on send button450 UserInviteUserPage.clickSendInvitationButton();451 //logout as Super Admin from whom invite is send452 LoginPage.logOutFromApplication();453 //2. click on register link over email454 TestUtil.clickRegisterLinkInEmail();455 //close first two windows456 browser.switchToWindow(browser.getWindowHandles()[0]);457 browser.closeWindow();458 browser.switchToWindow(browser.getWindowHandles()[0]);459 browser.closeWindow();460 browser.switchToWindow(browser.getWindowHandles()[0]);461 //fill new user details462 RegisterPage.enterNewRegisterUserDetails();463 //click on save button464 RegisterPage.clickAcceptInviteSaveButton();465 //verify error message for Confirm Password466 expect(browser.getUrl()).to.have.string('/login');467 });468 it('Should navigate to Invalid Link once user registered successfully',()=>{469 //1. sent invite to user via invite user from app.470 //Open App471 LoginPage.open();472 //wait till Login page is loaded473 LoginPage.waitTillPageLoadComplete();474 //login as Admin475 LoginPage.loginAsAdmin();476 //navigate to user invite page477 LoginPage.navigateToUserInviteUsers();478 //wait till User Invite page is loaded479 UserInviteUserPage.waitTillPageLoadComplete();480 //create new email address481 let emailAccount = TestUtil.createNewEmailAccount();482 //create invite for new user by super admin483 UserInviteUserPage.inviteUserAsSuperAdmin(emailAccount);484 //click on send button485 UserInviteUserPage.clickSendInvitationButton();486 //logout as Super Admin from whom invite is send487 LoginPage.logOutFromApplication();488 //2. click on register link over email489 TestUtil.clickRegisterLinkInEmail();490 //switch to send window491 browser.switchToWindow(browser.getWindowHandles()[2]);492 //fill new user details493 RegisterPage.enterNewRegisterUserDetails();494 //click on save button495 RegisterPage.clickAcceptInviteSaveButton();496 //wait till login page appear497 LoginPage.waitTillPageLoadComplete();498 //close browser499 browser.closeWindow();500 //move to second window501 browser.switchToWindow(browser.getWindowHandles()[1]);502 //back to mailbox503 browser.back();504 //click on Register link505 TestUtil.clickRegisterLinkInEmail();506 //verify error message for Confirm Password507 expect(TestUtil.checkInvalidInvitationCode()).to.have.equal(true);508 //switch to first browser509 browser.switchToWindow(browser.getWindowHandles()[0]);510 }); ...
switchTo.test.js
Source:switchTo.test.js
1const uuid = require('uuid/v4');2const switchTo = require('../../../../src/core/actions/switchTo');3const logger = require('../../../../src/utils/logger');4const { MESSAGE_TYPE, SWITCH_ERR } = require('../../../../src/constants');5describe('switch command test suite', () => {6 test('switchTo function should return if only single tab is open when "tab" is passed', async () => {7 const state = {8 browser: {9 getWindowHandle: jest.fn(),10 getWindowHandles: jest.fn(),11 },12 };13 state.browser.getWindowHandles.mockResolvedValue([uuid()]);14 state.browser.getWindowHandle.mockResolvedValue(uuid());15 await switchTo(state, { args: { what: 'tab' } });16 expect(state.browser.getWindowHandle).toHaveBeenCalled();17 expect(state.browser.getWindowHandles).toHaveBeenCalled();18 });19 test('switchTo function should switch between tabs when "tab" is passed when multiple tabs are open and current tab is the initial tab', async () => {20 const state = {21 browser: {22 getWindowHandles: jest.fn(),23 getWindowHandle: jest.fn(),24 switchToWindow: jest.fn(),25 },26 };27 const handles = [uuid(), uuid()];28 const currentWindow = handles[0];29 state.browser.getWindowHandles.mockResolvedValue(handles);30 state.browser.getWindowHandle.mockResolvedValue(currentWindow);31 state.browser.switchToWindow.mockResolvedValue(true);32 await switchTo(state, { args: { what: 'tab' } });33 expect(state.browser.getWindowHandle).toHaveBeenCalled();34 expect(state.browser.getWindowHandles).toHaveBeenCalled();35 expect(state.browser.switchToWindow).toHaveBeenCalled();36 });37 test('switchTo function should switch between tabs when "tab" is passed when multiple tabs are open and current tab is the latest tab', async () => {38 const state = {39 browser: {40 getWindowHandles: jest.fn(),41 getWindowHandle: jest.fn(),42 switchToWindow: jest.fn(),43 },44 };45 const handles = [uuid(), uuid()];46 const currentWindow = handles[1];47 state.browser.getWindowHandles.mockResolvedValue(handles);48 state.browser.getWindowHandle.mockResolvedValue(currentWindow);49 state.browser.switchToWindow.mockResolvedValue(true);50 await switchTo(state, { args: { what: 'tab' } });51 expect(state.browser.getWindowHandle).toHaveBeenCalled();52 expect(state.browser.getWindowHandles).toHaveBeenCalled();53 expect(state.browser.switchToWindow).toHaveBeenCalled();54 });55 test('switchTo function should return if only single tab is open when "window" is passed', async () => {56 const state = {57 browser: {58 getWindowHandle: jest.fn(),59 getWindowHandles: jest.fn(),60 },61 };62 state.browser.getWindowHandles.mockResolvedValue([uuid()]);63 state.browser.getWindowHandle.mockResolvedValue(uuid());64 await switchTo(state, { args: { what: 'window' } });65 expect(state.browser.getWindowHandle).toHaveBeenCalled();66 expect(state.browser.getWindowHandles).toHaveBeenCalled();67 });68 test('switchTo function should switch between tabs when "window" is passed when multiple tabs are open and current tab is the initial tab', async () => {69 const state = {70 browser: {71 getWindowHandles: jest.fn(),72 getWindowHandle: jest.fn(),73 switchToWindow: jest.fn(),74 },75 };76 const handles = [uuid(), uuid()];77 const currentWindow = handles[0];78 state.browser.getWindowHandles.mockResolvedValue(handles);79 state.browser.getWindowHandle.mockResolvedValue(currentWindow);80 state.browser.switchToWindow.mockResolvedValue(true);81 await switchTo(state, { args: { what: 'window' } });82 expect(state.browser.getWindowHandle).toHaveBeenCalled();83 expect(state.browser.getWindowHandles).toHaveBeenCalled();84 expect(state.browser.switchToWindow).toHaveBeenCalled();85 });86 test('switchTo function should switch between tabs when "window" is passed when multiple tabs are open and current tab is the latest tab', async () => {87 const state = {88 browser: {89 getWindowHandles: jest.fn(),90 getWindowHandle: jest.fn(),91 switchToWindow: jest.fn(),92 },93 };94 const handles = [uuid(), uuid()];95 const currentWindow = handles[1];96 state.browser.getWindowHandles.mockResolvedValue(handles);97 state.browser.getWindowHandle.mockResolvedValue(currentWindow);98 state.browser.switchToWindow.mockResolvedValue(true);99 await switchTo(state, { args: { what: 'tab' } });100 expect(state.browser.getWindowHandle).toHaveBeenCalled();101 expect(state.browser.getWindowHandles).toHaveBeenCalled();102 expect(state.browser.switchToWindow).toHaveBeenCalled();103 });104 test('switchTo function should emit an error message if an incorrect parameter is passed', async () => {105 const state = {106 browser: {107 getWindowHandles: jest.fn(),108 getWindowHandle: jest.fn(),109 switchToWindow: jest.fn(),110 },111 };112 logger.emitLogs = jest.fn();113 await switchTo(state, { args: { what: 'incorrect' } });114 expect(state.browser.getWindowHandle).not.toHaveBeenCalled();115 expect(state.browser.getWindowHandles).not.toHaveBeenCalled();116 expect(state.browser.switchToWindow).not.toHaveBeenCalled();117 expect(logger.emitLogs).toHaveBeenCalledWith({ message: SWITCH_ERR, type: MESSAGE_TYPE.ERROR });118 });...
navigation.js
Source:navigation.js
...30 page = page.replace(' extension', '');31 // Extension pages32 if (currentUrl.indexOf(`${page.toLowerCase()}.html`) === -1) {33 const url = `file://${__dirname}/../../../dist/sinon-chrome/${page.toLowerCase()}.html`;34 let tabIds = browser.getWindowHandles();35 if (tabIds.length > 0 && browser.getTitle() !== '') {36 browser.execute((url) => { // eslint-disable-line no-shadow37 window.open(url);38 });39 tabIds = browser.getWindowHandles();40 findTabByTitle('', tabIds);41 browser.url(url);42 } else {43 browser.url(url);44 }45 }46 expect(browser.getTitle()).to.be.oneOf(['Nuxeo Dev Tools', `${page} - Nuxeo Dev Tools`]);47 const browserUrl = browser.execute(() => {48 getCurrentTabUrl(() => {});49 return window.studioExt.server.url;50 });51 expect(browserUrl).to.equal('http://localhost:8080/nuxeo/');52 inject();53 let tabIds = browser.getWindowHandles();54 if (tabIds.length === 1) {55 openNuxeo();56 browser.pause(500);57 // Switch to Nuxeo58 tabIds = browser.getWindowHandles();59 findTabByTitle('Nuxeo Platform', tabIds);60 // Log in to Nuxeo61 login('Administrator', 'Administrator', 'input.login_button');62 browser.pause(500);63 // Switch back to extension page64 findTabByTitle('Nuxeo Dev Tools', tabIds);65 }66 } else if (page === 'Studio') {67 let tabIds = browser.getWindowHandles();68 if (tabIds.length > 1) {69 browser.execute(() => {70 const url = 'https://connect.nuxeo.com/nuxeo/site/studio/ide?project=bde-test';71 window.open(url);72 });73 browser.pause(500);74 tabIds = browser.getWindowHandles();75 findTabByTitle('Welcome - Nuxeo ⢠Connect â Customer Portal', tabIds);76 } else {77 const url = 'https://connect.nuxeo.com/nuxeo/site/studio/ide?project=bde-test';78 browser.url(url);79 }80 expect(browser.getTitle()).to.equal('Welcome - Nuxeo ⢠Connect â Customer Portal');81 } else if (page === 'Nuxeo') {82 openNuxeo();83 const tabIds = browser.getWindowHandles();84 findTabByTitle('Nuxeo Dev Tools', tabIds);85 } else {86 assert.fail([`"${page} page" unknown. See "navigation" step definition.`]);87 }88});89Then(/^I log into (.+)/, (page) => {90 if (page === 'Studio') {91 login(connectUsr, connectPsw, 'input.btn-submit');92 // Wait for stuff to happen in Studio so that HTTP calls pass93 browser.pause(8000);94 const title = browser.getTitle();95 expect(title.should.be.equal('Nuxeo Studio'));96 } else if (page === 'Nuxeo') {97 login('Administrator', 'Administrator', 'input.login_button');98 }99});100Then(/the (.+) page opens/, (titleToFind) => {101 const tabIds = browser.getWindowHandles();102 findTabByTitle(titleToFind, tabIds);103 return browser.getTitle().should.equal(titleToFind);104});105When(/I go to the (.+) page/, (page) => {106 const tabIds = browser.getWindowHandles();107 if (page === 'Popup extension') {108 page = 'Nuxeo Dev Tools';109 }110 findTabByTitle(page, tabIds);111 browser.refresh();112 expect(browser.getTitle()).to.include(page);113});114When(/I have a (.+) document in Nuxeo/, (docType) => {115 docType = docType || 'File';116 const doc = init(docType);117 return create('/default-domain/', doc).then((d) => {118 this.doc = d;119 });120});...
checkIsOpenedInNewWindow.spec.js
Source:checkIsOpenedInNewWindow.spec.js
1import checkIsOpenedInNewWindow from2 'src/support/check/checkIsOpenedInNewWindow';3describe('checkIsOpenedInNewWindow', () => {4 let expectLengthShouldNotEqual;5 let expectShouldContain;6 beforeEach(() => {7 global.browser = {8 getWindowHandles: jest.fn(() => ['window1', 'window2']),9 switchToWindow: jest.fn(() => {10 // foo11 }),12 getUrl: jest.fn(() => 'http://www.example.com/test'),13 closeWindow: jest.fn(() => {14 // foo15 }),16 };17 expectLengthShouldNotEqual = jest.fn();18 expectShouldContain = jest.fn();19 global.expect = jest.fn(() => ({20 not: {21 toHaveLength: expectLengthShouldNotEqual,22 },23 toContain: expectShouldContain,24 }));25 });26 it('Should fail if no popup was opened', () => {27 global.expect = jest.fn(() => {28 throw new Error();29 });30 global.browser.getWindowHandles.mockReturnValueOnce(['window1']);31 try {32 checkIsOpenedInNewWindow(33 'http://www.example.com/test',34 ''35 );36 } catch (e) {37 _expect(e);38 }39 _expect(global.browser.getWindowHandles).toHaveBeenCalledTimes(1);40 _expect(global.browser.getWindowHandles).toHaveBeenCalledWith();41 _expect(global.browser.switchToWindow).not.toHaveBeenCalled();42 _expect(global.browser.getUrl).not.toHaveBeenCalled();43 _expect(global.browser.closeWindow).not.toHaveBeenCalled();44 _expect(global.expect).toHaveBeenCalledTimes(1);45 _expect(global.expect).toHaveBeenCalledWith(['window1']);46 _expect(global.expect).toThrow();47 _expect(expectLengthShouldNotEqual).not.toHaveBeenCalled();48 _expect(expectShouldContain).not.toHaveBeenCalled();49 });50 it('Should not fail if the URL of the popup does match', () => {51 checkIsOpenedInNewWindow('http://www.example.com/test', '');52 _expect(global.browser.getWindowHandles).toHaveBeenCalledTimes(1);53 _expect(global.browser.getWindowHandles).toHaveBeenCalledWith();54 _expect(global.browser.switchToWindow).toHaveBeenCalledTimes(1);55 _expect(global.browser.switchToWindow).toHaveBeenCalledWith('window2');56 _expect(global.browser.getUrl).toHaveBeenCalledTimes(1);57 _expect(global.browser.getUrl).toHaveBeenCalledWith();58 _expect(global.browser.closeWindow).toHaveBeenCalledTimes(1);59 _expect(global.browser.closeWindow).toHaveBeenCalledWith();60 _expect(expectLengthShouldNotEqual).toHaveBeenCalledTimes(1);61 _expect(expectShouldContain).toHaveBeenCalledTimes(1);62 _expect(expectShouldContain).toHaveBeenCalledWith(63 'http://www.example.com/test',64 'The popup has a incorrect getUrl'65 );66 });...
checkNewWindow.spec.js
Source:checkNewWindow.spec.js
1import checkNewWindow from 'src/support/check/checkNewWindow';2describe('checkNewWindow', () => {3 let expectToEqual;4 let expectToNotEqual;5 beforeEach(() => {6 global.browser = {7 getWindowHandles: jest.fn(() => ({8 value: ['window1'],9 })),10 };11 expectToEqual = jest.fn();12 expectToNotEqual = jest.fn();13 global.expect = jest.fn(() => ({14 not: {15 toHaveLength: expectToNotEqual,16 },17 toHaveLength: expectToEqual,18 }));19 });20 it('Should test if a new window is opened', () => {21 checkNewWindow('', false);22 _expect(global.browser.getWindowHandles).toHaveBeenCalledTimes(1);23 _expect(global.browser.getWindowHandles).toHaveBeenCalledWith();24 _expect(expectToNotEqual).toHaveBeenCalledTimes(1);25 _expect(expectToNotEqual).toHaveBeenCalledWith(26 1,27 'A new window has been opened'28 );29 });30 it('Should test if a new window is not opened', () => {31 checkNewWindow('', true);32 _expect(global.browser.getWindowHandles).toHaveBeenCalledTimes(1);33 _expect(global.browser.getWindowHandles).toHaveBeenCalledWith();34 _expect(expectToEqual).toHaveBeenCalledTimes(1);35 _expect(expectToEqual).toHaveBeenCalledWith(36 1,37 'A new window should not have been opened'38 );39 });...
generic.steps.js
Source:generic.steps.js
1import { Given, When, Then } from "cucumber";2import coreLib from "../../utilities/coreLibrary.js"3Then(/^I should see the window title as "(.*)" opened in the same window/, expectedValue => {4 let windowHandles = browser.getWindowHandles();5 assert.equal(browser.switchWindow(windowHandles.value[0]).getTitle(), expectedValue, "Actual Value : " + browser.switchWindow(windowHandles.value[0]).getTitle() + "\n Expected Value : " + expectedValue + "\n Actual and Expected not matched");6});7Then(/^I should see the window title as "(.*)"/, expectedValue => {8 assert.equal(browser.getTitle(), expectedValue, "Actual Value : " + browser.getTitle() + "\n" + "Expected Value : " + expectedValue + "\n" + "Actual and Expected not matched");9});10Then(/^I should see the window title "(.*)" opened in the new tab/, expectedValue => {11 browser.switchToWindow(browser.getWindowHandles()[browser.getWindowHandles().length - 1]);12 expect(browser.getTitle().toString()).to.equal(expectedValue);13 browser.closeWindow();14 browser.switchToWindow(browser.getWindowHandles()[browser.getWindowHandles().length - 1]);15});16Given(/^I set customer data for scenario "(.*)"/, scenario => {17 coreLib.generateCustomerID(scenario)...
Using AI Code Generation
1describe('webdriver.io page', () => {2 it('should have the right title', () => {3 const title = browser.getTitle();4 assert.strictEqual(title, 'WebdriverIO · Next-gen WebDriver test framework for Node.js');5 });6 it('should have the right title', () => {7 const title = browser.getTitle();8 assert.strictEqual(title, 'WebdriverIO · Next-gen WebDriver test framework for Node.js');9 });10 it('should have the right title', () => {11 const title = browser.getTitle();12 assert.strictEqual(title, 'WebdriverIO · Next-gen WebDriver test framework for Node.js');13 });14});15describe('webdriver.io page', () => {16 it('should have the right title', () => {17 const title = browser.getTitle();18 assert.strictEqual(title, 'WebdriverIO · Next-gen WebDriver test framework for Node.js');19 });20 it('should have the right title', () => {21 const title = browser.getTitle();22 assert.strictEqual(title, 'WebdriverIO · Next-gen WebDriver test framework for Node.js');23 });24 it('should have the right title', () => {25 const title = browser.getTitle();26 assert.strictEqual(title, 'WebdriverIO · Next-gen WebDriver test framework for Node.js');27 });28});29describe('webdriver.io page', () => {30 it('should have the right title', () => {31 const title = browser.getTitle();32 assert.strictEqual(title, 'WebdriverIO · Next-gen WebDriver test framework for Node.js');33 });34 it('should have the right title', () => {35 const title = browser.getTitle();36 assert.strictEqual(title, 'WebdriverIO · Next-gen WebDriver test framework for Node.js');37 });38 it('should have the right title', () => {39 const title = browser.getTitle();40 assert.strictEqual(title, 'WebdriverIO · Next-gen WebDriver
Using AI Code Generation
1describe('webdriver.io page', () => {2 it('should have the right title', () => {3 const title = browser.getTitle();4 expect(title).toBe('WebdriverIO · Next-gen browser and mobile automation test framework for Node.js');5 browser.pause(2000);6 browser.windowHandles();7 browser.pause(2000);8 });9});
Using AI Code Generation
1describe('webdriver.io page', () => {2 it('should have the right title', () => {3 const title = browser.getTitle()4 console.log(browser.getWindowHandles());5 console.log(browser.getWindowHandle());6 console.log(browser.getWindowSize());7 console.log(browser.getUrl());8 console.log(browser.getTitle());9 console.log(browser.getTagName('body'));10 console.log(browser.getHTML('body'));11 console.log(browser.getSessionId());12 console.log(browser.getCookie());13 console.log(browser.getCookies());14 console.log(browser.getAlertText());
Using AI Code Generation
1describe('webdriver.io page', () => {2 it('should have the right title', () => {3 browser.pause(1000)4 const title = browser.getTitle()5 console.log(title)6 browser.pause(1000)7 })8})
Using AI Code Generation
1describe('webdriver.io page', function() {2 it('should be able to get the current window handles', function () {3 var windowHandles = browser.getWindowHandles();4 console.log(windowHandles);5 });6});
Using AI Code Generation
1describe('WebDriverIO API Demos', () => {2 it('Get Window Handles', () => {3 browser.pause(3000)4 console.log('Title of the page: ' + browser.getTitle())5 browser.pause(3000)6 browser.switchWindow('ToolsQA')7 browser.pause(3000)8 console.log('Title of the page: ' + browser.getTitle())9 browser.pause(3000)10 browser.switchWindow('Free QA Automation Tools Tutorial for Beginners with Examples')11 browser.pause(3000)12 console.log('Title of the page: ' + browser.getTitle())13 browser.pause(3000)14 })15})
Using AI Code Generation
1describe('Window Handling', () => {2 it('Window Handling', () => {3 browser.maximizeWindow();4 console.log('Parent Window Title: ' + browser.getTitle());5 var parentWindow = browser.getWindowHandle();6 console.log('Parent Window ID: ' + parentWindow);7 var handles = browser.getWindowHandles();8 console.log(handles);9 browser.switchWindow(handles[1]);10 console.log('Child Window Title: ' + browser.getTitle());11 var childWindow = browser.getWindowHandle();12 console.log('Child Window ID: ' + childWindow);13 browser.switchWindow(handles[0]);14 console.log('Parent Window Title: ' + browser.getTitle());15 })16})
Using AI Code Generation
1const webdriverio = require('webdriverio');2const options = { desiredCapabilities: { browserName: 'chrome' } };3 .remote(options)4 .init()5 .getTitle().then(function (title) {6 console.log('Title was: ' + title);7 })8 .windowHandles().then(function (handles) {9 console.log(handles);10 browser.switchToWindow(handles[1]);11 })12 .end();
Using AI Code Generation
1describe('webdriver.io page', () => {2 it('should have the right title', () => {3 browser.pause(3000)4 browser.getTitle()5 browser.pause(3000)6 browser.getUrl()7 browser.pause(3000)8 browser.getSource()9 browser.pause(3000)10 browser.getWindowHandles()11 browser.pause(3000)12 browser.pause(3000)13 browser.getTitle()14 browser.pause(3000)15 browser.getUrl()16 browser.pause(3000)17 browser.getSource()18 browser.pause(3000)19 browser.pause(3000)20 browser.getTitle()21 browser.pause(3000)22 browser.getUrl()23 browser.pause(3000)24 browser.getSource()25 browser.pause(3000)26 browser.pause(3000)27 browser.getTitle()28 browser.pause(3000)29 browser.getUrl()30 browser.pause(3000)31 browser.getSource()32 browser.pause(3000)33 })34})
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.
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.
Selenium Automation With WebdriverIO - Read more about automation testing with WebdriverIO and how it supports both browsers and mobile devices.
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?
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.
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.
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.
Handling Dropdown In Selenium - Learn more about handling dropdowns and how it's important while performing automated browser testing.
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.
JavaScript Testing with Selenium and WebdriverIO - Speed up your Javascript testing with Selenium and WebdriverIO.
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.
Get 100 minutes of automation test minutes FREE!!