Best JavaScript code snippet using appium
searchPage.js
Source:searchPage.js
1let Wait = require('../utils/wait')2let searchPage = function () {3 //Result Search Section4 let search_Image = element(by.css('img.card-image'));5 let emptyNotification_Message = element(by.css('span[translate="search.no.input.given.label"]'));6 let physician_Picture_Element = element(by.css('app-physician-card:nth-child(1)>div>div>div>app-avatar>div>img'));7 let physician_Name_Element = element(by.css('app-physician-card:nth-child(1)>div>div>div.physician-name, align-self-center'));8 let profile_Button_Element = element(by.css('app-physician-card:nth-child(1)>div>div>a+a>button'));9 let address_Element = element(by.css('app-physician-card:nth-child(1)>div>div+div>div>div>div:nth-child(1)'));10 let online_Appointments_Element = element(by.css('app-physician-card:nth-child(1)>div>div+div>div>div>div:nth-child(2)'));11 let availableAppointments_Element = element(by.css('app-physician-card:nth-child(1)>div>div+div>app-physician-calendar>div>div>div>span:nth-child(1)'));12 let showMoreResults_Element = element(by.css('a.load-more-link'));13 let result_Distance_Element = element(by.css('div.col-sm-12.col-md-8.col-lg-9 > div > div > app-physician-card:nth-child(1) > div > div.card-body > div > div > div:nth-child(1) > div:nth-child(2) > span.description-text'));14 let video_Conference_Element = element(by.css('app-physician-card:nth-child(1)>div>div+div>div>div>div:nth-child(2)>div'));15 let detail_Link = element(by.css('app-physician-card:nth-child(1)>div>div+div>div>div>div>div>span+span>a.online-booking-tooltip'));16 let result_Barrier_Element = element(by.css('span[translate="practice.flags.SG_handicappedAccessible"]'));17 //Search Section18 let specialization_Element = element(by.css('input#search-query-typeahead'));19 let location_Element = element(by.css('input#search-location-typeahead'));20 let onlineTime_Element = element(by.css('span[translate="search.filter.checkbox.online.booking"]'));21 let video_Appointment = element(by.css('label>span[translate="search.filter.checkbox.video.appointment"]'));22 let barrier_Element = element(by.css('span[translate="search.filter.checkbox.accessibility"]'));23 let searchButton_Element = element(by.css('button[translate="doctorSearch.search.filter.submit"]'));24 let timeFrame_Element = element(by.css('div[class="day dropdown dropdown-select d-block"]'));25 let selectSecondValue = element(by.css('div>typeahead-container[class="dropdown open dropdown-menu"]>button:nth-child(2)>span'));26 let selectfirstPhysician = element(by.css('typeahead-container[class="dropdown open dropdown-menu"]>button:nth-child(2)'));27 //Sorting Section28 let bestResult_Element = element(by.cssContainingText(".text", "Beste Ergebnisse"));29 let alphabeticByDoctor_Element = element(by.css('div:nth-child(2) > app-sort > div > div > div:nth-child(3) > div > div > label'));30 let radius_Element = element(by.css('div.row.mb-3 > div > div > label'));31 //New Test Case32 let promptMessage = element(by.css('button#matomo-reject'));33 let selectAppointmentType = element(by.css('div.dropdown-select>button[class*="btn btn"]'));34 let selectOfficeHours = element(by.css('div.dropdown-menu-right>button[class*="dropdown-item btn-block text-left ng-star-inserted"]:nth-of-type(1)'));35 let firstFreeAppointment = element(by.css('div[class="first-available-time calendar-cell-mask d-flex align-items-center justify-content-center ng-star-inserted"]'));36 let timeSlot = element(by.css('div[class="calendar-cell calendar-cell-mask justify-content-center align-items-center ng-star-inserted"]'));37 let nextButton1 = element(by.css('button[class="btn btn-primary w-100"]'));38 let nextButton2 = element(by.css('button[class="btn btn-primary w-100"]'));39 // let rememberLater = element(by.xpath('/html/body/app-root/div[2]/app-header/div/div[1]/div/div/div[2]/a'));40 //New Test Case 241 let requestForAppointment = element(by.css('[class="appointment-button-data"]'));42 let selectTuesday = element (by.css('div.table-content.collapsed > div:nth-child(1) > div:nth-child(2) > label > span'));43 let arrow = element (by.css('span[class="icon icon-G3_hideRight ng-star-inserted"]'));44 let physicanName = element(by.css('[class="profile-name align-self-center"]'))45 let selectSaturday = element(by.css('div.table-content > div:nth-child(1) > div:nth-child(6) > label'));46 let nextbutton3 = element(by.css('button[class="btn btn-primary w-100"]'));47 let pageTitle = element(by.css('div[class="appointment-wish-header-title"]'));48 let noButton = element(by.css('button.btn.btn-outline-secondary.option-button.ng-star-inserted.active-option'));49 let nextbutton4 = element(by.css('button[class="btn btn-primary w-100"]'));50 let sucessMessage = element(by.css('.appointment-wish-success')).element(by.css('.title'));51//functions52this.validatePhysicianName = function (title) {53 physicanName.getText().then(function (text){54 expect(text).toBe(title)55 })56}57this.clickOnRequestForAppointment = function () {58 requestForAppointment.click();59 60}61this.clickOnSelectTuesday = function () {62 selectTuesday.click();63 64}65this.clickOnArrow = function () {66 arrow.click();67 68}69this.ClickOnSaturday = function () {70 selectSaturday.click();71 72}73this.clickOnNextbutton3 = function () {74 nextbutton3.click();75 76}77this.validatePageTitle = function (title) {78 pageTitle.getText().then(function (text){79 expect(text).toBe(title)80 })81 82}83this.validateNoButton = function (text) {84 noButton.getText().then(function (value){85 expect(value).toBe(text)86 })87}88this.clickOnNextbutton4 = function () {89 nextbutton4.click();90 91}92this.clickOnNextbutton2 = function (title) {93 sucessMessage.getText().then(function (text){94 expect(text).toBe(title)95 })96}97 //New Test Funcitons98 this.ClickOnRememberLater = function () {99 rememberLater.click();100 101 }102 this.clickOnPromptMessage = function () {103 promptMessage.click();104 }105 this.clickOnSelectAppointmentType = function () {106 selectAppointmentType.click()107 108 }109 this.clickOnOfficeHours = function () {110 selectOfficeHours.click();111 }112 this.clickOnfirstFreeAppointment = function () {113 firstFreeAppointment.click();114 115 }116 this.clickOnTimeSlot = function () {117 timeSlot.click();118 }119 this.clickOnNextButton1 = function () {120 nextButton1.click();121 }122 this.clickOnNextButton2 = function () {123 nextButton2.click();124 }125 //Result Search Section functions126 this.validateResultBarrierElement = function (message) {127 result_Barrier_Element.isDisplayed().then(function (ResultBarrierElement) {128 console.log(ResultBarrierElement);129 expect(ResultBarrierElement).toEqual(true);130 })131 }132 this.validateVideoConferenceElement = function (message) {133 video_Conference_Element.isDisplayed().then(function (VideoConferenceElement) {134 console.log(VideoConferenceElement);135 expect(VideoConferenceElement).toEqual(true);136 })137 }138 this.ValidateEmptyNotificationMessage = function (message) {139 emptyNotification_Message.getText().then(function (emptyNotificationMessage) {140 console.log(emptyNotificationMessage);141 expect(emptyNotificationMessage).toEqual(message);142 })143 }144 this.searchImageValidation = function () {145 search_Image.isDisplayed().then(function (searchImage) {146 console.log(searchImage);147 expect(searchImage).toEqual(true);148 })149 }150 this.validatePhysicianPictureElement = function () {151 physician_Picture_Element.isDisplayed().then(function (PhysicianPictureElement) {152 console.log(PhysicianPictureElement);153 expect(PhysicianPictureElement).toEqual(true);154 })155 }156 this.validatePhysicianNameElement = function () {157 physician_Name_Element.isDisplayed().then(function (PhysicianNameElement) {158 console.log(PhysicianNameElement);159 expect(PhysicianNameElement).toEqual(true);160 })161 }162 this.validateProfileButtonElement = function () {163 profile_Button_Element.isDisplayed().then(function (ProfileButtonElement) {164 console.log(ProfileButtonElement);165 expect(ProfileButtonElement).toEqual(true);166 })167 }168 this.validateAddressElement = function () {169 address_Element.isDisplayed().then(function (addressElement) {170 console.log(addressElement);171 expect(addressElement).toEqual(true);172 })173 }174 this.validateOnlineAppointmentsElement = function () {175 online_Appointments_Element.isDisplayed().then(function (onlineAppointmentsElement) {176 console.log(onlineAppointmentsElement);177 expect(onlineAppointmentsElement).toEqual(true);178 })179 }180 this.validateAvailableAppointmentsElement = function () {181 availableAppointments_Element.isDisplayed().then(function (availableAppointmentsElement) {182 console.log(availableAppointmentsElement);183 expect(availableAppointmentsElement).toEqual(true);184 })185 }186 this.validateShowMoreResultsElement = function () {187 showMoreResults_Element.isDisplayed().then(function (ShowMoreResultsElement) {188 console.log(ShowMoreResultsElement);189 expect(ShowMoreResultsElement).toEqual(true);190 })191 }192 this.clickShowMoreResultsButton = function () {193 showMoreResults_Element.click();194 browser.sleep(3000)195 }196 this.clickDetailLink = function () {197 detail_Link.click();198 }199 this.validateResultDistanceElement = function () {200 result_Distance_Element.isDisplayed().then(function (DistanceElement) {201 console.log(DistanceElement);202 expect(DistanceElement).toEqual(true);203 })204 }205 //Search Section functions206 this.validateSpecializationElement = function () {207 specialization_Element.isDisplayed().then(function (specialityElement) {208 console.log(specialityElement);209 expect(specialityElement).toEqual(true);210 })211 }212 this.enterDoctorName = function (docName) {213 specialization_Element.sendKeys(docName)214 }215 this.selectSecondValueFromList = function () {216 selectSecondValue.click();217 218 }219 this.selectSecondPhysianFromList = function () {220 selectfirstPhysician.click();221 222 }223 224 this.validateLocationElement = function () {225 location_Element.isDisplayed().then(function (locationElement) {226 console.log(locationElement);227 expect(locationElement).toEqual(true);228 })229 }230 this.enterValueOnLocation = function (value) {231 location_Element.sendKeys(value);232 }233 this.validateOnlineTimeElement = function () {234 onlineTime_Element.isDisplayed().then(function (onlineTimeElement) {235 console.log(onlineTimeElement);236 expect(onlineTimeElement).toEqual(true);237 })238 }239 this.clickOnlineTimeElement = function () {240 onlineTime_Element.click();241 }242 this.validateVideoAppointmentElement = function () {243 video_Appointment.isDisplayed().then(function (videoAppointment) {244 console.log(videoAppointment);245 expect(videoAppointment).toEqual(true);246 })247 }248 this.clickVideoAppointment = function () {249 video_Appointment.click();250 }251 this.validateBarrierElement = function () {252 barrier_Element.isDisplayed().then(function (barrierElement) {253 console.log(barrierElement);254 expect(barrierElement).toEqual(true);255 })256 }257 this.clickBarrierElement = function () {258 barrier_Element.click();259 }260 this.validateSearchButtonElement = function () {261 searchButton_Element.isDisplayed().then(function (searchButtonElement) {262 console.log(searchButtonElement);263 expect(searchButtonElement).toEqual(true);264 })265 }266 this.clickSearchButton = function () {267 searchButton_Element.click();268 browser.sleep(3000)269 }270 this.validateTimeFrame_Element = function () {271 timeFrame_Element.isDisplayed().then(function (TimeFrame_Element) {272 console.log(TimeFrame_Element);273 expect(TimeFrame_Element).toEqual(true);274 })275 }276 //Sorting Section Functions277 this.validateBestResultElement = function () {278 bestResult_Element.isDisplayed().then(function (bestResultElement) {279 console.log(bestResultElement);280 expect(bestResultElement).toEqual(true);281 })282 }283 this.validateAlphabeticByDoctorElement = function () {284 alphabeticByDoctor_Element.isDisplayed().then(function (alphabeticByDoctorElement) {285 console.log(alphabeticByDoctorElement);286 expect(alphabeticByDoctorElement).toEqual(true);287 })288 }289 this.clickAlphabeticByDoctorElement = function () {290 alphabeticByDoctor_Element.click();291 browser.sleep(2000)292 }293 // this.validateDistanceElement = function () {294 // distance_Element.isDisplayed().then(function (distanceElement) {295 // console.log(distanceElement);296 // expect(distanceElement).toEqual(true);297 // })298 // }299 this.clickDistanceElement = function () {300 radius_Element.click();301 browser.sleep(3000)302 }303 this.validateRadiusElement = function () {304 radius_Element.isDisplayed().then(function (radiusElement) {305 console.log(radiusElement);306 expect(radiusElement).toEqual(true);307 })308 }309}...
delete-dev-machine.spec.js
Source:delete-dev-machine.spec.js
1/*2 * Copyright (c) 2015-2018 Red Hat, Inc.3 * This program and the accompanying materials are made4 * available under the terms of the Eclipse Public License 2.05 * which is available at https://www.eclipse.org/legal/epl-2.0/6 *7 * SPDX-License-Identifier: EPL-2.08 *9 * Contributors:10 * Red Hat, Inc. - initial API and implementation11 */12'use strict';13describe('Stack details >', () => {14 let stackDetailsPageObject;15 let stackDetailsMock;16 let utils;17 beforeEach(() => {18 stackDetailsMock = require('./../stack-details.mock.js');19 stackDetailsPageObject = require('./../stack-details.po.js');20 utils = require('../../../utils');21 });22 describe('one machine (dev) in stack >', () => {23 it('cannot be removed', () => {24 browser.addMockModule('userDashboardMock', stackDetailsMock.dockerimageStack);25 browser.get('/');26 // go to stack details page27 let stackId = 'testStackId';28 browser.setLocation('/stack/' + stackId);29 // get the machine configuration elements map30 let machineConfigElement = stackDetailsPageObject.getMachineConfigByIndex(0);31 expect(machineConfigElement).toBeTruthy();32 let machineConfigParts = stackDetailsPageObject.splitMachineConfig(machineConfigElement);33 // click on machine's title to expand its config34 expect(machineConfigParts.titleTextElement.isDisplayed()).toBeTruthy();35 machineConfigParts.titleTextElement.click();36 // check if current machine has ws-agent activated37 expect(machineConfigParts.isDevSwitchElement.getAttribute('class')).toMatch('md-checked');38 // click on 'Delete' button39 expect(machineConfigParts.titleDeleteElement.isDisplayed()).toBeTruthy();40 machineConfigParts.titleDeleteElement.click();41 // 'Remove machine' popup is shown42 expect(stackDetailsPageObject.deleteDevMachinePopupElement.isDisplayed()).toBeTruthy();43 // but "Delete" button is not there44 expect(stackDetailsPageObject.deleteDevMachineDeleteButtonElement.isPresent()).toBeFalsy();45 });46 });47 describe('two machines in stack >', () => {48 it('machine (not dev) can be removed', () => {49 browser.addMockModule('userDashboardMock', stackDetailsMock.composefileStack);50 browser.get('/');51 // go to stack details page52 const stackId = 'testStackId';53 browser.setLocation('/stack/' + stackId);54 // get machine (not dev)55 const notDevMachineName = 'db';56 let machineConfigElement = stackDetailsPageObject.getMachineConfigByName(notDevMachineName);57 expect(machineConfigElement).toBeTruthy();58 let machineConfigParts = stackDetailsPageObject.splitMachineConfig(machineConfigElement);59 // click on machine's title to expand its config60 expect(machineConfigParts.titleTextElement.isDisplayed()).toBeTruthy();61 machineConfigParts.titleTextElement.click();62 // check if current machine doesn't have ws-agent activated63 expect(machineConfigParts.isDevSwitchElement.getAttribute('class')).not.toMatch('md-checked');64 // try to remove this machine65 expect(machineConfigParts.titleDeleteElement.isDisplayed()).toBeTruthy();66 machineConfigParts.titleDeleteElement.click();67 // 'Remove machine' popup is shown68 expect(stackDetailsPageObject.deleteNotDevMachinePopupElement.isDisplayed()).toBeTruthy();69 // 'Delete' button is visible70 expect(stackDetailsPageObject.deleteNotDevMachineDeleteButtonElement.isDisplayed()).toBeTruthy();71 // click on 'Delete' button72 stackDetailsPageObject.deleteNotDevMachineDeleteButtonElement.click();73 const deletedMachineConfigElement = stackDetailsPageObject.getMachineConfigByName(notDevMachineName);74 expect(deletedMachineConfigElement.isPresent()).toBeFalsy();75 });76 it('machine (dev) can be removed', () => {77 browser.addMockModule('userDashboardMock', stackDetailsMock.composefileStack);78 browser.get('/');79 // go to stack details page80 const stackId = 'testStackId';81 browser.setLocation('/stack/' + stackId);82 // get first machine (dev)83 const firstMachineName = 'dev-machine';84 const firstMachineConfigElement = stackDetailsPageObject.getMachineConfigByName(firstMachineName);85 expect(firstMachineConfigElement).toBeTruthy();86 const firstMachineConfigParts = stackDetailsPageObject.splitMachineConfig(firstMachineConfigElement);87 // click on first machine's title to expand its config88 expect(firstMachineConfigParts.titleTextElement.isDisplayed()).toBeTruthy();89 firstMachineConfigParts.titleTextElement.click();90 // check if first machine has ws-agent activated91 expect(firstMachineConfigParts.isDevSwitchElement.getAttribute('class')).toMatch('md-checked');92 // try to remove this machine93 expect(firstMachineConfigParts.titleDeleteElement.isDisplayed()).toBeTruthy();94 firstMachineConfigParts.titleDeleteElement.click();95 // 'Remove machine' popup is shown96 expect(stackDetailsPageObject.deleteDevMachinePopupElement.isDisplayed()).toBeTruthy();97 // 'Delete' button is visible98 expect(stackDetailsPageObject.deleteDevMachineDeleteButtonElement.isDisplayed()).toBeTruthy();99 // 'Delete' button is disabled100 expect(stackDetailsPageObject.deleteDevMachineDeleteButtonElement.isEnabled()).toBeFalsy();101 // look for radio button for second machine102 const secondMachineName = 'db';103 let notDevMachineRadioButtonElement = utils.getRadioButtonByLabel(stackDetailsPageObject.deleteDevMachinePopupElement, secondMachineName.toUpperCase());104 expect(notDevMachineRadioButtonElement.isDisplayed()).toBeTruthy();105 // check second machine name radio button106 notDevMachineRadioButtonElement.click();107 // 'Delete' button is enabled108 expect(stackDetailsPageObject.deleteDevMachineDeleteButtonElement.isEnabled()).toBeTruthy();109 // click on 'Delete' button110 stackDetailsPageObject.deleteDevMachineDeleteButtonElement.click();111 // first machine config is deleted112 expect(firstMachineConfigElement.isPresent()).toBeFalsy();113 // get second machine config114 const secondMachineConfigElement = stackDetailsPageObject.getMachineConfigByName(secondMachineName);115 expect(secondMachineConfigElement).toBeTruthy();116 const secondMachineConfigParts = stackDetailsPageObject.splitMachineConfig(secondMachineConfigElement);117 // click on second machine's title to expand its config118 expect(secondMachineConfigParts.titleTextElement.isDisplayed()).toBeTruthy();119 secondMachineConfigParts.titleTextElement.click();120 // check if second machine has ws-agent activated121 expect(secondMachineConfigParts.isDevSwitchElement.getAttribute('class')).toMatch('md-checked');122 });123 });...
test_resetFilterNotification.spec.js
Source:test_resetFilterNotification.spec.js
1'use strict';2var components = require('components');3var logger = browser.getLogger('filter#test_resetFilter');4var _ = require('lodash');5describe('filter reset notifications', function(){6 beforeEach(function(){7 logger.info('running from ' + __filename);8 var opts = components.conf.resetFilterNotification;9 components.loginPage.load().login( opts.username, opts.password );10 });11 afterEach(function(){12 components.layout.logout();13 });14 it('should display notification in manage lessons', function(done){15 browser.get('/');16 components.layout.goToUserSection();17 components.mySection.goToMyLessons();18 expect(components.mySection.lessons.filterIsActiveNotification.displayElement.isDisplayed()).toBeFalsy('should not display on first load');19 components.filter.setText('foo');20 browser.actions().sendKeys(protractor.Key.ENTER).perform();21 expect(components.mySection.lessons.filterIsActiveNotification.displayElement.isDisplayed()).toBeTruthy('should display due to text');22 components.mySection.lessons.filterIsActiveNotification.resetFilter();23 expect(components.mySection.lessons.filterIsActiveNotification.displayElement.isDisplayed()).toBeFalsy('should not display after reset');24 components.filter.setText('foo');25 browser.actions().sendKeys(protractor.Key.ENTER).perform();26 expect(components.mySection.lessons.filterIsActiveNotification.displayElement.isDisplayed()).toBeTruthy('should display again due to text 2');27 components.mySection.lessons.filterIsActiveNotification.hideNotification();28 expect(components.mySection.lessons.filterIsActiveNotification.displayElement.isDisplayed()).toBeFalsy('should not display due to hide click');29 browser.refresh();30 expect(components.mySection.lessons.filterIsActiveNotification.displayElement.isDisplayed()).toBeTruthy('should display after refresh');31 browser.sleep(1000).then(done);32 });33 it('should display in all pages', function(){34 _.each(35 [36 { url : '/#!/user/create/lessons', page: components.mySection.lessons },37 { url : '/#!/user/create/questions', page: components.mySection.questions },38 { url : '/#!/user/create/reports', page: components.mySection.reports },39 { url : '/#!/user/create/invites', page: components.mySection.invites }40 ],41 function( location ){42 console.log('testing ', location);43 browser.get(location.url);44 logger.info('testing :: ' + location.url);45 browser.sleep(1000);46 components.filter.setSubject(components.filter.FILTER_SUBJECTS.MATH);47 expect(location.page.filterIsActiveNotification.rootElement.isDisplayed()).toBeTruthy();48 }49 );50 });51 //it('it remove all values except for language and refresh page', function( done ){52 // browser.sleep(1000).then(done);53 //});...
isDisplayed.js
Source:isDisplayed.js
1/*global module, element, protractor, by, browser, expect*/2(function () {3 'use strict';4 5 module.exports = function () {6 7 this.byId = function (element) {8 expect(element(by.id(element)).isDisplayed()).toBe(true, 'Element is not displayed!');9 };10 11 this.byLinkText = function (element) {12 expect(element(by.linkText(element)).isDisplayed()).toBe(true, 'Element is not displayed!');13 };14 15 this.byPartialLinkText = function (element) {16 expect(element(by.partialLinkText(element)).isDisplayed()).toBe(true, 'Element is not displayed!');17 };18 19 this.byCss = function (element) {20 expect(element(by.css(element)).isDisplayed()).toBe(true, 'Element is not displayed');21 };22 23 this.byModel = function (element) {24 expect(element(by.model(element)).isDisplayed()).toBe(true, 'Element is not displayed');25 };26 27 this.byClassName = function (element) {28 expect(element(by.className(element)).isDisplayed()).toBe(true, 'Element is not displayed');29 };30 31 this.byCssContainingText = function (element, text) {32 expect(element(by.cssContainingText(element, text)).isDisplayed()).toBe(true, 'Element is not displayed');33 };34 35 this.byName = function (element) {36 expect(element(by.name(element)).isDisplayed()).toBe(true, 'Element is not displayed');37 };38 39 this.byBinding = function (element) {40 expect(element(by.binding(element)).isDisplayed()).toBe(true, 'Element is not displayed');41 };42 43 this.byExactBinding = function (element) {44 expect(element(by.exactBinding(element)).isDisplayed()).toBe(true, 'Element is not displayed');45 };46 47 this.byButtonText = function (element) {48 expect(element(by.buttonText(element)).isDisplayed()).toBe(true, 'Element is not displayed');49 };50 51 this.byPartialButtonText = function (element) {52 expect(element(by.partialButtonText(element)).isDisplayed()).toBe(true, 'Element is not displayed');53 };54 55 this.byExactRepeater = function (element) {56 expect(element(by.exactRepeater(element)).isDisplayed()).toBe(true, 'Element is not displayed');57 };58 59 this.byTagName = function (element) {60 expect(element(by.tagName(element)).isDisplayed()).toBe(true, 'Element is not displayed');61 };62 63 this.byXpath = function (element) {64 expect(element(by.xpath(element)).isDisplayed()).toBe(true, 'Element is not displayed');65 };66 };...
isNotDisplayed.js
Source:isNotDisplayed.js
1/*global module, element, protractor, by, browser, expect*/2(function () {3 'use strict';4 5 module.exports = function () {6 7 this.byId = function (element) {8 expect(element(by.id(element)).isDisplayed()).toBe(false, 'Element is displayed!');9 };10 11 this.byLinkText = function (element) {12 expect(element(by.linkText(element)).isDisplayed()).toBe(false, 'Element is displayed!');13 };14 15 this.byPartialLinkText = function (element) {16 expect(element(by.partialLinkText(element)).isDisplayed()).toBe(false, 'Element is displayed!');17 };18 19 this.byCss = function (element) {20 expect(element(by.css(element)).isDisplayed()).toBe(false, 'Element is displayed!');21 };22 23 this.byModel = function (element) {24 expect(element(by.model(element)).isDisplayed()).toBe(false, 'Element is displayed!');25 };26 27 this.byClassName = function (element) {28 expect(element(by.className(element)).isDisplayed()).toBe(false, 'Element is displayed!');29 };30 31 this.byCssContainingText = function (element, text) {32 expect(element(by.cssContainingText(element, text)).isDisplayed()).toBe(false, 'Element is displayed!');33 };34 35 this.byName = function (element) {36 expect(element(by.name(element)).isDisplayed()).toBe(false, 'Element is displayed!');37 };38 39 this.byBinding = function (element) {40 expect(element(by.binding(element)).isDisplayed()).toBe(false, 'Element is displayed!');41 };42 43 this.byExactBinding = function (element) {44 expect(element(by.exactBinding(element)).isDisplayed()).toBe(false, 'Element is displayed!');45 };46 47 this.byButtonText = function (element) {48 expect(element(by.buttonText(element)).isDisplayed()).toBe(false, 'Element is displayed!');49 };50 51 this.byPartialButtonText = function (element) {52 expect(element(by.partialButtonText(element)).isDisplayed()).toBe(false, 'Element is displayed!');53 };54 55 this.byExactRepeater = function (element) {56 expect(element(by.exactRepeater(element)).isDisplayed()).toBe(false, 'Element is displayed!');57 };58 59 this.byTagName = function (element) {60 expect(element(by.tagName(element)).isDisplayed()).toBe(false, 'Element is displayed!');61 };62 63 this.byXpath = function (element) {64 expect(element(by.xpath(element)).isDisplayed()).toBe(false, 'Element is displayed!');65 };66 };...
actionsForWeb.js
Source:actionsForWeb.js
...6 * @param {string} locator 7 */8 click(locator) {9 const element = $(locator);10 if(element.isDisplayed()) {11 element.click();12 } else {13 super.throw_common_err(locator);14 }15 };16 /**17 * @function doubleClick18 * @param {string} locator 19 */20 doubleClick(locator) {21 const element = $(locator);22 if(element.isDisplayed()) {23 element.doubleClick();24 } else {25 super.throw_common_err(locator);26 }27 };28 /**29 * @function setValue30 * @param {string} locator 31 * @param {string} value32 */33 setValue(locator, value) {34 const element = $(locator);35 if(element.isDisplayed()) {36 element.setValue(value);37 } else {38 super.throw_common_err(locator);39 }40 };41 /**42 * @function clear43 * @param {string} locator44 */45 clear(locator) {46 const element = $(locator);47 if(element.isDisplayed()) {48 element.setValue('');49 } else {50 super.throw_common_err(locator);51 }52 };53 /**54 * @function selectByVisibleText55 * @param {string} locator 56 * @param {string} value57 */58 selectByVisibleText(locator, value) {59 const element = $(locator);60 if (element.isDisplayed()) {61 element.selectByVisibleText(value); 62 } else {63 super.throw_common_err(locator);64 }65 };66 /**67 * @function selectByAttribute68 * @param {string} locator 69 * @param {string} attribute70 * @param {string} value71 */72 selectByAttribute(locator, attribute, value) {73 const element = $(locator);74 if (element.isDisplayed()) {75 element.selectByAttribute(attribute, value); 76 } else {77 super.throw_common_err(locator);78 }79 };80 /**81 * @function moveTo82 * @param {string} locator83 */84 moveTo(locator) {85 const element = $(locator);86 if(element.isDisplayed()) {87 element.moveTo();88 } else {89 super.throw_common_err(locator);90 }91 };92 /**93 * @function getText94 * @param {string} locator95 */96 getText(locator) {97 const element = $(locator);98 if(element.isDisplayed()) {99 return element.getText();100 } else {101 super.throw_common_err(locator);102 }103 };104}...
user_registerForm_func.js
Source:user_registerForm_func.js
...13 browser.url(url.baseUrl)14 });15 it('should validate Register button is displayed on the top', () => {16 const element = $(elements.registerButton.selector)17 expect(element.isDisplayed()).true;18 });19 it('should redirect to Register form after click to Register button', () => {20 const element = $(elements.registerButton.selector);21 element.click();22 const h1Text = $('//h1').getText();23 expect(h1Text).eq(elements.registerForm.title);24 25 });26 it('should have correct url', () => {27 const currentUrl = browser.getUrl();28 expect(currentUrl).eq(url.registerUrl);29 });30 it('should have `Real name` field', () => {31 const element = $('//input[@name="name"]');32 expect(element.isDisplayed()).true;33 });34 it('should have `Cell phone number` name field', () => {35 const element = $('//input[@name="phone"]');36 expect(element.isDisplayed()).true;37 });38 it('should have `Email`field', () => {39 const element = $('//input[@name="email"]');40 expect(element.isDisplayed()).true;41 });42 it('should have `Password` field', () =>{43 const element = $('//input[@name="password"]');44 expect(element.isDisplayed()).true;45 });46 it('should have `About` field', () => {47 const element = $('//textarea[@name="about"]');48 expect(element.isDisplayed()).true;49 });50 it('should have `Goals` field', () => {51 const element =$('//textarea[@name="goals"]');52 expect(element.isDisplayed()).true;53 });54 it('shouold have `English Level` field', () =>{55 const element =$('//label[@for="englishLevel"]/../../selector');56 expect(element.isDisplayed()).true;57 });58 59});60describe('User --- Register Form --- Func --- Register new user', () => {61 it('should type `Real name` field', () => {62 const element = $('//input[@name="name"]');63 element.setValue(user.admin.name);64 });65 it('should have `Cell phone number` name field', () =>{66 const element = $('//input[@name="phone"]');67 element.setValue(user.admin.phone);68 });69 it('should have `Email` field', () =>{70 const element = $('//input[@name="email"]');...
postData.spec.js
Source:postData.spec.js
1var mock = require('../../index'), //substitute for require('protractor-http-mock')2 get = require('./get'); 3describe('post data', function(){4 afterEach(function(){5 mock.teardown();6 });7 it('matches post data', function(){8 mock([9 {10 request: {11 path: 'users/new',12 method: 'POST'13 },14 response: {15 status: 400,16 data: {17 error: 'generic response'18 }19 }20 },21 {22 request: {23 path: 'users/new',24 method: 'POST',25 data: {26 name: 'Stewie'27 }28 },29 response: {30 status: 20031 }32 },33 {34 request: {35 path: 'users/new',36 method: 'POST',37 data: 'Brian'38 },39 response: {40 status: 500,41 data: { 42 error: 'no dogs allowed!' 43 }44 }45 }46 ]);47 get();48 var succElement = element(by.binding('ctrl.success'));49 var errElement = element(by.binding('ctrl.error'));50 element(by.css('.form #save')).click();51 expect(succElement.isDisplayed()).toBe(false);52 expect(errElement.isDisplayed()).toBe(true);53 expect(errElement.getText()).toBe('generic response');54 element(by.model('ctrl.newUser')).sendKeys('Stewie');55 element(by.css('.form #save')).click();56 expect(succElement.isDisplayed()).toBe(true);57 expect(errElement.isDisplayed()).toBe(false);58 expect(succElement.getText()).toBe('new user saved: Stewie');59 element(by.model('ctrl.newUser')).sendKeys('Brian');60 element(by.css('.form #save-name')).click();61 expect(succElement.isDisplayed()).toBe(false);62 expect(errElement.isDisplayed()).toBe(true);63 expect(errElement.getText()).toBe('no dogs allowed!');64 });65 it('matches complex post data', function(){66 mock([67 {68 request: {69 path: 'users/new',70 method: 'POST',71 data: {72 group: 'other group'73 }74 },75 response: {76 status: 50077 }78 },79 {80 request: {81 path: 'users/new',82 method: 'POST',83 data: {84 group: 'default',85 users: [86 { name: 'One' },87 { name: 'Two' }88 ]89 }90 },91 response: {92 status: 20093 }94 }95 ]);96 get(); 97 element(by.model('ctrl.newUser')).sendKeys('default');98 element(by.css('.form #add-default')).click();99 var succElement = element(by.binding('ctrl.success'));100 expect(succElement.isDisplayed()).toBe(true);101 expect(succElement.getText()).toBe('new user saved: default');102 });...
Using AI Code Generation
1var webdriver = require('selenium-webdriver'),2 until = webdriver.until;3var driver = new webdriver.Builder()4 .forBrowser('firefox')5 .build();6driver.findElement(By.name('q')).sendKeys('webdriver');7driver.findElement(By.name('btnG')).click();8driver.wait(until.titleIs('webdriver - Google Search'), 1000);9driver.quit();
Using AI Code Generation
1var webdriverio = require('webdriverio');2var options = {3 desiredCapabilities: {4 }5};6 .remote(options)7 .init()8 .getTitle().then(function(title) {9 console.log('Title was: ' + title);10 })11 .end();12var webdriverio = require('webdriverio');13var options = {14 desiredCapabilities: {15 }16};17 .remote(options)18 .init()19 .getTitle().then(function(title) {20 console.log('Title was: ' + title);21 })22 .end();23var webdriverio = require('webdriverio');24var options = {25 desiredCapabilities: {26 }27};28 .remote(options)29 .init()30 .getTitle().then(function(title) {31 console.log('Title was: ' + title);32 })33 .end();34var webdriverio = require('webdriverio');35var options = {36 desiredCapabilities: {37 }38};39 .remote(options)40 .init()41 .getTitle().then(function(title) {42 console.log('Title was: ' + title);43 })44 .end();45var webdriverio = require('webdriverio');46var options = {47 desiredCapabilities: {48 }49};50 .remote(options)51 .init()52 .getTitle().then(function(title) {53 console.log('Title was: ' + title);54 })
Using AI Code Generation
1var webdriver = require('selenium-webdriver');2var driver = new webdriver.Builder()3 .forBrowser('chrome')4 .build();5driver.findElement(webdriver.By.name('q')).sendKeys('webdriver');6driver.findElement(webdriver.By.name('btnG')).click();7driver.wait(function() {8 return driver.getTitle().then(function(title) {9 return title === 'webdriver - Google Search';10 });11}, 1000);12driver.quit();13var webdriver = require('selenium-webdriver');14var driver = new webdriver.Builder()15 .forBrowser('chrome')16 .build();17driver.findElement(webdriver.By.name('q')).sendKeys('webdriver');18driver.findElement(webdriver.By.name('btnG')).click();19driver.wait(function() {20 return driver.getTitle().then(function(title) {21 return title === 'webdriver - Google Search';22 });23}, 1000);24driver.quit();25var webdriver = require('selenium-webdriver');26var driver = new webdriver.Builder()27 .forBrowser('chrome')28 .build();29driver.findElement(webdriver.By.name('q')).sendKeys('webdriver');30driver.findElement(webdriver.By.name('btnG')).click();31driver.wait(function() {32 return driver.getTitle().then(function(title) {33 return title === 'webdriver - Google Search';34 });35}, 1000);36driver.quit();37var webdriver = require('selenium-webdriver');38var driver = new webdriver.Builder()39 .forBrowser('chrome')40 .build();41driver.findElement(webdriver.By.name('q')).sendKeys('webdriver');42driver.findElement(webdriver.By.name('btnG')).click();43driver.wait(function() {44 return driver.getTitle().then(function(title) {45 return title === 'webdriver - Google Search';46 });47}, 1000);48driver.quit();49var webdriver = require('selenium-webdriver');50var driver = new webdriver.Builder()51 .forBrowser('chrome')52 .build();
Using AI Code Generation
1var webdriver = require('selenium-webdriver');2var driver = new webdriver.Builder()3 .forBrowser('chrome')4 .build();5driver.findElement(webdriver.By.name('q')).sendKeys('webdriver');6driver.findElement(webdriver.By.name('btnG')).click();7driver.wait(function() {8 return driver.getTitle().then(function(title) {9 return title === 'webdriver - Google Search';10 });11}, 1000);12driver.quit();13var webdriver = require('selenium-webdriver');14var driver = new webdriver.Builder()15 .forBrowser('chrome')16 .build();17driver.findElement(webdriver.By.name('q')).sendKeys('webdriver');18driver.findElement(webdriver.By.name('btnG')).click();19driver.wait(function() {20 return driver.getTitle().then(function(title) {21 return title === 'webdriver - Google Search';22 });23}, 1000);24driver.quit();25var webdriver = require('selenium-webdriver');26var driver = new webdriver.Builder()27 .forBrowser('chrome')28 .build();29driver.findElement(webdriver.By.name('q')).sendKeys('webdriver');30driver.findElement(webdriver.By.name('btnG')).click();31driver.wait(function() {32 return driver.getTitle().then(function(title) {33 return title === 'webdriver - Google Search';34 });35}, 1000);36driver.quit();37var webdriver = require('selenium-webdriver');38var driver = new webdriver.Builder()39 .forBrowser('chrome')40 .build();41driver.findElement(webdriver.By.name('q')).sendKeys('webdriver');42driver.findElement(webdriver.By.name('btnG')).click();43driver.wait(function() {44 return driver.getTitle().then(function(title) {45 return title === 'webdriver - Google Search';46 });47}, 1000);48driver.quit();49var webdriver = require('selenium-webdriver');50var driver = new webdriver.Builder()51 .forBrowser('chrome')52 .build();
Using AI Code Generation
1var webdriver = require('selenium-webdriver');2 withCapabilities(webdriver.Capabilities.chrome()).build();3driver.findElement(webdriver.By.name('q')).sendKeys('webdriver');4driver.findElement(webdriver.By.name('btnG')).click();5driver.wait(function() {6 return driver.getTitle().then(function(title) {7 return title === 'webdriver - Google Search';8 });9}, 1000);10driver.findElement(webdriver.By.name('q')).isDisplayed().then(function(isVisible) {11 if (isVisible) {12 console.log('Element is visible');13 } else {14 console.log('Element is not visible');15 }16});17driver.quit();18var webdriver = require('selenium-webdriver');19 withCapabilities(webdriver.Capabilities.chrome()).build();20driver.findElement(webdriver.By.name('q')).sendKeys('webdriver');21driver.findElement(webdriver.By.name('btnG')).click();22driver.wait(function() {23 return driver.getTitle().then(function(title) {24 return title === 'webdriver - Google Search';25 });26}, 1000);27driver.findElement(webdriver.By.name('q')).isDisplayed().then(function(isVisible) {28 if (isVisible) {29 console.log('Element is visible');30 } else {31 console.log('Element is not visible');32 }33});34driver.findElement(webdriver.By.name('btnG')).isEnabled().then(function(isEnabled) {35 if (isEnabled) {36 console.log('Element is enabled');37 } else {38 console.log('Element is not enabled');39 }40});41driver.quit();42var webdriver = require('selenium-webdriver');43 withCapabilities(webdriver.Capabilities.chrome()).build();44driver.findElement(webdriver.By.name('q')).sendKeys('webdriver');45driver.findElement(webdriver.By.name('btnG')).click();46driver.wait(function() {47 return driver.getTitle().then(function(title) {
Using AI Code Generation
1var webdriver = require('selenium-webdriver');2var driver = new webdriver.Builder()3 .withCapabilities({4 })5 .build();6driver.findElement(webdriver.By.name('q')).sendKeys('webdriver');7driver.findElement(webdriver.By.name('btnG')).click();8driver.wait(function() {9 return driver.getTitle().then(function(title) {10 return title === 'webdriver - Google Search';11 });12}, 1000);13var el = driver.findElement(webdriver.By.id('hplogo'));14el.isDisplayed().then(function(isDisplayed) {15 console.log('isDisplayed', isDisplayed);16});17driver.quit();18var webdriver = require('selenium-webdriver');19var driver = new webdriver.Builder()20 .withCapabilities({21 })22 .build();23driver.findElement(webdriver.By.name('q')).sendKeys('webdriver');24driver.findElement(webdriver.By.name('btnG')).click();25driver.wait(function() {26 return driver.getTitle().then(function(title) {27 return title === 'webdriver - Google Search';28 });29}, 1000);30var el = driver.findElement(webdriver.By.id('hplogo'));31el.isDisplayed().then(function(isDisplayed) {32 console.log('isDisplayed', isDisplayed);33});34driver.quit();
Using AI Code Generation
1console.log(element.isDisplayed());2console.log(element.getText());3console.log(element.getAttribute('name'));4console.log(element.getSize());5console.log(element.getLocation());6console.log(element.getTagName());7console.log(element.getRect());8console.log(element.getCssValue('name'));9element.clear();10element.click();11element.sendKeys('text');12element.submit();13element.touchAction([14 { action: 'press', options: { x: 100, y: 200 } },15 { action: 'moveTo', options: { x: 100, y: 300 } },16]);17element.touchPerform([18 { action: 'press', options: { x: 100, y: 200 } },19 { action: 'moveTo', options: { x: 100, y: 300 } },20]);21element.performMultiAction([22 { action: 'press', options: { x: 100,
Using AI Code Generation
1var expect = require("chai").expect;2var webdriverio = require("webdriverio");3var wdioChai = require("wdio-chai");4var wdioChaiAsPromised = require("wdio-chai-as-promised");5var wdioExpect = require("wdio-expect");6var wdioShould = require("wdio-should");7var wdioAssert = require("wdio-assert");8var wdioScreenshot = require("wdio-screenshot");
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!!