How to use driver.getWindowSize method in Appium Xcuitest Driver

Best JavaScript code snippet using appium-xcuitest-driver

getDeviceInfo.test.js

Source:getDeviceInfo.test.js Github

copy

Full Screen

1import {IMAGE_STRING} from '../mocks/mocks'2import * as Utils from '../../lib/helpers/utils'3describe('getDeviceInfo', () => {4 let determineIphoneXSeriesSpy, determineLargeIphoneXSeriesSpy, getDeviceInfo, getScreenshotSizeSpy5 const screenData = {6 width: 10,7 height: 20,8 }9 beforeEach(() => {10 jest.isolateModules(() => {11 getDeviceInfo = require('../../lib/methods/getDeviceInfo').getDeviceInfo12 })13 delete global.driver14 global.driver = {15 capabilities:{},16 getWindowSize: jest.fn().mockResolvedValue(screenData),17 }18 getScreenshotSizeSpy = jest.spyOn(Utils, 'getScreenshotSize').mockReturnValue({19 width: 1000,20 height: 2000,21 })22 })23 afterEach(() => {24 global.driver = {25 getWindowSize: jest.fn().mockRestore(),26 }27 determineIphoneXSeriesSpy.mockRestore()28 determineLargeIphoneXSeriesSpy.mockRestore()29 getScreenshotSizeSpy.mockRestore()30 })31 it('should be able to get the default device info for the initial run', async () => {32 determineIphoneXSeriesSpy = jest.spyOn(Utils, 'determineIphoneXSeries').mockReturnValue(false)33 determineLargeIphoneXSeriesSpy = jest.spyOn(Utils, 'determineLargeIphoneXSeries').mockReturnValue(false)34 expect(await getDeviceInfo(IMAGE_STRING)).toMatchSnapshot()35 expect(getScreenshotSizeSpy).toBeCalledWith(IMAGE_STRING)36 expect(global.driver.getWindowSize).toHaveBeenCalled()37 expect(determineIphoneXSeriesSpy).toBeCalledWith(screenData)38 expect(determineLargeIphoneXSeriesSpy).toBeCalledWith(screenData)39 })40 it('should be able to get the default device info for the second run', async () => {41 determineIphoneXSeriesSpy = jest.spyOn(Utils, 'determineIphoneXSeries').mockReturnValue(false)42 determineLargeIphoneXSeriesSpy = jest.spyOn(Utils, 'determineLargeIphoneXSeries').mockReturnValue(false)43 expect(await getDeviceInfo(IMAGE_STRING)).toMatchSnapshot()44 expect(getScreenshotSizeSpy).toBeCalledWith(IMAGE_STRING)45 expect(global.driver.getWindowSize).toHaveBeenCalled()46 expect(determineIphoneXSeriesSpy).toBeCalledWith(screenData)47 expect(determineLargeIphoneXSeriesSpy).toBeCalledWith(screenData)48 getScreenshotSizeSpy.mockRestore()49 determineIphoneXSeriesSpy.mockRestore()50 determineLargeIphoneXSeriesSpy.mockRestore()51 global.driver = {52 getWindowSize: jest.fn().mockRestore(),53 }54 // The second run to check that the data is stored in the `DEVICE_INFO` and all methods are not called again55 global.driver = {56 getWindowSize: jest.fn().mockResolvedValue(screenData),57 }58 getScreenshotSizeSpy = jest.spyOn(Utils, 'getScreenshotSize').mockReturnValue({59 width: 1000,60 height: 2000,61 })62 determineIphoneXSeriesSpy = jest.spyOn(Utils, 'determineIphoneXSeries').mockReturnValue(false)63 determineLargeIphoneXSeriesSpy = jest.spyOn(Utils, 'determineLargeIphoneXSeries').mockReturnValue(false)64 expect(await getDeviceInfo(IMAGE_STRING)).toMatchSnapshot()65 expect(getScreenshotSizeSpy).not.toHaveBeenCalled()66 expect(global.driver.getWindowSize).not.toHaveBeenCalled()67 expect(determineIphoneXSeriesSpy).not.toHaveBeenCalled()68 expect(determineLargeIphoneXSeriesSpy).not.toHaveBeenCalled()69 })70 it('should be able to get the device info for an iPhone X', async () => {71 determineIphoneXSeriesSpy = jest.spyOn(Utils, 'determineIphoneXSeries').mockReturnValue(true)72 determineLargeIphoneXSeriesSpy = jest.spyOn(Utils, 'determineLargeIphoneXSeries').mockReturnValue(false)73 expect(await getDeviceInfo(IMAGE_STRING)).toMatchSnapshot()74 })75 it('should be able to get the device info for an iPhone X Large', async () => {76 determineIphoneXSeriesSpy = jest.spyOn(Utils, 'determineIphoneXSeries').mockReturnValue(false)77 determineLargeIphoneXSeriesSpy = jest.spyOn(Utils, 'determineLargeIphoneXSeries').mockReturnValue(true)78 expect(await getDeviceInfo(IMAGE_STRING)).toMatchSnapshot()79 })80 it('should be able to get the device info for a landscape phone', async () => {81 global.driver = {82 capabilities: {},83 getWindowSize: jest.fn().mockResolvedValue({84 width: 1000,85 height: 500,86 }),87 }88 expect(await getDeviceInfo(IMAGE_STRING)).toMatchSnapshot()89 })90 it('should be able to get the device info an Android phone', async () => {91 global.driver = {92 capabilities: {93 pixelRatio: 2.75,94 statBarHeight: 66,95 viewportRect: { left: 0, top: 66, width: 1000, height: 1802 }96 },97 getWindowSize: jest.fn().mockResolvedValue({98 width: 1000,99 height: 2000,100 }),101 }102 expect(await getDeviceInfo(IMAGE_STRING)).toMatchSnapshot()103 })...

Full Screen

Full Screen

TC_018_OrderScreen.js

Source:TC_018_OrderScreen.js Github

copy

Full Screen

...11 12 })13 it('Swipe vertically', () => {14 /********SWIPE SCREEN VERTICALLY *******/15 const {height} = driver.getWindowSize();16 const anchorPercentage = 50;17 const startPointPercentage = 90;18 const endPointPercentage = 10;19 const anchor = height * anchorPercentage / 100;20 const startPoint = height * startPointPercentage / 100;21 const endPoint = height * endPointPercentage / 100;22 driver.touchPerform([23 {24 action: 'press',25 options: {26 x: anchor,27 y: startPoint28 }29 },30 {31 action: 'wait',32 options: {33 ms: 100034 }35 },36 {37 action: 'moveTo',38 options: {39 x: anchor,40 y: endPoint41 }42 },43 {44 action: 'release',45 options: {46 }47 }48 ])49 /**********************************/50 })51 it('Click tour item', () => {52 HomeScreen.clickOnImageListTourItem();53 54 browser.pause(2000);55 })56 it('Check total payment with another adults number and children number without discount', () => {57 DetailTour.increaseChildrenNumber().increaseAdultsNumber().clickOnButtonBookTour();58 })59 it('Swipe vertically', () => {60 /********SWIPE SCREEN VERTICALLY *******/61 const {height} = driver.getWindowSize();62 const anchorPercentage = 50;63 const startPointPercentage = 90;64 const endPointPercentage = 10;65 const anchor = height * anchorPercentage / 100;66 const startPoint = height * startPointPercentage / 100;67 const endPoint = height * endPointPercentage / 100;68 driver.touchPerform([69 {70 action: 'press',71 options: {72 x: anchor,73 y: startPoint74 }75 },...

Full Screen

Full Screen

all-screens.js

Source:all-screens.js Github

copy

Full Screen

...38 world.swipeLeft = swipeLeft;39 world.archive = new ArchiveScreen( world );40}41async function swipeRight( world, { start_x=30, end_x=0.95 } = {} ) {42 let size = await world.driver.getWindowSize();43 await world.driver.touchAction([ 44 {action: 'press', x: start_x, y: size.height/2},45 {action: 'wait', ms: 1000 },46 {action: 'moveTo', x: size.width*end_x, y: size.height/2},47 'release']);48}49async function swipeLeft(world) {50 let size = await world.driver.getWindowSize();51 await world.driver.touchPerform([ 52 {action: 'press', x: size.width*0.60, y: size.height/2},53 {action: 'wait', ms: 1000 },54 {action: 'moveTo', x: 4, y: size.height/2},55 {action:'release'}]);56}57exports.setUpWorld = setUpWorld;...

Full Screen

Full Screen

List-Performance-test.e2e.js

Source:List-Performance-test.e2e.js Github

copy

Full Screen

...14 });15 afterAll(async () => await driver.quit());16 test('render home screen Android ', async () => {17 // let list = await driver.elementByAccessibilityId('long_list');18 // var size = await driver.getWindowSize();19 // var starty = size.height * 0.8;20 // var endy = size.height * 0.2;21 // var startx = size.width / 2;22 // driver.swipe(startx, starty, startx, endy, 3000);23 // //let list = await driver.getElementById('long_list');24 // var isVisible = false;25 // while (!isVisible) {26 // await driver.execute('mobile: swipe', {element: list, direction: 'up'});27 // //await driver.execute('mobile: scroll', {direction: 'down'});28 // }29 var isVisible = false;30 while (!isVisible) {31 var size = await driver.getWindowSize();32 var starty = size.height * 0.8;33 var endy = size.height * 0.2;34 var touchAction = new wd.TouchAction(driver)35 .longPress({x: 0, y: starty})36 .moveTo({x: 0, y: endy})37 .release();38 await touchAction.perform();39 await driver.sleep(1210);40 }41 let item0 = await driver.elementByAccessibilityId('0');42 expect(await item0.text()).toBe('0');43 });44 // test('render home screen ios ', async () => {45 // let list = await driver.elementByAccessibilityId('long_list');...

Full Screen

Full Screen

device-specs.js

Source:device-specs.js Github

copy

Full Screen

1import { IosDriver } from '../../lib/driver';2import { uiauto } from '../..';3import chai from 'chai';4import chaiAsPromised from 'chai-as-promised';5import sinon from 'sinon';6chai.should();7chai.use(chaiAsPromised);8const PLUS_HEIGHT = 736;9const NONPLUS_HEIGHT = 568;10describe('device pixel ratio', function () {11 let driver;12 beforeEach(function () {13 driver = new IosDriver();14 });15 it('pixel ratio should equal 2 with non plus device', async function () {16 sinon.stub(driver, 'getWindowSize').returns({width: 1000, height: NONPLUS_HEIGHT});17 let pixelRatio = await driver.getDevicePixelRatio();18 pixelRatio.should.equal(2);19 });20 it('pixel ratio should equal 3 with plus device', async function () {21 sinon.stub(driver, 'getWindowSize').returns({width: 1000, height: PLUS_HEIGHT});22 let pixelRatio = await driver.getDevicePixelRatio();23 pixelRatio.should.equal(3);24 });25});26describe('status bar height', function () {27 it('should invoke correct command', async function () {28 let driver = new IosDriver();29 driver.uiAutoClient = new uiauto.UIAutoClient();30 sinon.stub(driver.uiAutoClient, 'sendCommand')31 .withArgs('UIATarget.localTarget().frontMostApp().statusBar().rect().size.height;')32 .returns(24);33 await driver.getStatusBarHeight().should.eventually.eql(24);34 });35});36describe('viewport rect', function () {37 it('should return the viewport rect without statusbar height', async function () {38 let driver = new IosDriver();39 sinon.stub(driver, 'getDevicePixelRatio').returns(3.0);40 sinon.stub(driver, 'getStatusBarHeight').returns(24);41 sinon.stub(driver, 'getWindowSize').returns({width: 320, height: 568});42 let viewportRect = await driver.getViewportRect();43 viewportRect.left.should.equal(0);44 viewportRect.top.should.equal(24 * 3);45 viewportRect.width.should.equal(320 * 3);46 viewportRect.height.should.equal(568 * 3 - 72);47 });...

Full Screen

Full Screen

swipeVertical.js

Source:swipeVertical.js Github

copy

Full Screen

...5 const FORM_COMPONENT = "~Forms-screen"6 // 0. click on Forms icon button7 $(FORM_ICON).click()8 // 1. Swipe up screen vertically9 const { width, height } = driver.getWindowSize()10 console.log(driver.getWindowSize())11 const anchorPercentage = 50 //50% * width12 const startPointPercentage = 90 // 90% * height13 const endPointPercentage = 10 // 10% * height14 const anchor = anchorPercentage * width / 10015 const startPoint = startPointPercentage * height / 10016 const endPoint = endPointPercentage * height / 10017 // Touch on screen before doing touch18 $(FORM_COMPONENT).click()19 // Press on start point, wait 1s, moveTo endPoint , release20 driver.touchPerform([21 {22 action: 'press',23 options: {24 x: anchor,...

Full Screen

Full Screen

pickMenuItem.js

Source:pickMenuItem.js Github

copy

Full Screen

1import wd from 'wd';2export default async (driver, PlatformOS) => {3 if (PlatformOS === 'ios') {4 const action = new wd.TouchAction(driver);5 let {height} = await driver.getWindowSize();6 await driver.sleep(1000);7 await action8 .press({x: 50, y: height - 10})9 .wait(1000)10 .moveTo({x: 50, y: height - 80})11 .release();12 await action.perform();13 await driver.waitForElementByXPath(14 "//XCUIElementTypeOther[@name='Done']",15 8000,16 );17 const Done = await driver.elementByXPath(18 "//XCUIElementTypeOther[@name='Done']",19 );...

Full Screen

Full Screen

Screen.js

Source:Screen.js Github

copy

Full Screen

...3 * Get device screen width4 * @returns {Number} width5 */6 async getWidth() {7 return (await driver.getWindowSize())['width'];8 };9 /**10 * Get device screen height11 * @returns {Number} height12 */13 async getHeight() {14 return (await driver.getWindowSize())['height'];15 };16 /**17 * Perform tap by coordinates18 * @param {Number} x coordinate19 * @param {Number} y coordinate20 * @param {Number} timeout for execution comand. Default: 500ms21 */22 async performTapByCoordinates(x ,y, timeout = 500) {23 await driver.touchPerform([24 { action: 'tap', options: { x: x, y: y } },25 { action: 'release' }26 ]);27 await browser.pause(timeout);28 };...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriver = require('selenium-webdriver'),2 until = webdriver.until;3var driver = new webdriver.Builder()4 .forBrowser('selenium')5 .build();6driver.findElement(By.name('q')).sendKeys('webdriver');7driver.findElement(By.name('btnG')).click();8driver.wait(until.titleIs('webdriver - Google Search'), 1000);9driver.getWindowSize().then(function(size) {10 console.log(size);11});12var webdriver = require('selenium-webdriver'),13 until = webdriver.until;14var driver = new webdriver.Builder()15 .forBrowser('selenium')16 .build();17driver.findElement(By.name('q')).sendKeys('webdriver');18driver.findElement(By.name('btnG')).click();19driver.wait(until.titleIs('webdriver - Google Search'), 1000);20driver.setWindowSize(500, 500).then(function() {21 driver.getWindowSize().then(function(size) {22 console.log(size);23 });24});25var webdriver = require('selenium-webdriver'),26 until = webdriver.until;27var driver = new webdriver.Builder()28 .forBrowser('selenium')29 .build();30driver.findElement(By.name('q')).sendKeys('webdriver');31driver.findElement(By.name('btnG')).click();32driver.wait(until.titleIs('webdriver - Google Search'), 1000);33driver.getOrientation().then(function(orientation) {34 console.log(orientation);35});36var webdriver = require('selenium-webdriver'),37 until = webdriver.until;38var driver = new webdriver.Builder()39 .forBrowser('selenium')40 .build();41driver.findElement(By.name('q')).sendKeys('webdriver');42driver.findElement(By.name('btnG')).click();43driver.wait(until.titleIs('webdriver - Google Search'), 1000);44driver.setOrientation("LANDSCAPE").then(function() {45 driver.getOrientation().then(function(orientation) {

Full Screen

Using AI Code Generation

copy

Full Screen

1const { remote } = require('webdriverio');2const opts = {3 capabilities: {4 }5};6(async () => {7 const browser = await remote(opts);8 const windowSize = await browser.getWindowSize();9 console.log('window size: ', windowSize);10})();11window size: { width: 375, height: 667 }12const windowSize = await browser.getWindowSize('current');13console.log('window size: ', windowSize);14window size: { width: 375, height: 667 }15const windowSize = await browser.getWindowSize('native');16console.log('window size: ', windowSize);17window size: { width: 375, height: 667 }18const windowSize = await browser.getWindowSize('webview');19console.log('window size: ', windowSize);20window size: { width: 375, height: 667 }21const { remote } = require('webdriverio');22const opts = {23 capabilities: {24 }25};

Full Screen

Using AI Code Generation

copy

Full Screen

1var wd = require('wd');2driver.init({3}).then(function () {4 return driver.getWindowSize();5}).then(function (size) {6 console.log(size);7 return driver.quit();8});9var wd = require('wd');10driver.init({11}).then(function () {12 return driver.setWindowSize(200, 500);13}).then(function () {14 return driver.getWindowSize();15}).then(function (size) {16 console.log(size);17 return driver.quit();18});19var wd = require('wd');20driver.init({21}).then(function () {22 return driver.getOrientation();23}).then(function (orientation) {24 console.log(orientation);25 return driver.quit();26});27var wd = require('wd');28driver.init({29}).then(function

Full Screen

Using AI Code Generation

copy

Full Screen

1var wd = require('wd');2var assert = require('assert');3var chai = require('chai');4var chaiAsPromised = require('chai-as-promised');5chai.use(chaiAsPromised);6var should = chai.should();7var expect = chai.expect;8var desiredCaps = {9};10driver.init(desiredCaps);11driver.getWindowSize().then(function (size) {12 console.log("The size of the screen is: " + JSON.stringify(size));13});14driver.quit();15The size of the screen is: {"width":375,"height":667}

Full Screen

Using AI Code Generation

copy

Full Screen

1const webdriverio = require('webdriverio');2const options = {3 desiredCapabilities: {4 }5};6(async function() {7 const client = await webdriverio.remote(options);8 const size = await client.getWindowSize();9 console.log(size);10})();11{ width: 375, height: 667 }

Full Screen

Using AI Code Generation

copy

Full Screen

1driver.setWindowSize(400, 400);2driver.getWindowSize();3{ width: 400, height: 400 }4driver.getWindowSize();5{ width: 400, height: 400 }6driver.getWindowSize();7{ width: 400, height: 400 }8driver.getWindowSize();9{ width: 400, height: 400 }10driver.getWindowSize();11{ width: 400, height: 400 }12driver.getWindowSize();13{ width: 400, height: 400 }14driver.getWindowSize();15{ width: 400, height: 400 }16driver.getWindowSize();17{ width: 400, height: 400 }18driver.getWindowSize();19{ width: 400, height: 400 }20driver.getWindowSize();

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriver = require('selenium-webdriver'),2until = webdriver.until;3var capabilities = {4};5var driver = new webdriver.Builder()6.withCapabilities(capabilities)7.build();8driver.getWindowSize().then(function(size) {9console.log(size);10});11driver.quit();

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Appium Xcuitest Driver automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Sign up Free
_

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful