Best JavaScript code snippet using chrominator
SideNavigationPage.po.ts
Source:SideNavigationPage.po.ts
1/*2 * Licensed to the Apache Software Foundation (ASF) under one3 * or more contributor license agreements. See the NOTICE file4 * distributed with this work for additional information5 * regarding copyright ownership. The ASF licenses this file6 * to you under the Apache License, Version 2.0 (the7 * "License"); you may not use this file except in compliance8 * with the License. You may obtain a copy of the License at9 *10 * http://www.apache.org/licenses/LICENSE-2.011 *12 * Unless required by applicable law or agreed to in writing,13 * software distributed under the License is distributed on an14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY15 * KIND, either express or implied. See the License for the16 * specific language governing permissions and limitations17 * under the License.18 */19import { browser, by, element, ExpectedConditions } from 'protractor';20import { BasePage } from './BasePage.po';21export class SideNavigationPage extends BasePage{22 //Navigation for Configure23 private propConfigure = "//div[@id='sidebar-menu']//a[contains(text(),'Configure')]";24 private mnuConfigure = element(by.xpath( this.propConfigure ))25 private lnkServers = element(by.xpath("(//a[@href='/#!/servers'])[1]"));26 private lnkServerCapabilities = element(by.xpath("//a[@href='/#!/server-capabilities']"));27 private lnkOrigins = element(by.xpath("//a[@href='/#!/origins']"));28 private lnkProfiles = element(by.xpath("//a[@href='/#!/profiles']"));29 private lnkParameters = element(by.xpath("//a[@href='/#!/parameters']"))30 private lnkTypes = element(by.xpath("//a[@href='/#!/types']"))31 private lnkStatuses = element(by.xpath("//a[@href='/#!/statuses']"))32 //Navigation for Services33 private propServices = "//div[@id='sidebar-menu']//a[text()=' Services']"34 private mnuServices = element(by.xpath( this.propServices ));35 private lnkDeliveryServices = element(by.xpath("//a[@href='/#!/delivery-services']"));36 private lnkDeliveryServiceRequest = element(by.xpath("//a[@href='/#!/delivery-service-requests']"));37 private lnkServiceCategories = element(by.xpath("//a[@href='/#!/service-categories']"));38 private lnkCertExpirations = element(by.id("cert-expirations"));39 //Navigation for Users Admin40 private propUserAdmin = "//div[@id='sidebar-menu']//a[contains(text(),'User Admin')]"41 private mnuUserAdmin = element(by.xpath( this.propUserAdmin ))42 private lnkTenants = element(by.xpath("//a[@href='/#!/tenants']"));43 private lnkUsers = element(by.xpath("//a[@href='/#!/users']"));44 //Navigation for CDNs45 private propCDN = "//div[@id='sidebar-menu']//a[contains(text(),'CDNs')]";46 private mnuCDN = element(by.xpath(this.propCDN))47 //Navigation for Topology48 private propTopology = "//div[@id='sidebar-menu']//a[contains(text(),'Topology')]"49 private mnuTopology = element(by.xpath( this.propTopology ))50 private lnkPhysLocations = element(by.linkText('Phys Locations'))51 private lnkDivisions = element(by.xpath("//a[@href='/#!/divisions']"));52 private lnkTopologies = element(by.xpath("//a[@href='/#!/topologies']"));53 private lnkCacheGroups = element(by.xpath("//a[@href='/#!/cache-groups']"));54 private lnkCoordinates = element(by.xpath("//a[@href='/#!/coordinates']"));55 private lnkRegions = element(by.xpath("//a[@href='/#!/regions']"));56 private lnkASNs = element(by.xpath("//a[@href='/#!/asns']"));57 //Navigation for Jobs58 private mnuTools = element(by.cssContainingText("#sidebar-menu a", "Tools"))59 private lnkJobs = element(by.linkText("Invalidate Content"))60 async ClickConfigureMenu(){61 await browser.wait(ExpectedConditions.visibilityOf(this.mnuConfigure), 2000);62 await this.mnuConfigure.click();63 }64 async ClickUserAdminMenu(){65 await browser.wait(ExpectedConditions.visibilityOf(this.mnuUserAdmin), 2000);66 await this.mnuUserAdmin.click();67 }68 async ClickServicesMenu(){69 await browser.wait(ExpectedConditions.visibilityOf(this.mnuServices), 2000);70 await this.mnuServices.click();71 }72 async ClickTopologyMenu(){73 await browser.wait(ExpectedConditions.visibilityOf(this.mnuTopology), 2000);74 await this.mnuTopology.click();75 }76 async ClickToolsMenu(){77 await browser.wait(ExpectedConditions.visibilityOf(this.mnuTools), 2000);78 await this.mnuTools.click();79 }80 async NavigateToTopologiesPage(){81 await browser.wait(ExpectedConditions.visibilityOf(this.lnkTopologies), 2000);82 await browser.actions().mouseMove(this.lnkTopologies).perform();83 await browser.actions().click(this.lnkTopologies).perform();84 }85 async NavigateToDivisionsPage(){86 await browser.wait(ExpectedConditions.visibilityOf(this.lnkDivisions), 2000);87 await browser.actions().mouseMove(this.lnkDivisions).perform();88 await browser.actions().click(this.lnkDivisions).perform();89 }90 async NavigateToRegionsPage(){91 await browser.wait(ExpectedConditions.visibilityOf(this.lnkRegions), 2000);92 await browser.actions().mouseMove(this.lnkRegions).perform();93 await browser.actions().click(this.lnkRegions).perform();94 }95 async NavigateToASNsPage(){96 await browser.wait(ExpectedConditions.visibilityOf(this.lnkASNs), 2000);97 await browser.actions().mouseMove(this.lnkASNs).perform();98 await browser.actions().click(this.lnkASNs).perform();99 }100 async NavigateToCacheGroupsPage(){101 await browser.wait(ExpectedConditions.visibilityOf(this.lnkCacheGroups), 2000);102 await browser.actions().mouseMove(this.lnkCacheGroups).perform();103 await browser.actions().click(this.lnkCacheGroups).perform();104 }105 async NavigateToCoordinatesPage(){106 await browser.wait(ExpectedConditions.visibilityOf(this.lnkCoordinates), 2000);107 await browser.actions().mouseMove(this.lnkCoordinates).perform();108 await browser.actions().click(this.lnkCoordinates).perform();109 }110 async NavigateToServersPage(){111 await browser.wait(ExpectedConditions.visibilityOf(this.lnkServers), 2000);112 await browser.actions().mouseMove(this.lnkServers).perform();113 await browser.actions().click(this.lnkServers).perform();114 }115 async NavigateToServerCapabilitiesPage(){116 await browser.wait(ExpectedConditions.visibilityOf(this.lnkServerCapabilities), 2000);117 await browser.actions().mouseMove(this.lnkServerCapabilities).perform();118 await browser.actions().click(this.lnkServerCapabilities).perform();119 }120 async NavigateToOriginsPage(){121 await browser.wait(ExpectedConditions.visibilityOf(this.lnkOrigins), 2000);122 await browser.actions().mouseMove(this.lnkOrigins).perform();123 await browser.actions().click(this.lnkOrigins).perform();124 }125 async NavigateToProfilesPage() {126 await browser.wait(ExpectedConditions.visibilityOf(this.lnkProfiles), 2000);127 await browser.actions().mouseMove(this.lnkProfiles).perform();128 await browser.actions().click(this.lnkProfiles).perform();129 }130 async NavigateToParametersPage() {131 await browser.wait(ExpectedConditions.visibilityOf(this.lnkParameters), 2000);132 await browser.actions().mouseMove(this.lnkParameters).perform();133 await browser.actions().click(this.lnkParameters).perform();134 }135 async NavigateToTypesPage(){136 await browser.wait(ExpectedConditions.visibilityOf(this.lnkTypes), 2000);137 await browser.actions().mouseMove(this.lnkTypes).perform();138 await browser.actions().click(this.lnkTypes).perform();139 }140 async NavigateToStatusesPage(){141 await browser.wait(ExpectedConditions.visibilityOf(this.lnkStatuses), 2000);142 await browser.actions().mouseMove(this.lnkStatuses).perform();143 await browser.actions().click(this.lnkStatuses).perform();144 }145 async NavigateToDeliveryServicesPage() {146 await browser.wait(ExpectedConditions.visibilityOf(this.lnkDeliveryServices), 2000);147 await browser.actions().mouseMove(this.lnkDeliveryServices).perform();148 await browser.actions().click(this.lnkDeliveryServices).perform();149 }150 async NavigateToDeliveryServicesRequestsPage(){151 await browser.wait(ExpectedConditions.visibilityOf(this.lnkDeliveryServiceRequest), 2000);152 await browser.actions().mouseMove(this.lnkDeliveryServiceRequest).perform();153 await browser.actions().click(this.lnkDeliveryServiceRequest).perform();154 }155 async NavigateToServiceCategoriesPage(){156 await browser.wait(ExpectedConditions.visibilityOf(this.lnkServiceCategories), 2000);157 await browser.actions().mouseMove(this.lnkServiceCategories).perform();158 await browser.actions().click(this.lnkServiceCategories).perform();159 }160 /** NavigateToCertExpirationsPage verifies that the link to the Certificate Expirations page is clickable. */161 public async NavigateToCertExpirationsPage(): Promise<void>{162 return this.lnkCertExpirations.click();163 }164 async NavigateToUsersPage(){165 await browser.wait(ExpectedConditions.visibilityOf(this.lnkUsers), 2000);166 await browser.actions().mouseMove(this.lnkUsers).perform();167 await browser.actions().click(this.lnkUsers).perform();168 }169 async NavigateToTenantsPage(){170 await browser.wait(ExpectedConditions.visibilityOf(this.lnkTenants), 2000);171 await browser.actions().mouseMove(this.lnkTenants).perform();172 await browser.actions().click(this.lnkTenants).perform();173 }174 async NavigateToCDNPage(){175 await browser.wait(ExpectedConditions.visibilityOf(this.mnuCDN), 2000);176 await browser.actions().mouseMove(this.mnuCDN).perform();177 await browser.actions().click(this.mnuCDN).perform();178 }179 async NavigateToPhysLocation(){180 await browser.wait(ExpectedConditions.visibilityOf(this.lnkPhysLocations), 2000);181 await browser.actions().mouseMove(this.lnkPhysLocations).perform();182 await browser.actions().click(this.lnkPhysLocations).perform();183 }184 async NavigateToJobsPage(){185 await browser.wait(ExpectedConditions.visibilityOf(this.lnkJobs), 2000);186 await browser.actions().mouseMove(this.lnkJobs).perform();187 await browser.actions().click(this.lnkJobs).perform();188 }...
buyAnItem.spec.ts
Source:buyAnItem.spec.ts
1import { browser, ExpectedConditions } from 'protractor';2import { MainPage, SignInFormModalPage, CheckoutPage, SuccessPage } from '../../src/ui/index';3import { expect } from 'chai';4var superagent = require('superagent');56describe('When buying an item', () => {7 const expectedConditions = ExpectedConditions;8 const mainPage = new MainPage();9 const signInFormModalPage = new SignInFormModalPage();10 const checkoutPage = new CheckoutPage();11 const successPage = new SuccessPage();1213 describe('Before buying an item', ()=> {1415 it("first, it should delete all users to avoid possible problems", (function (done) {16 superagent.del('http://ec2-3-144-243-225.us-east-2.compute.amazonaws.com:8080/')17 .set("User-Agent", "agent")18 .set("Content-Type", "application/json")19 .end(done)20 }));2122 it("then, the API should create an user to be able to complete the purchase", (function (done) {23 superagent.post('http://ec2-3-144-243-225.us-east-2.compute.amazonaws.com:8080/')24 .set("User-Agent", "agent")25 .set("Content-Type", "application/json")26 .send({27 customerId: 0,28 name: "Paco",29 address: "123 malibú, polo norte",30 email: "paco@example.com",31 phone: "123 456 7890",32 username: "u",33 password: "u",34 enabled: "true",35 role: "USER",36 })37 .end(done)38 }));3940 it ('it should get the page', async () => {41 await browser.get('http://ec2-3-144-243-225.us-east-2.compute.amazonaws.com:8080/');42 expect(await browser.getTitle()).to.equal('Atsea Shop');43 });44 it('then it should log in an user', async () => {45 await browser.wait(expectedConditions.elementToBeClickable(mainPage.getBtnSignIn()));46 await mainPage.clickBtnSignIn()47 await browser.wait(expectedConditions.presenceOf(mainPage.getSigInForm()));48 await browser.wait(expectedConditions.elementToBeClickable(signInFormModalPage.getUsernameField()));49 await signInFormModalPage.fillUsernameField("u");50 await browser.wait(expectedConditions.elementToBeClickable(signInFormModalPage.getPasswordField()));51 await signInFormModalPage.fillPasswordField("u");52 await browser.wait(expectedConditions.elementToBeClickable(signInFormModalPage.getBtnSubmitUserData()), 3000)53 await signInFormModalPage.submitUserData();54 await browser.wait(expectedConditions.presenceOf(mainPage.getWelcomeMessage()));55 56 expect(mainPage.getWelcomeMessage().getText()).to.equal('Welcome!');57 58 })59 it('then it should add an item to the cart and proceed to checkout', async() => {60 await browser.wait(expectedConditions.elementToBeClickable(mainPage.getAddProductBtn()));61 await mainPage.ClickAddBtn();62 await browser.wait(expectedConditions.elementToBeClickable(mainPage.getCheckoutBtn()));63 await mainPage.clickCheckoutBtn();64 await browser.wait(expectedConditions.presenceOf(checkoutPage.getCheckouPageTitle()));65 })66 it('then it should finish the order', async ()=> {67 await browser.wait(expectedConditions.elementToBeClickable(checkoutPage.getBtnCompleteOrder()));68 await checkoutPage.clickBtnCompleteOrder();69 await browser.wait(expectedConditions.presenceOf(successPage.getSuccessMessage()));70 //expect(successPage.getSuccessMessage().innerText()).to.equal('You have successfully placed an order!');71 })72 it('after, it should go back to the main page', async()=>{73 await browser.wait(expectedConditions.elementToBeClickable(successPage.getContinueShoppingBtn()));74 await successPage.clickContinueShoppingBtn();75 await browser.wait(expectedConditions.presenceOf(mainPage.getPageTitle()));76 })77 it('it should log out', async () => {78 await browser.wait(expectedConditions.presenceOf(mainPage.getWelcomeMessage()));79 await browser.wait(expectedConditions.elementToBeClickable(mainPage.getBtnSignOut()));80 await mainPage.clickBtnSignOut();81 await browser.wait(expectedConditions.presenceOf(mainPage.getBtnCreateUser()));82 })83 });
...
table-field.e2e.spec.ts
Source:table-field.e2e.spec.ts
1import {browser, by, element, ExpectedConditions, Key} from 'protractor';2describe('ajf-table-field', () => {3 beforeEach(async () => await browser.get('/mat-table-field'));4 it('should show a table field', async () => {5 expect(await element(by.className('ajf-table-field')).isPresent()).toBe(true);6 const cells = await element.all(by.tagName('td')).getWebElements();7 expect(cells.length).toBe(12);8 cells.forEach(async cell => console.log(await cell.getText()));9 expect(await cells[0].getText()).toBe('2.1');10 expect(await cells[4].getText()).toBe('Row 1');11 expect(await cells[8].getText()).toBe('Row 2');12 });13 it('should show table header', async () => {14 const cells = await element.all(by.tagName('td')).getWebElements();15 cells.forEach(async cell => console.log(await cell.getText()));16 expect(await cells[1].getText()).toBe('Label 1');17 expect(await cells[2].getText()).toBe('Label 2');18 expect(await cells[3].getText()).toBe('Label 3');19 });20 it('should show an input on data cell click', async () => {21 const cells = await element.all(by.tagName('td')).getWebElements();22 await cells[0].click();23 await browser.wait(24 ExpectedConditions.not(ExpectedConditions.presenceOf(element(by.css('input')))));25 await cells[5].click();26 await browser.wait(ExpectedConditions.presenceOf(element(by.css('input'))));27 });28 it('should go to next cell when pressed the tab key in input', async () => {29 const cells = await element.all(by.tagName('td')).getWebElements();30 await cells[5].click();31 await browser.wait(ExpectedConditions.presenceOf(32 element(by.css('tr:nth-of-type(2) td:nth-of-type(2) input'))));33 let input = element(by.css('input'));34 expect(await input.isPresent()).toBe(true);35 await input.sendKeys(Key.TAB);36 await browser.wait(ExpectedConditions.not(ExpectedConditions.presenceOf(37 element(by.css('tr:nth-of-type(2) td:nth-of-type(2) input')))));38 await browser.wait(ExpectedConditions.presenceOf(39 element(by.css('tr:nth-of-type(2) td:nth-of-type(3) input'))));40 });...
Using AI Code Generation
1var chrominator = require('chrominator');2 .init()3 .setViewport({width: 1024, height: 768})4 .type('#lst-ib', 'webdriver')5 .click('input[value="Google Search"]')6 .waitForElementVisible('#resultStats')7 .end();8#### `init()`9#### `setViewport(options)`10#### `goto(url)`11#### `type(selector, text)`12#### `click(selector)`13#### `waitForElementVisible(selector)`14#### `end()`15#### `chrominator.init()`16chrominator.init();17#### `chrominator.setViewport(options)`18chrominator.setViewport({19});20#### `chrominator.goto(url)`21#### `chrominator.type(selector, text)`22chrominator.type('#lst-ib', 'webdriver');23#### `chrominator.click(selector)`24chrominator.click('input[value="Google Search"]');25#### `chrominator.waitForElementVisible(selector)`26chrominator.waitForElementVisible('#resultStats');27#### `chrominator.end()`
Using AI Code Generation
1var chrominator = require('chrominator');2var assert = require('assert');3var By = chrominator.By;4var until = chrominator.until;5chrominator.run(function(){6 return chrominator.createBrowser()7 .findElement(By.name('q'))8 .sendKeys('webdriver')9 .findElement(By.name('btnG'))10 .click()11 .then(function(){12 return chrominator.wait(until.titleIs('webdriver - Google Search'), 1000);13 })14 .then(function(){15 return chrominator.getTitle().then(function(title){16 assert.equal(title, 'webdriver - Google Search');17 });18 })19 .then(function(){20 return chrominator.wait(until.elementIsVisible(chrominator.findElement(By.id('resultStats'))), 1000);21 })22 .then(function(){23 return chrominator.findElement(By.id('resultStats')).isDisplayed().then(function(isVisible){24 assert.equal(isVisible, true);25 });26 })27 .then(function(){28 return chrominator.wait(until.elementIsEnabled(chrominator.findElement(By.id('resultStats'))), 1000);29 })30 .then(function(){31 return chrominator.findElement(By.id('resultStats')).isEnabled().then(function(isEnabled){32 assert.equal(isEnabled, true);33 });34 })35 .then(function(){36 return chrominator.wait(until.elementIsSelected(chrominator.findElement(By.id('resultStats'))), 1000);37 })38 .then(function(){39 return chrominator.findElement(By.id('resultStats')).isSelected().then(function(isSelected){40 assert.equal(isSelected, true);41 });42 })43 .then(function(){44 return chrominator.wait(until.elementContainsText(chrominator.findElement(By.id('resultStats')),
Using AI Code Generation
1var chrominator = require('chrominator');2var EC = chrominator.ExpectedConditions;3chrominator.create(function (err, chrome) {4 .then(chrome.findElement({ name: 'q' }))5 .then(function (element) {6 chrome.sendKeys(element, 'Hello World');7 chrome.wait(EC.elementToBeClickable(element), 10000);8 });9});
Using AI Code Generation
1var chrominator = require('chrominator');2var By = chrominator.By;3var until = chrominator.until;4chrominator.run(function*() {5 yield this.driver.findElement(By.name('q')).sendKeys('webdriver');6 yield this.driver.wait(until.elementIsVisible(By.name('btnG')), 10000);7 yield this.driver.findElement(By.name('btnG')).click();8 yield this.driver.wait(until.titleIs('webdriver - Google Search'), 10000);9 yield this.driver.quit();10});
Using AI Code Generation
1var chrominator = require('chrominator');2var ec = chrominator.ExpectedConditions;3chrominator.createBrowser()4 .then(function() {5 return chrominator.wait(ec.titleIs('Google'));6 })7 .then(function() {8 return chrominator.wait(ec.titleContains('oogle'));9 })10 .then(function() {11 return chrominator.wait(ec.titleIs('Google'));12 })13 .then(function() {14 return chrominator.wait(ec.titleIs('Google'));15 })16 .then(function() {17 return chrominator.wait(ec.titleIs('Google'));18 })19 .then(function() {20 return chrominator.wait(ec.titleIs('Google'));21 })22 .then(function() {23 return chrominator.wait(ec.titleIs('Google'));24 })25 .then(function() {26 return chrominator.wait(ec.titleIs('Google'));27 })28 .then(function() {29 return chrominator.wait(ec.titleIs('Google'));30 })31 .then(function() {32 return chrominator.wait(ec.titleIs('Google'));33 })34 .then(function() {35 return chrominator.wait(ec.titleIs('Google'));36 })37 .then(function() {38 return chrominator.wait(ec.titleIs('Google'));39 })40 .end();41#### titleIs(title)42#### titleContains(title)43#### urlContains(url)44#### urlMatches(url)45#### elementIsVisible(element)46#### elementIsNotVisible(element)
Using AI Code Generation
1const chrominator = require('chrominator');2chrominator.launch({ headless: false }).then(async browser => {3 const page = await browser.newPage();4 await page.waitForSelector('input[name="q"]');5 await page.type('input[name="q"]', 'Chrominator');6 await page.click('input[name="btnK"]');7 await page.waitForSelector('h3');8 await page.screenshot({ path: 'test.png' });9 await browser.close();10});
Using AI Code Generation
1var chrominator = require('chrominator');2chrominator.start({3})4.wait(2000)5.then(function(){6 chrominator.sendKeys('input[name="q"]', 'Hello World!')7 .then(function(){8 chrominator.sendKeys('input[name="q"]', chrominator.Key.ENTER)9 .then(function(){10 chrominator.takeScreenshot('screenshot.png')11 .then(function(){12 chrominator.stop();13 });14 });15 });16});
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!!