How to use driver.getWindowSize method in Appium

Best JavaScript code snippet using appium

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('chrome')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();10driver.getWindowSize().then(function(size){11 console.log(size);12});13driver.setWindowSize(500, 500).then(function(){14 console.log("Window size changed");15});16driver.getOrientation().then(function(orientation){17 console.log(orientation);18});19driver.setOrientation("LANDSCAPE").then(function(){20 console.log("Orientation changed");21});22driver.getNetworkConnection().then(function(networkConnection){23 console.log(networkConnection);24});25driver.setNetworkConnection(6).then(function(){26 console.log("Network connection changed");27});28driver.getGeoLocation().then(function(geoLocation){29 console.log(geoLocation);30});31driver.setGeoLocation({latitude: 40.7143528, longitude: -74.0059731, altitude: 1}).then(function(){32 console.log("Geo location changed");33});34driver.getDeviceTime().then(function(deviceTime){35 console.log(deviceTime);36});37driver.getDeviceTime().then(function(deviceTime){38 console.log(deviceTime);39});40driver.hideKeyboard("Done").then(function(){41 console.log("Keyboard hidden");42});43driver.isKeyboardShown().then(function(isKeyboardShown){44 console.log(isKeyboardShown);45});46driver.lock(5).then(function(){

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriver = require('selenium-webdriver');2var driver = new webdriver.Builder()3 .forBrowser('chrome')4 .build();5driver.getWindowSize().then(function(size) {6 console.log(size);7 driver.quit();8});9driver.getWindowSize()10driver.manage().window().getSize()11driver.manage().window().getRect()12driver.manage().window().getPosition()13driver.manage().window().getRect()14driver.manage().window().maximize()15driver.manage().window().fullscreen()16driver.manage().window().setPosition()17driver.manage().window().setRect()18driver.manage().window().setSize()19driver.manage().window().setRect()20driver.manage().window().maximize()21driver.manage().window().fullscreen()22driver.manage().window().setPosition()23driver.manage().window().setRect()24driver.manage().window().setSize()25driver.manage().window().setRect()26driver.manage().window().maximize()27driver.manage().window().fullscreen()28driver.manage().window().setPosition()29driver.manage().window().setRect()

Full Screen

Using AI Code Generation

copy

Full Screen

1const {Builder, By, Key, until} = require('selenium-webdriver');2const {Options} = require('selenium-webdriver/chrome');3const {Driver} = require('selenium-webdriver/chrome');4const {ServiceBuilder} = require('selenium-webdriver/chrome');5async function example() {6 let options = new Options();7 options.addArguments("disable-infobars");8 options.addArguments("disable-extensions");9 options.addArguments("disable-notifications");10 options.addArguments("disable-popup-blocking");11 options.addArguments("disable-translate");12 options.addArguments("disable-web-security");13 options.addArguments("no-sandbox");14 options.addArguments("start-maximized");15 options.addArguments("test-type");16 options.addArguments("ignore-certificate-errors");17 options.addArguments("disable-gpu");18 options.addArguments("disable-dev-shm-usage");19 options.addArguments("disable-software-rasterizer");20 options.addArguments("disable-features=VizDisplayCompositor");21 options.addArguments("disable-features=NetworkService");22 options.addArguments("disable-features=VizDisplayCompositor");23 options.addArguments("disable-features=NetworkService");24 options.addArguments("enable-features=NetworkServiceInProcess");25 options.addArguments("enable-features=VizDisplayCompositor");26 options.addArguments("disable-features=VizDisplayCompositor");27 options.addArguments("disable-features=NetworkService");28 options.addArguments("enable-features=NetworkServiceInProcess");29 options.addArguments("enable-features=VizDisplayCompositor");30 options.addArguments("disable-features=VizDisplayCompositor");31 options.addArguments("disable-features=NetworkService");32 options.addArguments("enable-features=NetworkServiceInProcess");33 options.addArguments("enable-features=VizDisplayCompositor");34 options.addArguments("disable-features=VizDisplayCompositor");35 options.addArguments("disable-features=NetworkService");36 options.addArguments("enable-features=NetworkServiceInProcess");37 options.addArguments("enable-features=VizDisplayCompositor");38 options.addArguments("disable-features=VizDisplayCompositor");39 options.addArguments("disable-features=NetworkService");40 options.addArguments("enable-features=NetworkServiceInProcess");41 options.addArguments("enable-features=Viz

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriver = require('selenium-webdriver');2var driver = new webdriver.Builder().forBrowser('chrome').build();3driver.getWindowSize().then(function(size) {4console.log(size);5});6var webdriver = require('selenium-webdriver');7var driver = new webdriver.Builder().forBrowser('chrome').build();8driver.manage().window().getSize().then(function(size) {9console.log(size);10});

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('Test', function() {2 it('should get window size', function() {3 return driver.getWindowSize();4 });5});6describe('Test', function() {7 it('should set window size', function() {8 return driver.setWindowSize(400, 500);9 });10});11describe('Test', function() {12 it('should get orientation', function() {13 return driver.getOrientation();14 });15});16describe('Test', function() {17 it('should set orientation', function() {18 return driver.setOrientation('LANDSCAPE');19 });20});21describe('Test', function() {22 it('should get location', function() {23 return driver.getGeoLocation();24 });25});26describe('Test', function() {27 it('should set location', function() {28 return driver.setGeoLocation(40, 50);29 });30});31describe('Test', function() {32 it('should get network connection', function() {33 return driver.getNetworkConnection();34 });35});36describe('Test', function() {37 it('should set network connection', function() {38 return driver.setNetworkConnection(2);39 });40});41describe('Test', function() {42 it('should get available log types', function() {43 return driver.getAvailableLogTypes();44 });45});46describe('Test', function() {47 it('should get logs', function() {48 return driver.getLogs('logcat');49 });50});51describe('Test', function() {52 it('should get performance data types', function() {53 return driver.getPerformanceDataTypes();54 });55});56describe('Test', function() {57 it('should get performance data', function() {58 return driver.getPerformanceData('com.android.chrome', 'cpuinfo', 1000);

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 automation tests on LambdaTest cloud grid

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

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful