Best JavaScript code snippet using appium
hook.js
Source: hook.js
...31 },32 },33 connectionRetryCount: 0,34 })35 await driver.setWindowSize(816, 686)36 drivers.set('firefox', {driver, cleanup: () => driver.deleteSession()})37 } else if (name === 'internet explorer') {38 driver = await remote({39 protocol: 'https',40 hostname: 'ondemand.saucelabs.com',41 path: '/wd/hub',42 port: 443,43 logLevel: 'silent',44 capabilities: {45 browserName: 'internet explorer',46 browserVersion: '11.285',47 platformName: 'Windows 10',48 'sauce:options': {49 name: 'Snippets tests',50 idleTimeout: 1000,51 username: process.env.SAUCE_USERNAME,52 accessKey: process.env.SAUCE_ACCESS_KEY,53 },54 },55 connectionRetryCount: 0,56 })57 await driver.setWindowSize(816, 686)58 drivers.set('internet explorer', {driver, cleanup: () => driver.deleteSession()})59 } else if (name === 'ios safari') {60 let options61 if (process.env.APPLITOOLS_TEST_REMOTE === 'local') {62 options = {63 protocol: 'http',64 hostname: '0.0.0.0',65 path: '/wd/hub',66 port: 4723,67 logLevel: 'silent',68 capabilities: {69 name: 'Snippets tests',70 browserName: 'Safari',71 deviceName: 'iPhone XS',...
chrome-screenshot-service-spec.js
1'use strict';2const ChromeScreenshotService = require('../../src/components/chrome-screenshot-service'),3 promiseSpyObject = require('../support/promise-spy-object');4describe('ChromeScreenshotService', () => {5 let chromeDriver, underTest, config;6 beforeEach(() => {7 config = {};8 chromeDriver = promiseSpyObject('chromeDriver', ['start', 'loadUrl', 'stop', 'screenshot', 'setWindowSize', 'getContentBox']);9 underTest = new ChromeScreenshotService(config, {10 chromeDriver: chromeDriver11 });12 });13 ['start', 'stop'].forEach(op => {14 describe(op, () => {15 it(`${op}s the chrome driver`, done => {16 underTest[op]()17 .then(() => expect(chromeDriver[op]).toHaveBeenCalled())18 .then(done, done.fail);19 chromeDriver.promises[op].resolve();20 });21 it(`rejects if chrome driver does not ${op}`, done => {22 underTest[op]()23 .then(done.fail)24 .catch(e => {25 expect(e).toEqual('xxx');26 })27 .then(done, done.fail);28 chromeDriver.promises[op].reject('xxx');29 });30 });31 });32 describe('screenshot', () => {33 it('blows up if no params', done => {34 underTest.screenshot()35 .then(done.fail)36 .catch(e => {37 expect(e).toEqual('invalid-args');38 })39 .then(done, done.fail);40 });41 it('blows up if URL is not set', done => {42 underTest.screenshot({})43 .then(done.fail)44 .catch(e => {45 expect(e).toEqual('invalid-args');46 })47 .then(done, done.fail);48 });49 it('sets the window size to 10, 10 if not provided in the config or options', done => {50 chromeDriver.setWindowSize.and.callFake((width, height) => {51 expect(width).toEqual(10);52 expect(height).toEqual(10);53 done();54 return new Promise(() => false);55 });56 underTest.screenshot({url: 'xxx'})57 .then(done.fail, done.fail);58 });59 it('rejects when setting the initial size rejects', done => {60 underTest.screenshot({url: 'yyy'})61 .then(done.fail)62 .catch(e => expect(e).toEqual('boom'))63 .then(done, done.fail);64 chromeDriver.promises.setWindowSize.reject('boom');65 });66 it('loads the URL after window size is set', done => {67 chromeDriver.loadUrl.and.callFake(url => {68 expect(url).toEqual('someUrl');69 done();70 return new Promise(() => false);71 });72 underTest.screenshot({url: 'someUrl'})73 .then(done.fail, done.fail);74 chromeDriver.promises.setWindowSize.resolve();75 });76 it('rejects if loading the URL rejects', done => {77 underTest.screenshot({url: 'someUrl'})78 .then(done.fail)79 .catch(e => expect(e).toEqual('boom'))80 .then(done, done.fail);81 chromeDriver.promises.setWindowSize.resolve();82 chromeDriver.promises.loadUrl.reject('boom');83 });84 it('sets the window to content size before taking the screenshot', done => {85 chromeDriver.screenshot.and.callFake(() => {86 expect(chromeDriver.setWindowSize.calls.argsFor(1)).toEqual([55, 66]);87 expect(chromeDriver.setWindowSize.calls.count()).toEqual(2);88 done();89 return new Promise(() => false);90 });91 underTest.screenshot({url: 'xxx'})92 .then(done.fail, done.fail);93 chromeDriver.promises.setWindowSize.resolve();94 chromeDriver.promises.loadUrl.resolve();95 chromeDriver.promises.getContentBox.resolve({width: 55, height: 66});96 });97 it('resolves with the chrome driver screenshot', done => {98 underTest.screenshot({url: 'xxx'})99 .then(r => expect(r).toEqual('screenshot-img'))100 .then(done, done.fail);101 chromeDriver.promises.setWindowSize.resolve();102 chromeDriver.promises.loadUrl.resolve();103 chromeDriver.promises.getContentBox.resolve({width: 55, height: 66});104 chromeDriver.promises.screenshot.resolve('screenshot-img');105 });106 });...
chrome-screenshot-service.js
Source: chrome-screenshot-service.js
1'use strict';2const validateRequiredComponents = require('../util/validate-required-components');3module.exports = function ChromeScreenshotService(config, components) {4 validateRequiredComponents(components, ['chromeDriver']);5 const self = this,6 chromeDriver = components.chromeDriver,7 getNaturalSize = async function (options) {8 const initialWidth = options.initialWidth || 10,9 initialHeight = options.initialHeight || 10;10 await chromeDriver.setWindowSize(initialWidth, initialHeight);11 await chromeDriver.loadUrl(options.url);12 return chromeDriver.getContentBox();13 };14 self.start = chromeDriver.start;15 self.stop = chromeDriver.stop;16 self.screenshot = async function (options) {17 if (!options || !options.url) {18 return Promise.reject('invalid-args');19 }20 const naturalSize = await getNaturalSize(options);21 await chromeDriver.setWindowSize(naturalSize.width, naturalSize.height);22 if (options.beforeScreenshot) {23 await chromeDriver.evaluate(options.beforeScreenshot, options.beforeScreenshotArgs);24 await chromeDriver.waitForNetworkIdle();25 }26 return chromeDriver.screenshot();27 };28 self.canHandle = () => true;...
example.config.js
Source: example.config.js
1'use strict'2function size(width) {3 return function (driver) {4 return driver.setWindowSize(width, 600 /* any height*/);5 };6}7module.exports = {8 seleniumHost: 'http://localhost:4444/wd/hub',9 browsers: ['chrome'],10 envHosts: {11 build: 'http://localhost:8000/example/build',12 prod: 'http://localhost:8000/example/prod'13 },14 paths: [15 { 'Tiny CSS Difference': ['/tiny_css_difference.html', size(800)] },16 {17 'Chart Difference': ['/chart_difference.html', function (browser) {18 return size(800)(browser).sleep(2000);...
homepage.test.js
Source: homepage.test.js
1'use strict';2const assert = require('assert');3const {4 driver,5 BASE_URL,6} = require('./helper');7describe('test/homepage.test.js', () => {8 describe('home page UI testing', () => {9 before(function() {10 this.timeout(5 * 1000);11 return driver12 .initWindow({13 width: 800,14 height: 600,15 deviceScaleFactor: 2,16 });17 });18 beforeEach(() => {19 return driver20 .getUrl(`${BASE_URL}`);21 });22 afterEach(function() {23 return driver24 .saveScreenshots(this);25 });26 after(() => {27 return driver28 .openReporter(false)29 .quit();30 });31 it('page render success', () => {32 return driver33 .setWindowSize(800, 600)34 .title()35 .then(title => {36 assert.equal(title, 'egg view example');37 })38 .source()39 .then(html => {40 assert.ok(html.includes('egg view example here, welcome foobar'));41 });42 });43 });...
example.test.js
Source: example.test.js
1'use strict';2const { webpackHelper } = require('macaca-wd');3const {4 driver,5 BASE_URL6} = webpackHelper;7describe('./test/example.test.js', () => {8 describe('page func testing', () => {9 before(() => {10 return driver11 .initWindow({12 platformName: 'playwright',13 browserName: 'chromium',14 width: 375,15 height: 667,16 deviceScaleFactor: 2,17 });18 });19 beforeEach(() => {20 return driver21 .getUrl(`${BASE_URL}/examples`);22 });23 afterEach(function () {24 return driver25 .coverage()26 .saveScreenshots(this);27 });28 after(() => {29 return driver30 .openReporter(false)31 .quit();32 });33 it('page resize should be ok', () => {34 return driver35 .setWindowSize(800, 600)36 .sleep(1000);37 });38 });...
window-size.js
Source: window-size.js
1const setWindowSize = async (driver, width, height) => {2 await driver.manage().window().setRect({3 width,4 height,5 x: 0,6 y: 0,7 });8};9const fullScreen = async (driver) => driver.manage().window().fullscreen();10const hugeScreen = async (driver) => setWindowSize(driver, 1200, 800);11const largeScreen = async (driver) => setWindowSize(driver, 900, 800);12const mediumScreen = async (driver) => setWindowSize(driver, 600, 800);13const smallScreen = async (driver) => setWindowSize(driver, 300, 800);14const sizes = () => [15 fullScreen,16 hugeScreen,17 largeScreen,18 mediumScreen,19 smallScreen,20];21module.exports = {22 fullScreen,23 hugeScreen,24 largeScreen,25 mediumScreen,26 smallScreen,27 sizes,...
screenshot
Source: screenshot
...5var capabilities = {6 'browserName' : 'firefox'7};8var path = ['', function (driver) {9 return driver.setWindowSize(1300, 6000).sleep(2000);10}];11viff.takeScreenshot(capabilities, process.argv[2], path, function (bufferImg) {12 FS.writeFileSync('output.png', bufferImg);13 viff.closeDrivers();...
Using AI Code Generation
1driver.setWindowSize(500, 500);2driver.getWindowSize();3driver.getOrientation();4driver.setOrientation("LANDSCAPE");5driver.getGeoLocation();6driver.setGeoLocation(12.9716, 77.5946, 100);7driver.getNetworkConnection();8driver.setNetworkConnection(6);9driver.getPerformanceData("com.android.chrome", "cpuinfo", 10);10driver.getPerformanceDataTypes();11driver.getSupportedPerformanceDataTypes();12driver.getSettings();13driver.updateSettings({"ignoreUnimportantViews": true});14driver.getClipboard();15driver.setClipboard("text/plain", "Hello");16driver.hideKeyboard();17driver.lock(5);18driver.unlock();19driver.isLocked();20driver.isDeviceLocked();21driver.toggleAirplaneMode();22driver.toggleData();23driver.toggleWiFi();24driver.toggleLocationServices();25driver.openNotifications();26driver.startActivity("com.android.chrome", "com.google.android.apps.chrome.Main");
Using AI Code Generation
1var wd = require('wd');2var driver = wd.promiseChainRemote("localhost", 4723);3var desiredCapabilities = {4};5 .init(desiredCapabilities)6 .setWindowSize(500, 500)7 .quit();8 .init(desiredCapabilities)9 .setWindowRect(0, 0, 500, 500)10 .quit();
Using AI Code Generation
1driver.setWindowSize(480, 800);2driver.setWindowSize(480, 800, "landscape");3driver.setWindowSize(480, 800, "portrait");4driver.setWindowSize("current");5driver.getScreenshot();6driver.touch("singleTap", {x: 100, y: 100});7driver.touch("doubleTap", {x: 100, y: 100});8driver.touch("longPress", {x: 100, y: 100});9driver.touch("drag", {fromX: 100, fromY: 100, toX: 200, toY: 200});10driver.touch("drag", {fromX: 100, fromY: 100, toX: 200, toY: 200, duration: 1000});11driver.touch("scroll", {element: element, toX: 100, toY: 100});12driver.touch("scroll", {element: element, toX: 100, toY: 100, duration: 1000});13driver.touch("scroll", {element: element, toElement: element});14driver.touch("scroll", {element: element, toElement: element, duration: 1000});15driver.touch("pinch", {element: element, percent: 200, speed: 1000});16driver.touch("zoom", {element: element, percent: 200, speed: 1000});17driver.touchPerform([18 {action: "press", options: {x: 100, y: 100}},19 {action: "moveTo", options: {x: 200, y: 200}},20 {action: "release"}21]);22driver.performMultiAction([23 {action: "press", options: {element: element}},24 {action: "moveTo", options: {element: element}},25 {action: "release"}26]);27driver.performTouchId(true);
Using AI Code Generation
1driver.setWindowSize(600, 800)2 .then(function() {3 });4driver.getWindowSize()5 .then(function(size) {6 });7driver.getOrientation()8 .then(function(orientation) {9 });10driver.setOrientation("LANDSCAPE")11 .then(function() {12 });13driver.getGeoLocation()14 .then(function(location) {15 });16driver.setGeoLocation(40.7143528, -74.0059731)17 .then(function() {18 });19driver.getNetworkConnection()20 .then(function(connection) {21 });22driver.setNetworkConnection(6)23 .then(function() {24 });25driver.getPerformanceData("com.example.android.apis", "memoryinfo", 5)26 .then(function(data) {27 });28driver.getPerformanceDataTypes()29 .then(function(data) {30 });31driver.getSettings()32 .then(function(settings) {33 });34driver.updateSettings({"ignoreUnimportantViews": false})35 .then(function() {36 });37driver.toggleLocationServices()38 .then(function() {39 });40driver.lock(5)41 .then(function() {42 });43driver.isLocked()44 .then(function(locked)
Check out the latest blogs from LambdaTest on this topic:
Were you able to work upon your resolutions for 2019? I may sound comical here but my 2019 resolution being a web developer was to take a leap into web testing in my free time. Why? So I could understand the release cycles from a tester’s perspective. I wanted to wear their shoes and see the SDLC from their eyes. I also thought that it would help me groom myself better as an all-round IT professional.
Technology is constantly evolving, what was state of art a few years back might be defunct now. Especially now, where the world of software development and testing is innovating ways to incorporate emerging technologies such as artificial intelligence, machine learning, big data, etc.
With the rapid evolution in technology and a massive increase of businesses going online after the Covid-19 outbreak, web applications have become more important for organizations. For any organization to grow, the web application interface must be smooth, user-friendly, and cross browser compatible with various Internet browsers.
Before starting this post on Unity testing, let’s start with a couple of interesting cases. First, Temple Run, a trendy iOS game, was released in 2011 (and a year later on Android). Thanks to its “infinity” or “never-ending” gameplay and simple interface, it reached the top free app on the iOS store and one billion downloads.
Let’s put it short: Appium Desktop = Appium Server + Inspector. When Appium Server runs automation test scripts, Appium Inspector can identify the UI elements of every application under test. The core structure of an Appium Inspector is to ensure that you discover every visible app element when you develop your test scripts. Before you kickstart your journey with Appium Inspector, you need to understand the details of it.
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!!