Best JavaScript code snippet using appium-xcuitest-driver
clusters_bundle_spec.js
Source:clusters_bundle_spec.js
1import MockAdapter from 'axios-mock-adapter';2import { loadHTMLFixture } from 'helpers/fixtures';3import { setTestTimeout } from 'helpers/timeout';4import Clusters from '~/clusters/clusters_bundle';5import { APPLICATION_STATUS, APPLICATIONS, RUNNER } from '~/clusters/constants';6import axios from '~/lib/utils/axios_utils';7import initProjectSelectDropdown from '~/project_select';8jest.mock('~/lib/utils/poll');9jest.mock('~/project_select');10const { INSTALLING, INSTALLABLE, INSTALLED, UNINSTALLING } = APPLICATION_STATUS;11describe('Clusters', () => {12 setTestTimeout(1000);13 let cluster;14 let mock;15 const mockGetClusterStatusRequest = () => {16 const { statusPath } = document.querySelector('.js-edit-cluster-form').dataset;17 mock = new MockAdapter(axios);18 mock.onGet(statusPath).reply(200);19 };20 beforeEach(() => {21 loadHTMLFixture('clusters/show_cluster.html');22 });23 beforeEach(() => {24 mockGetClusterStatusRequest();25 });26 beforeEach(() => {27 cluster = new Clusters();28 });29 afterEach(() => {30 cluster.destroy();31 mock.restore();32 });33 describe('class constructor', () => {34 beforeEach(() => {35 jest.spyOn(Clusters.prototype, 'initPolling');36 cluster = new Clusters();37 });38 it('should call initPolling on construct', () => {39 expect(cluster.initPolling).toHaveBeenCalled();40 });41 it('should call initProjectSelectDropdown on construct', () => {42 expect(initProjectSelectDropdown).toHaveBeenCalled();43 });44 });45 describe('checkForNewInstalls', () => {46 const INITIAL_APP_MAP = {47 helm: { status: null, title: 'Helm Tiller' },48 ingress: { status: null, title: 'Ingress' },49 runner: { status: null, title: 'GitLab Runner' },50 };51 it('does not show alert when things transition from initial null state to something', () => {52 cluster.checkForNewInstalls(INITIAL_APP_MAP, {53 ...INITIAL_APP_MAP,54 helm: { status: INSTALLABLE, title: 'Helm Tiller' },55 });56 const flashMessage = document.querySelector('.js-cluster-application-notice .flash-text');57 expect(flashMessage).toBeNull();58 });59 it('shows an alert when something gets newly installed', () => {60 cluster.checkForNewInstalls(61 {62 ...INITIAL_APP_MAP,63 helm: { status: INSTALLING, title: 'Helm Tiller' },64 },65 {66 ...INITIAL_APP_MAP,67 helm: { status: INSTALLED, title: 'Helm Tiller' },68 },69 );70 const flashMessage = document.querySelector('.js-cluster-application-notice .flash-text');71 expect(flashMessage).not.toBeNull();72 expect(flashMessage.textContent.trim()).toEqual(73 'Helm Tiller was successfully installed on your Kubernetes cluster',74 );75 });76 it('shows an alert when multiple things gets newly installed', () => {77 cluster.checkForNewInstalls(78 {79 ...INITIAL_APP_MAP,80 helm: { status: INSTALLING, title: 'Helm Tiller' },81 ingress: { status: INSTALLABLE, title: 'Ingress' },82 },83 {84 ...INITIAL_APP_MAP,85 helm: { status: INSTALLED, title: 'Helm Tiller' },86 ingress: { status: INSTALLED, title: 'Ingress' },87 },88 );89 const flashMessage = document.querySelector('.js-cluster-application-notice .flash-text');90 expect(flashMessage).not.toBeNull();91 expect(flashMessage.textContent.trim()).toEqual(92 'Helm Tiller, Ingress was successfully installed on your Kubernetes cluster',93 );94 });95 });96 describe('updateContainer', () => {97 const { location } = window;98 beforeEach(() => {99 delete window.location;100 window.location = {101 reload: jest.fn(),102 hash: location.hash,103 };104 });105 afterEach(() => {106 window.location = location;107 });108 describe('when creating cluster', () => {109 it('should show the creating container', () => {110 cluster.updateContainer(null, 'creating');111 expect(cluster.creatingContainer.classList.contains('hidden')).toBeFalsy();112 expect(cluster.successContainer.classList.contains('hidden')).toBeTruthy();113 expect(cluster.errorContainer.classList.contains('hidden')).toBeTruthy();114 expect(window.location.reload).not.toHaveBeenCalled();115 });116 it('should continue to show `creating` banner with subsequent updates of the same status', () => {117 cluster.updateContainer(null, 'creating');118 cluster.updateContainer('creating', 'creating');119 expect(cluster.creatingContainer.classList.contains('hidden')).toBeFalsy();120 expect(cluster.successContainer.classList.contains('hidden')).toBeTruthy();121 expect(cluster.errorContainer.classList.contains('hidden')).toBeTruthy();122 expect(window.location.reload).not.toHaveBeenCalled();123 });124 });125 describe('when cluster is created', () => {126 it('should hide the "creating" banner and refresh the page', () => {127 jest.spyOn(cluster, 'setClusterNewlyCreated');128 cluster.updateContainer(null, 'creating');129 cluster.updateContainer('creating', 'created');130 expect(cluster.creatingContainer.classList.contains('hidden')).toBeTruthy();131 expect(cluster.successContainer.classList.contains('hidden')).toBeTruthy();132 expect(cluster.errorContainer.classList.contains('hidden')).toBeTruthy();133 expect(window.location.reload).toHaveBeenCalled();134 expect(cluster.setClusterNewlyCreated).toHaveBeenCalledWith(true);135 });136 it('when the page is refreshed, it should show the "success" banner', () => {137 jest.spyOn(cluster, 'setClusterNewlyCreated');138 jest.spyOn(cluster, 'isClusterNewlyCreated').mockReturnValue(true);139 cluster.updateContainer(null, 'created');140 cluster.updateContainer('created', 'created');141 expect(cluster.creatingContainer.classList.contains('hidden')).toBeTruthy();142 expect(cluster.successContainer.classList.contains('hidden')).toBeFalsy();143 expect(cluster.errorContainer.classList.contains('hidden')).toBeTruthy();144 expect(window.location.reload).not.toHaveBeenCalled();145 expect(cluster.setClusterNewlyCreated).toHaveBeenCalledWith(false);146 });147 it('should not show a banner when status is already `created`', () => {148 jest.spyOn(cluster, 'setClusterNewlyCreated');149 jest.spyOn(cluster, 'isClusterNewlyCreated').mockReturnValue(false);150 cluster.updateContainer(null, 'created');151 cluster.updateContainer('created', 'created');152 expect(cluster.creatingContainer.classList.contains('hidden')).toBeTruthy();153 expect(cluster.successContainer.classList.contains('hidden')).toBeTruthy();154 expect(cluster.errorContainer.classList.contains('hidden')).toBeTruthy();155 expect(window.location.reload).not.toHaveBeenCalled();156 expect(cluster.setClusterNewlyCreated).not.toHaveBeenCalled();157 });158 });159 describe('when cluster has error', () => {160 it('should show the error container', () => {161 cluster.updateContainer(null, 'errored', 'this is an error');162 expect(cluster.creatingContainer.classList.contains('hidden')).toBeTruthy();163 expect(cluster.successContainer.classList.contains('hidden')).toBeTruthy();164 expect(cluster.errorContainer.classList.contains('hidden')).toBeFalsy();165 expect(cluster.errorReasonContainer.textContent).toContain('this is an error');166 });167 it('should show `error` banner when previously `creating`', () => {168 cluster.updateContainer('creating', 'errored');169 expect(cluster.creatingContainer.classList.contains('hidden')).toBeTruthy();170 expect(cluster.successContainer.classList.contains('hidden')).toBeTruthy();171 expect(cluster.errorContainer.classList.contains('hidden')).toBeFalsy();172 });173 });174 describe('when cluster is unreachable', () => {175 it('should show the unreachable warning container', () => {176 cluster.updateContainer(null, 'unreachable');177 expect(cluster.unreachableContainer.classList.contains('hidden')).toBe(false);178 });179 });180 describe('when cluster has an authentication failure', () => {181 it('should show the authentication failure warning container', () => {182 cluster.updateContainer(null, 'authentication_failure');183 expect(cluster.authenticationFailureContainer.classList.contains('hidden')).toBe(false);184 });185 });186 });187 describe('installApplication', () => {188 it.each(APPLICATIONS)('tries to install %s', (applicationId, done) => {189 jest.spyOn(cluster.service, 'installApplication').mockResolvedValue();190 cluster.store.state.applications[applicationId].status = INSTALLABLE;191 const params = {};192 if (applicationId === 'knative') {193 params.hostname = 'test-example.com';194 }195 // eslint-disable-next-line promise/valid-params196 cluster197 .installApplication({ id: applicationId, params })198 .then(() => {199 expect(cluster.store.state.applications[applicationId].status).toEqual(INSTALLING);200 expect(cluster.store.state.applications[applicationId].requestReason).toEqual(null);201 expect(cluster.service.installApplication).toHaveBeenCalledWith(applicationId, params);202 done();203 })204 .catch();205 });206 it('sets error request status when the request fails', () => {207 jest208 .spyOn(cluster.service, 'installApplication')209 .mockRejectedValueOnce(new Error('STUBBED ERROR'));210 cluster.store.state.applications.helm.status = INSTALLABLE;211 const promise = cluster.installApplication({ id: 'helm' });212 return promise.then(() => {213 expect(cluster.store.state.applications.helm.status).toEqual(INSTALLABLE);214 expect(cluster.store.state.applications.helm.installFailed).toBe(true);215 expect(cluster.store.state.applications.helm.requestReason).toBeDefined();216 });217 });218 });219 describe('uninstallApplication', () => {220 it.each(APPLICATIONS)('tries to uninstall %s', applicationId => {221 jest.spyOn(cluster.service, 'uninstallApplication').mockResolvedValueOnce();222 cluster.store.state.applications[applicationId].status = INSTALLED;223 cluster.uninstallApplication({ id: applicationId });224 expect(cluster.store.state.applications[applicationId].status).toEqual(UNINSTALLING);225 expect(cluster.store.state.applications[applicationId].requestReason).toEqual(null);226 expect(cluster.service.uninstallApplication).toHaveBeenCalledWith(applicationId);227 });228 it('sets error request status when the uninstall request fails', () => {229 jest230 .spyOn(cluster.service, 'uninstallApplication')231 .mockRejectedValueOnce(new Error('STUBBED ERROR'));232 cluster.store.state.applications.helm.status = INSTALLED;233 const promise = cluster.uninstallApplication({ id: 'helm' });234 return promise.then(() => {235 expect(cluster.store.state.applications.helm.status).toEqual(INSTALLED);236 expect(cluster.store.state.applications.helm.uninstallFailed).toBe(true);237 expect(cluster.store.state.applications.helm.requestReason).toBeDefined();238 });239 });240 });241 describe('fetch cluster environments success', () => {242 beforeEach(() => {243 jest.spyOn(cluster.store, 'toggleFetchEnvironments').mockReturnThis();244 jest.spyOn(cluster.store, 'updateEnvironments').mockReturnThis();245 cluster.handleClusterEnvironmentsSuccess({ data: {} });246 });247 it('toggles the cluster environments loading icon', () => {248 expect(cluster.store.toggleFetchEnvironments).toHaveBeenCalled();249 });250 it('updates the store when cluster environments is retrieved', () => {251 expect(cluster.store.updateEnvironments).toHaveBeenCalled();252 });253 });254 describe('handleClusterStatusSuccess', () => {255 beforeEach(() => {256 jest.spyOn(cluster.store, 'updateStateFromServer').mockReturnThis();257 jest.spyOn(cluster, 'checkForNewInstalls').mockReturnThis();258 jest.spyOn(cluster, 'updateContainer').mockReturnThis();259 cluster.handleClusterStatusSuccess({ data: {} });260 });261 it('updates clusters store', () => {262 expect(cluster.store.updateStateFromServer).toHaveBeenCalled();263 });264 it('checks for new installable apps', () => {265 expect(cluster.checkForNewInstalls).toHaveBeenCalled();266 });267 it('updates message containers', () => {268 expect(cluster.updateContainer).toHaveBeenCalled();269 });270 });271 describe('updateApplication', () => {272 const params = { version: '1.0.0' };273 let storeUpdateApplication;274 let installApplication;275 beforeEach(() => {276 storeUpdateApplication = jest.spyOn(cluster.store, 'updateApplication');277 installApplication = jest.spyOn(cluster.service, 'installApplication');278 cluster.updateApplication({ id: RUNNER, params });279 });280 afterEach(() => {281 storeUpdateApplication.mockRestore();282 installApplication.mockRestore();283 });284 it('calls store updateApplication method', () => {285 expect(storeUpdateApplication).toHaveBeenCalledWith(RUNNER);286 });287 it('sends installApplication request', () => {288 expect(installApplication).toHaveBeenCalledWith(RUNNER, params);289 });290 });...
ios-deploy.js
Source:ios-deploy.js
...15 }16 async remove (bundleid) {17 const service = await services.startInstallationProxyService(this.udid);18 try {19 await service.uninstallApplication(bundleid);20 } finally {21 service.close();22 }23 }24 async removeApp (bundleId) {25 await this.remove(bundleId);26 }27 async install (app) {28 const start = new Date();29 try {30 const bundlePathOnPhone = await this.pushAppBundle(app);31 await this.installApplication(bundlePathOnPhone);32 log.info(`Installation is successful after ${new Date() - start}ms`);33 } catch (e) {...
Using AI Code Generation
1var webdriverio = require('webdriverio');2var options = {3 desiredCapabilities: {4 }5};6 .remote(options)7 .init()8 .then(function () {9 return this.uninstallApplication('com.my.app');10 })11 .then(function () {12 return this.end();13 })14 .catch(function (err) {15 console.error(err);16 });17var webdriverio = require('webdriverio');18var options = {19 desiredCapabilities: {20 }21};22 .remote(options)23 .init()24 .then(function () {25 return this.removeApp('com.my.app');26 })27 .then(function () {28 return this.end();29 })30 .catch(function (err) {31 console.error(err);32 });33var webdriverio = require('webdriverio');34var options = {35 desiredCapabilities: {36 }37};38 .remote(options)39 .init()40 .then(function () {41 return this.removeApp('com.my.app');42 })43 .then(function () {44 return this.end();45 })46 .catch(function (err) {47 console.error(err);48 });49var webdriverio = require('webdriverio');50var options = {51 desiredCapabilities: {
Using AI Code Generation
1var wd = require('wd');2var assert = require('assert');3var path = require('path');4var desiredCaps = {5};6var driver = wd.promiseChainRemote('localhost', 4723);7driver.init(desiredCaps)8 .then(function () {9 return driver.quit();10 })11 .then(function () {12 console.log('Test passed');13 })14 .catch(function (err) {15 console.log('Test failed with error: ' + err);16 });17var wd = require('wd');18var assert = require('assert');19var path = require('path');20var desiredCaps = {21};22var driver = wd.promiseChainRemote('localhost', 4723);23driver.init(desiredCaps)24 .then(function () {25 return driver.service.uninstallApplication('com.example.apple-samplecode.UICatalog');26 })27 .then(function () {28 return driver.quit();29 })30 .then(function () {31 console.log('Test passed');32 })33 .catch(function (err) {34 console.log('Test failed with error: ' + err);35 });36curl -X POST -d '{"bundleId":"com.example.apple-samplecode.UICatalog"}
Using AI Code Generation
1var wd = require('wd');2driver.init({3 })4 .then(function () {5 return driver.execute('mobile: uninstallApplication', {bundleId: 'com.example.apple-samplecode.UICatalog'});6 })7 .then(function () {8 console.log('AppiumTestApp uninstalled');9 })10 .catch(function (err) {11 console.log(err);12 })13 .fin(function () {14 driver.quit();15 });16{17}
Using AI Code Generation
1var wd = require('wd');2var assert = require('assert');3var appBundleId = process.argv[2];4var deviceUDID = process.argv[3];5var driver = wd.promiseChainRemote('localhost', 4723);6 .init({7 })8 .then(function() {9 return driver.uninstallApplication(appBundleId);10 })11 .then(function() {12 console.log('App uninstalled');13 return driver.quit();14 })15 .catch(function(error) {16 console.log('Error occured: ' + error);17 return driver.quit();18 });
Using AI Code Generation
1const argv = require('yargs').argv;2const request = require('request');3const udid = argv.udid;4const bundleId = argv.bundleId;5const appiumUrl = argv.appiumUrl;6const uninstallApp = (udid, bundleId, appiumUrl) => {7 const options = {8 headers: {9 },10 body: {11 desiredCapabilities: {12 }13 },14 };15 request(options, (error, response, body) => {16 if (error) throw new Error(error);17 const sessionId = body.sessionId;18 const uninstallAppOptions = {19 headers: {20 },21 body: {22 },23 };24 request(uninstallAppOptions, (error, response, body) => {25 if (error) throw new Error(error);26 console.log(body);27 });28 });29};30uninstallApp(udid, bundleId, appiumUrl);
Using AI Code Generation
1const wdio = require('webdriverio');2const opts = {3 capabilities: {4 }5};6async function main() {7 const driver = await wdio.remote(opts);8 const bundleId = await driver.execute('mobile: launchApp', {bundleId: 'com.apple.mobilesafari'});9 await driver.execute('mobile: terminateApp', {bundleId: 'com.apple.mobilesafari'});10 await driver.execute('mobile: uninstallApp', {bundleId: 'com.apple.mobilesafari'});11 await driver.deleteSession();12}13main();14[0-0] 2020-04-09T10:43:50.000Z INFO webdriver: DATA { capabilities: { alwaysMatch: { platformName: 'iOS', platformVersion: '13.3', deviceName: 'iPhone 11', app: 'com.apple.mobilesafari', automationName: 'XCUITest' }, firstMatch: [ {} ] }, desiredCapabilities: { platformName: 'iOS', platformVersion: '13.3', deviceName: 'iPhone 11', app: 'com.apple.mobilesafari', automationName: 'XCUITest' } }15[0-0] 2020-04-09T10:43:51.000Z INFO webdriver: COMMAND mobile: launchApp({bundleId: com.apple.mobilesafari})
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!!