Best JavaScript code snippet using webdriverio-monorepo
test_Capabilities.js
Source:test_Capabilities.js
1/* This Source Code Form is subject to the terms of the Mozilla Public2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,3 * You can obtain one at http://mozilla.org/MPL/2.0/. */4"use strict";5const { Preferences } = ChromeUtils.import(6 "resource://gre/modules/Preferences.jsm"7);8const { AppInfo } = ChromeUtils.import(9 "chrome://remote/content/marionette/appinfo.js"10);11const { error } = ChromeUtils.import(12 "chrome://remote/content/shared/webdriver/Errors.jsm"13);14const {15 Capabilities,16 PageLoadStrategy,17 Proxy,18 Timeouts,19 UnhandledPromptBehavior,20} = ChromeUtils.import(21 "chrome://remote/content/shared/webdriver/Capabilities.jsm"22);23add_test(function test_Timeouts_ctor() {24 let ts = new Timeouts();25 equal(ts.implicit, 0);26 equal(ts.pageLoad, 300000);27 equal(ts.script, 30000);28 run_next_test();29});30add_test(function test_Timeouts_toString() {31 equal(new Timeouts().toString(), "[object Timeouts]");32 run_next_test();33});34add_test(function test_Timeouts_toJSON() {35 let ts = new Timeouts();36 deepEqual(ts.toJSON(), { implicit: 0, pageLoad: 300000, script: 30000 });37 run_next_test();38});39add_test(function test_Timeouts_fromJSON() {40 let json = {41 implicit: 0,42 pageLoad: 2.0,43 script: Number.MAX_SAFE_INTEGER,44 };45 let ts = Timeouts.fromJSON(json);46 equal(ts.implicit, json.implicit);47 equal(ts.pageLoad, json.pageLoad);48 equal(ts.script, json.script);49 run_next_test();50});51add_test(function test_Timeouts_fromJSON_unrecognised_field() {52 let json = {53 sessionId: "foobar",54 };55 try {56 Timeouts.fromJSON(json);57 } catch (e) {58 equal(e.name, error.InvalidArgumentError.name);59 equal(e.message, "Unrecognised timeout: sessionId");60 }61 run_next_test();62});63add_test(function test_Timeouts_fromJSON_invalid_types() {64 for (let value of [null, [], {}, false, "10", 2.5]) {65 Assert.throws(66 () => Timeouts.fromJSON({ implicit: value }),67 /InvalidArgumentError/68 );69 }70 run_next_test();71});72add_test(function test_Timeouts_fromJSON_bounds() {73 for (let value of [-1, Number.MAX_SAFE_INTEGER + 1]) {74 Assert.throws(75 () => Timeouts.fromJSON({ script: value }),76 /InvalidArgumentError/77 );78 }79 run_next_test();80});81add_test(function test_PageLoadStrategy() {82 equal(PageLoadStrategy.None, "none");83 equal(PageLoadStrategy.Eager, "eager");84 equal(PageLoadStrategy.Normal, "normal");85 run_next_test();86});87add_test(function test_Proxy_ctor() {88 let p = new Proxy();89 let props = [90 "proxyType",91 "httpProxy",92 "sslProxy",93 "socksProxy",94 "socksVersion",95 "proxyAutoconfigUrl",96 ];97 for (let prop of props) {98 ok(prop in p, `${prop} in ${JSON.stringify(props)}`);99 equal(p[prop], null);100 }101 run_next_test();102});103add_test(function test_Proxy_init() {104 let p = new Proxy();105 // no changed made, and 5 (system) is default106 equal(p.init(), false);107 equal(Preferences.get("network.proxy.type"), 5);108 // pac109 p.proxyType = "pac";110 p.proxyAutoconfigUrl = "http://localhost:1234";111 ok(p.init());112 equal(Preferences.get("network.proxy.type"), 2);113 equal(114 Preferences.get("network.proxy.autoconfig_url"),115 "http://localhost:1234"116 );117 // direct118 p = new Proxy();119 p.proxyType = "direct";120 ok(p.init());121 equal(Preferences.get("network.proxy.type"), 0);122 // autodetect123 p = new Proxy();124 p.proxyType = "autodetect";125 ok(p.init());126 equal(Preferences.get("network.proxy.type"), 4);127 // system128 p = new Proxy();129 p.proxyType = "system";130 ok(p.init());131 equal(Preferences.get("network.proxy.type"), 5);132 // manual133 for (let proxy of ["http", "ssl", "socks"]) {134 p = new Proxy();135 p.proxyType = "manual";136 p.noProxy = ["foo", "bar"];137 p[`${proxy}Proxy`] = "foo";138 p[`${proxy}ProxyPort`] = 42;139 if (proxy === "socks") {140 p[`${proxy}Version`] = 4;141 }142 ok(p.init());143 equal(Preferences.get("network.proxy.type"), 1);144 equal(Preferences.get("network.proxy.no_proxies_on"), "foo, bar");145 equal(Preferences.get(`network.proxy.${proxy}`), "foo");146 equal(Preferences.get(`network.proxy.${proxy}_port`), 42);147 if (proxy === "socks") {148 equal(Preferences.get(`network.proxy.${proxy}_version`), 4);149 }150 }151 // empty no proxy should reset default exclustions152 p = new Proxy();153 p.proxyType = "manual";154 p.noProxy = [];155 ok(p.init());156 equal(Preferences.get("network.proxy.no_proxies_on"), "");157 run_next_test();158});159add_test(function test_Proxy_toString() {160 equal(new Proxy().toString(), "[object Proxy]");161 run_next_test();162});163add_test(function test_Proxy_toJSON() {164 let p = new Proxy();165 deepEqual(p.toJSON(), {});166 // autoconfig url167 p = new Proxy();168 p.proxyType = "pac";169 p.proxyAutoconfigUrl = "foo";170 deepEqual(p.toJSON(), { proxyType: "pac", proxyAutoconfigUrl: "foo" });171 // manual proxy172 p = new Proxy();173 p.proxyType = "manual";174 deepEqual(p.toJSON(), { proxyType: "manual" });175 for (let proxy of ["httpProxy", "sslProxy", "socksProxy"]) {176 let expected = { proxyType: "manual" };177 p = new Proxy();178 p.proxyType = "manual";179 if (proxy == "socksProxy") {180 p.socksVersion = 5;181 expected.socksVersion = 5;182 }183 // without port184 p[proxy] = "foo";185 expected[proxy] = "foo";186 deepEqual(p.toJSON(), expected);187 // with port188 p[proxy] = "foo";189 p[`${proxy}Port`] = 0;190 expected[proxy] = "foo:0";191 deepEqual(p.toJSON(), expected);192 p[`${proxy}Port`] = 42;193 expected[proxy] = "foo:42";194 deepEqual(p.toJSON(), expected);195 // add brackets for IPv6 address as proxy hostname196 p[proxy] = "2001:db8::1";197 p[`${proxy}Port`] = 42;198 expected[proxy] = "foo:42";199 expected[proxy] = "[2001:db8::1]:42";200 deepEqual(p.toJSON(), expected);201 }202 // noProxy: add brackets for IPv6 address203 p = new Proxy();204 p.proxyType = "manual";205 p.noProxy = ["2001:db8::1"];206 let expected = { proxyType: "manual", noProxy: "[2001:db8::1]" };207 deepEqual(p.toJSON(), expected);208 run_next_test();209});210add_test(function test_Proxy_fromJSON() {211 let p = new Proxy();212 deepEqual(p, Proxy.fromJSON(undefined));213 deepEqual(p, Proxy.fromJSON(null));214 for (let typ of [true, 42, "foo", []]) {215 Assert.throws(() => Proxy.fromJSON(typ), /InvalidArgumentError/);216 }217 // must contain a valid proxyType218 Assert.throws(() => Proxy.fromJSON({}), /InvalidArgumentError/);219 Assert.throws(220 () => Proxy.fromJSON({ proxyType: "foo" }),221 /InvalidArgumentError/222 );223 // autoconfig url224 for (let url of [true, 42, [], {}]) {225 Assert.throws(226 () => Proxy.fromJSON({ proxyType: "pac", proxyAutoconfigUrl: url }),227 /InvalidArgumentError/228 );229 }230 p = new Proxy();231 p.proxyType = "pac";232 p.proxyAutoconfigUrl = "foo";233 deepEqual(p, Proxy.fromJSON({ proxyType: "pac", proxyAutoconfigUrl: "foo" }));234 // manual proxy235 p = new Proxy();236 p.proxyType = "manual";237 deepEqual(p, Proxy.fromJSON({ proxyType: "manual" }));238 for (let proxy of ["httpProxy", "sslProxy", "socksProxy"]) {239 let manual = { proxyType: "manual" };240 // invalid hosts241 for (let host of [242 true,243 42,244 [],245 {},246 null,247 "http://foo",248 "foo:-1",249 "foo:65536",250 "foo/test",251 "foo#42",252 "foo?foo=bar",253 "2001:db8::1",254 ]) {255 manual[proxy] = host;256 Assert.throws(() => Proxy.fromJSON(manual), /InvalidArgumentError/);257 }258 p = new Proxy();259 p.proxyType = "manual";260 if (proxy == "socksProxy") {261 manual.socksVersion = 5;262 p.socksVersion = 5;263 }264 let host_map = {265 "foo:1": { hostname: "foo", port: 1 },266 "foo:21": { hostname: "foo", port: 21 },267 "foo:80": { hostname: "foo", port: 80 },268 "foo:443": { hostname: "foo", port: 443 },269 "foo:65535": { hostname: "foo", port: 65535 },270 "127.0.0.1:42": { hostname: "127.0.0.1", port: 42 },271 "[2001:db8::1]:42": { hostname: "2001:db8::1", port: "42" },272 };273 // valid proxy hosts with port274 for (let host in host_map) {275 manual[proxy] = host;276 p[`${proxy}`] = host_map[host].hostname;277 p[`${proxy}Port`] = host_map[host].port;278 deepEqual(p, Proxy.fromJSON(manual));279 }280 // Without a port the default port of the scheme is used281 for (let host of ["foo", "foo:"]) {282 manual[proxy] = host;283 // For socks no default port is available284 p[proxy] = `foo`;285 if (proxy === "socksProxy") {286 p[`${proxy}Port`] = null;287 } else {288 let default_ports = { httpProxy: 80, sslProxy: 443 };289 p[`${proxy}Port`] = default_ports[proxy];290 }291 deepEqual(p, Proxy.fromJSON(manual));292 }293 }294 // missing required socks version295 Assert.throws(296 () => Proxy.fromJSON({ proxyType: "manual", socksProxy: "foo:1234" }),297 /InvalidArgumentError/298 );299 // Bug 1703805: Since Firefox 90 ftpProxy is no longer supported300 Assert.throws(301 () => Proxy.fromJSON({ proxyType: "manual", ftpProxy: "foo:21" }),302 /InvalidArgumentError/303 );304 // noProxy: invalid settings305 for (let noProxy of [true, 42, {}, null, "foo", [true], [42], [{}], [null]]) {306 Assert.throws(307 () => Proxy.fromJSON({ proxyType: "manual", noProxy }),308 /InvalidArgumentError/309 );310 }311 // noProxy: valid settings312 p = new Proxy();313 p.proxyType = "manual";314 for (let noProxy of [[], ["foo"], ["foo", "bar"], ["127.0.0.1"]]) {315 let manual = { proxyType: "manual", noProxy };316 p.noProxy = noProxy;317 deepEqual(p, Proxy.fromJSON(manual));318 }319 // noProxy: IPv6 needs brackets removed320 p = new Proxy();321 p.proxyType = "manual";322 p.noProxy = ["2001:db8::1"];323 let manual = { proxyType: "manual", noProxy: ["[2001:db8::1]"] };324 deepEqual(p, Proxy.fromJSON(manual));325 run_next_test();326});327add_test(function test_UnhandledPromptBehavior() {328 equal(UnhandledPromptBehavior.Accept, "accept");329 equal(UnhandledPromptBehavior.AcceptAndNotify, "accept and notify");330 equal(UnhandledPromptBehavior.Dismiss, "dismiss");331 equal(UnhandledPromptBehavior.DismissAndNotify, "dismiss and notify");332 equal(UnhandledPromptBehavior.Ignore, "ignore");333 run_next_test();334});335add_test(function test_Capabilities_ctor() {336 let caps = new Capabilities();337 ok(caps.has("browserName"));338 ok(caps.has("browserVersion"));339 ok(caps.has("platformName"));340 ok(["linux", "mac", "windows", "android"].includes(caps.get("platformName")));341 ok(caps.has("platformVersion"));342 equal(PageLoadStrategy.Normal, caps.get("pageLoadStrategy"));343 equal(false, caps.get("acceptInsecureCerts"));344 ok(caps.get("timeouts") instanceof Timeouts);345 ok(caps.get("proxy") instanceof Proxy);346 equal(caps.get("setWindowRect"), !AppInfo.isAndroid);347 equal(caps.get("strictFileInteractability"), false);348 equal(caps.get("webSocketUrl"), null);349 equal(false, caps.get("moz:accessibilityChecks"));350 ok(caps.has("moz:buildID"));351 ok(caps.has("moz:debuggerAddress"));352 ok(caps.has("moz:processID"));353 ok(caps.has("moz:profile"));354 equal(false, caps.get("moz:useNonSpecCompliantPointerOrigin"));355 equal(true, caps.get("moz:webdriverClick"));356 run_next_test();357});358add_test(function test_Capabilities_toString() {359 equal("[object Capabilities]", new Capabilities().toString());360 run_next_test();361});362add_test(function test_Capabilities_toJSON() {363 let caps = new Capabilities();364 let json = caps.toJSON();365 equal(caps.get("browserName"), json.browserName);366 equal(caps.get("browserVersion"), json.browserVersion);367 equal(caps.get("platformName"), json.platformName);368 equal(caps.get("platformVersion"), json.platformVersion);369 equal(caps.get("pageLoadStrategy"), json.pageLoadStrategy);370 equal(caps.get("acceptInsecureCerts"), json.acceptInsecureCerts);371 deepEqual(caps.get("proxy").toJSON(), json.proxy);372 deepEqual(caps.get("timeouts").toJSON(), json.timeouts);373 equal(caps.get("setWindowRect"), json.setWindowRect);374 equal(caps.get("strictFileInteractability"), json.strictFileInteractability);375 equal(caps.get("webSocketUrl"), json.webSocketUrl);376 equal(caps.get("moz:accessibilityChecks"), json["moz:accessibilityChecks"]);377 equal(caps.get("moz:buildID"), json["moz:buildID"]);378 equal(caps.get("moz:debuggerAddress"), json["moz:debuggerAddress"]);379 equal(caps.get("moz:processID"), json["moz:processID"]);380 equal(caps.get("moz:profile"), json["moz:profile"]);381 equal(382 caps.get("moz:useNonSpecCompliantPointerOrigin"),383 json["moz:useNonSpecCompliantPointerOrigin"]384 );385 equal(caps.get("moz:webdriverClick"), json["moz:webdriverClick"]);386 run_next_test();387});388add_test(function test_Capabilities_fromJSON() {389 const { fromJSON } = Capabilities;390 // plain391 for (let typ of [{}, null, undefined]) {392 ok(fromJSON(typ).has("browserName"));393 }394 for (let typ of [true, 42, "foo", []]) {395 Assert.throws(() => fromJSON(typ), /InvalidArgumentError/);396 }397 // matching398 let caps = new Capabilities();399 caps = fromJSON({ acceptInsecureCerts: true });400 equal(true, caps.get("acceptInsecureCerts"));401 caps = fromJSON({ acceptInsecureCerts: false });402 equal(false, caps.get("acceptInsecureCerts"));403 Assert.throws(404 () => fromJSON({ acceptInsecureCerts: "foo" }),405 /InvalidArgumentError/406 );407 for (let strategy of Object.values(PageLoadStrategy)) {408 caps = fromJSON({ pageLoadStrategy: strategy });409 equal(strategy, caps.get("pageLoadStrategy"));410 }411 Assert.throws(412 () => fromJSON({ pageLoadStrategy: "foo" }),413 /InvalidArgumentError/414 );415 Assert.throws(416 () => fromJSON({ pageLoadStrategy: null }),417 /InvalidArgumentError/418 );419 let proxyConfig = { proxyType: "manual" };420 caps = fromJSON({ proxy: proxyConfig });421 equal("manual", caps.get("proxy").proxyType);422 let timeoutsConfig = { implicit: 123 };423 caps = fromJSON({ timeouts: timeoutsConfig });424 equal(123, caps.get("timeouts").implicit);425 if (!AppInfo.isAndroid) {426 caps = fromJSON({ setWindowRect: true });427 equal(true, caps.get("setWindowRect"));428 Assert.throws(429 () => fromJSON({ setWindowRect: false }),430 /InvalidArgumentError/431 );432 } else {433 Assert.throws(434 () => fromJSON({ setWindowRect: true }),435 /InvalidArgumentError/436 );437 }438 caps = fromJSON({ strictFileInteractability: false });439 equal(false, caps.get("strictFileInteractability"));440 caps = fromJSON({ strictFileInteractability: true });441 equal(true, caps.get("strictFileInteractability"));442 caps = fromJSON({ webSocketUrl: true });443 equal(true, caps.get("webSocketUrl"));444 Assert.throws(445 () => fromJSON({ webSocketUrl: false }),446 /InvalidArgumentError/447 );448 Assert.throws(449 () => fromJSON({ webSocketUrl: "foo" }),450 /InvalidArgumentError/451 );452 caps = fromJSON({ "moz:accessibilityChecks": true });453 equal(true, caps.get("moz:accessibilityChecks"));454 caps = fromJSON({ "moz:accessibilityChecks": false });455 equal(false, caps.get("moz:accessibilityChecks"));456 Assert.throws(457 () => fromJSON({ "moz:accessibilityChecks": "foo" }),458 /InvalidArgumentError/459 );460 Assert.throws(461 () => fromJSON({ "moz:accessibilityChecks": 1 }),462 /InvalidArgumentError/463 );464 // capability is always populated with null if remote agent is not listening465 caps = fromJSON({});466 equal(null, caps.get("moz:debuggerAddress"));467 caps = fromJSON({ "moz:debuggerAddress": "foo" });468 equal(null, caps.get("moz:debuggerAddress"));469 caps = fromJSON({ "moz:debuggerAddress": true });470 equal(null, caps.get("moz:debuggerAddress"));471 caps = fromJSON({ "moz:useNonSpecCompliantPointerOrigin": false });472 equal(false, caps.get("moz:useNonSpecCompliantPointerOrigin"));473 caps = fromJSON({ "moz:useNonSpecCompliantPointerOrigin": true });474 equal(true, caps.get("moz:useNonSpecCompliantPointerOrigin"));475 Assert.throws(476 () => fromJSON({ "moz:useNonSpecCompliantPointerOrigin": "foo" }),477 /InvalidArgumentError/478 );479 Assert.throws(480 () => fromJSON({ "moz:useNonSpecCompliantPointerOrigin": 1 }),481 /InvalidArgumentError/482 );483 caps = fromJSON({ "moz:webdriverClick": true });484 equal(true, caps.get("moz:webdriverClick"));485 caps = fromJSON({ "moz:webdriverClick": false });486 equal(false, caps.get("moz:webdriverClick"));487 Assert.throws(488 () => fromJSON({ "moz:webdriverClick": "foo" }),489 /InvalidArgumentError/490 );491 Assert.throws(492 () => fromJSON({ "moz:webdriverClick": 1 }),493 /InvalidArgumentError/494 );495 run_next_test();496});497// use Proxy.toJSON to test marshal498add_test(function test_marshal() {499 let proxy = new Proxy();500 // drop empty fields501 deepEqual({}, proxy.toJSON());502 proxy.proxyType = "manual";503 deepEqual({ proxyType: "manual" }, proxy.toJSON());504 proxy.proxyType = null;505 deepEqual({}, proxy.toJSON());506 proxy.proxyType = undefined;507 deepEqual({}, proxy.toJSON());508 // iterate over object literals509 proxy.proxyType = { foo: "bar" };510 deepEqual({ proxyType: { foo: "bar" } }, proxy.toJSON());511 // iterate over complex object that implement toJSON512 proxy.proxyType = new Proxy();513 deepEqual({}, proxy.toJSON());514 proxy.proxyType.proxyType = "manual";515 deepEqual({ proxyType: { proxyType: "manual" } }, proxy.toJSON());516 // drop objects with no entries517 proxy.proxyType = { foo: {} };518 deepEqual({}, proxy.toJSON());519 proxy.proxyType = { foo: new Proxy() };520 deepEqual({}, proxy.toJSON());521 run_next_test();...
script.js
Source:script.js
...210 onIsOpenChange(isOpen) {211 if (isOpen) {212 this.$nextTick(() => {213 if (this.openCount++ == 0) {214 this.setWindowRect(this)215 this.setInitialPosition()216 }217 this.resizable && this.onWindowResize()218 this.onWindowMove()219 if (this.draggable) {220 this.draggableHelper = new DraggableHelper(221 this.titlebarElement(),222 this.windowElement(),223 {224 onMove: () => this.onWindowMove(),225 onMoveStart: () => this.$emit('move-start'),226 onMoveEnd: () => this.$emit('move-end'),227 }228 )229 }230 this.resizable && this.initResizeHelper()231 })232 this.activateWhenOpen && this.activate()233 }234 },235 onZGroupChange() {236 this.zElement.group = this.zGroup237 },238 fixPosition() {239 // const w = this.windowElement()240 // const rect = w.getBoundingClientRect()241 // if (rect.left < 0) w.style.left = `0px`242 // if (rect.top < 0) w.style.top = `0px`243 // if (rect.right > window.innerWidth)244 // w.style.left = `${window.innerWidth - rect.width}px`245 // if (rect.bottom > window.innerHeight)246 // w.style.top = `${window.innerHeight - rect.height}px`247 if (!this.resizeSiders.length) {248 this.setInitialPosition()249 }250 },251 onLeftChange(left) {252 this.setWindowRect({ left })253 this.onWindowMove(false)254 },255 onTopChange(top) {256 this.setWindowRect({ top })257 this.onWindowMove(false)258 },259 onWidthChange(width) {260 this.setWindowRect({ width })261 this.onWindowResize(false)262 },263 onHeightChange(height) {264 this.setWindowRect({ height })265 this.onWindowResize(false)266 },267 setWindowRect({ width, height, top, left }) {268 const w = this.windowElement()269 if (width != undefined) {270 w.style.width = `${width}px`271 }272 if (height != undefined) {273 const tHeight = contentSize(this.titlebarElement()).height274 w.style.height = `${height + tHeight}px`275 }276 if (left != undefined) {277 w.style.left = `${left}px`278 }279 if (top != undefined) {280 w.style.top = `${top}px`281 }...
pickerCommon.js
Source:pickerCommon.js
...87 * @param {!number} height in CSS pixel88 */89function resizeWindow(width, height) {90 var zoom = global.params.zoomFactor ? global.params.zoomFactor : 1;91 setWindowRect(adjustWindowRect(width * zoom, height * zoom, width * zoom, height * zoom));92}93/**94 * @param {!number} width in physical pixel95 * @param {!number} height in physical pixel96 * @param {?number} minWidth in physical pixel97 * @param {?number} minHeight in physical pixel98 * @return {!Rectangle} Adjusted rectangle with physical pixels99 */100function adjustWindowRect(width, height, minWidth, minHeight) {101 if (typeof minWidth !== "number")102 minWidth = 0;103 if (typeof minHeight !== "number")104 minHeight = 0;105 var windowRect = new Rectangle(0, 0, Math.ceil(width), Math.ceil(height));106 if (!global.params.anchorRectInScreen)107 return windowRect;108 var anchorRect = new Rectangle(global.params.anchorRectInScreen);109 var availRect = new Rectangle(window.screen.availLeft, window.screen.availTop, window.screen.availWidth, window.screen.availHeight);110 _adjustWindowRectVertically(windowRect, availRect, anchorRect, minHeight);111 _adjustWindowRectHorizontally(windowRect, availRect, anchorRect, minWidth);112 return windowRect;113}114/**115 * Arguments are physical pixels.116 */117function _adjustWindowRectVertically(windowRect, availRect, anchorRect, minHeight) {118 var availableSpaceAbove = anchorRect.y - availRect.y;119 availableSpaceAbove = Math.max(0, Math.min(availRect.height, availableSpaceAbove));120 var availableSpaceBelow = availRect.maxY - anchorRect.maxY;121 availableSpaceBelow = Math.max(0, Math.min(availRect.height, availableSpaceBelow));122 if (windowRect.height > availableSpaceBelow && availableSpaceBelow < availableSpaceAbove) {123 windowRect.height = Math.min(windowRect.height, availableSpaceAbove);124 windowRect.height = Math.max(windowRect.height, minHeight);125 windowRect.y = anchorRect.y - windowRect.height;126 } else {127 windowRect.height = Math.min(windowRect.height, availableSpaceBelow);128 windowRect.height = Math.max(windowRect.height, minHeight);129 windowRect.y = anchorRect.maxY;130 }131}132/**133 * Arguments are physical pixels.134 */135function _adjustWindowRectHorizontally(windowRect, availRect, anchorRect, minWidth) {136 windowRect.width = Math.min(windowRect.width, availRect.width);137 windowRect.width = Math.max(windowRect.width, minWidth);138 windowRect.x = anchorRect.x;139 // If we are getting clipped, we want to switch alignment to the right side140 // of the anchor rect as long as doing so will make the popup not clipped.141 var rightAlignedX = windowRect.x + anchorRect.width - windowRect.width;142 if (rightAlignedX >= availRect.x && (windowRect.maxX > availRect.maxX || global.params.isRTL))143 windowRect.x = rightAlignedX;144}145/**146 * @param {!Rectangle} rect Window position and size with physical pixels.147 */148function setWindowRect(rect) {149 if (window.frameElement) {150 window.frameElement.style.width = rect.width + "px";151 window.frameElement.style.height = rect.height + "px";152 } else {153 window.pagePopupController.setWindowRect(rect.x, rect.y, rect.width, rect.height);154 }155}156function hideWindow() {157 setWindowRect(adjustWindowRect(1, 1, 1, 1));158}159/**160 * @return {!boolean}161 */162function isWindowHidden() {163 // window.innerWidth and innerHeight are zoom-adjusted values. If we call164 // setWindowRect with width=100 and the zoom-level is 2.0, innerWidth will165 // return 50.166 return window.innerWidth <= 1 && window.innerHeight <= 1;167}168window.addEventListener("resize", function() {169 if (isWindowHidden())170 window.dispatchEvent(new CustomEvent("didHide"));171 else...
test-responsive.js
Source:test-responsive.js
...44 });45 it('should layout correctly after resize', async() => {46 const firstSlide = await getSlide(controller, 0);47 await waitForCarouselImg(controller, 0);48 await controller.setWindowRect({49 width: 600,50 height: 600,51 });52 // 2 slides width width 600 = 300 width per slide.53 await expect(controller.getElementRect(firstSlide)).to.include({54 width: 300,55 x: 0,56 });57 });58 it('should retain position when changing the visible count', async() => {59 const el = await getScrollingElement(controller);60 const secondSlide = await getSlide(controller, 1);61 await controller.scroll(el, {left: 333});62 await expect(prop(el, 'scrollLeft')).to.equal(333);63 await controller.setWindowRect({64 width: 600,65 height: 600,66 });67 await expect(controller.getElementRect(secondSlide)).to.include({x: 0});68 });69 it('should respond to attribute changes', async() => {70 const firstSlide = await getSlide(controller, 0);71 // 3 slides width width 1000 = 333 width per slide.72 await expect(controller.getElementRect(firstSlide)).to.include({73 width: 333,74 x: 0,75 });76 // Switch over to `visible-count="(min-width: 650px) 5, 4".77 const btn = await controller.findElement('#responsive-5-4');78 await controller.click(btn);79 // 5 slides width width 1000 = 200 width per slide80 await expect(controller.getElementRect(firstSlide)).to.include({81 width: 200,82 x: 0,83 });84 // Now make sure new media query is active.85 await controller.setWindowRect({86 width: 600,87 height: 600,88 });89 // 4 slides width width 600 = 150 width per slide.90 await expect(controller.getElementRect(firstSlide)).to.include({91 width: 150,92 x: 0,93 });94 });...
setWindowRect.js
Source:setWindowRect.js
...11 * All attributes are in in CSS pixels. To change the window react, you can either specify `width` and `height`, `x` and `y` or all properties together.12 *13 * @example14 * module.exports = {15 * 'demo test .setWindowRect()': function(browser) {16 *17 * // Change the screenX and screenY attributes of the window rect.18 * browser.setWindowRect({x: 500, y: 500});19 *20 * // Change the width and height attributes of the window rect.21 * browser.setWindowRect({width: 600, height: 300});22 *23 * // Retrieve the attributes24 * browser.setWindowRect(function(result) {25 * console.log(result.value);26 * });27 * },28 *29 * 'setWindowRect ES6 demo test': async function(browser) {30 * await browser.setWindowRect({31 * width: 600,32 * height: 300,33 * x: 100,34 * y: 10035 * });36 * }37 * }38 *39 * @w3c40 * @link /#dfn-get-window-rect41 * @method setWindowRect42 * @syntax .setWindowRect({width, height, x, y}, [callback]);43 * @param {object} options An object specifying either `width` and `height`, `x` and `y`, or all together to set properties for the [window rect](https://w3c.github.io/webdriver/#dfn-window-rect).44 * @param {function} [callback] Optional callback function to be called when the command finishes.45 * @see windowRect46 * @api protocol.contexts47 */48class SetWindowRect extends ClientCommand {49 performAction(callback) {50 this.api.windowRect(this.options, callback);51 }52 command(options, callback) {53 this.options = options;54 return super.command(callback);55 }56}...
test-amp-sidebar-toolbar.js
Source:test-amp-sidebar-toolbar.js
...24 beforeEach(() => {25 controller = env.controller;26 });27 it('should trigger the toolbar layout when viewport is resized', async () => {28 await controller.setWindowRect({width: 800, height: 600});29 const navElement = await controller.findElement('#nav-target-element');30 await expect(controller.getElementProperty(navElement, 'hidden')).to.be31 .false;32 // change orientation to potrait mode.33 await controller.setWindowRect({width: 600, height: 800});34 await expect(controller.getElementProperty(navElement, 'hidden')).to.be35 .true;36 // revert to landscape mode.37 await controller.setWindowRect({width: 800, height: 600});38 await expect(controller.getElementProperty(navElement, 'hidden')).to.be39 .false;40 });41 }...
commands.js
Source:commands.js
1export default {2 newSession: 'WebDriver:NewSession',3 executeScript: 'WebDriver:ExecuteScript',4 takeScreenshot: 'WebDriver:TakeScreenshot',5 getWindowRect: 'WebDriver:GetWindowRect',6 setWindowRect: 'WebDriver:SetWindowRect',7 quit: 'Marionette:Quit'...
Using AI Code Generation
1const { remote } = require('webdriverio');2(async () => {3 const browser = await remote({4 capabilities: {5 }6 })7 await browser.setWindowRect(0, 0, 500, 500)8 await browser.pause(5000)9 await browser.deleteSession()10})().catch((e) => console.error(e))11exports.config = {12 capabilities: [{13 }],14 mochaOpts: {15 }16}
Using AI Code Generation
1var webdriverio = require('webdriverio');2var options = { desiredCapabilities: { browserName: 'chrome' } };3 .remote(options)4 .init()5 .setWindowRect(0, 0, 500, 500)6 .end();
Using AI Code Generation
1describe('webdriver.io page', () => {2 it('should have the right title', () => {3 browser.setWindowRect(0, 0, 800, 600)4 const title = browser.getTitle()5 expect(title).toEqual('WebdriverIO · Next-gen browser and mobile automation test framework for Node.js')6 })7})8describe('webdriver.io page', () => {9 it('should have the right title', () => {10 browser.setWindowSize(800, 600)11 const title = browser.getTitle()12 expect(title).toEqual('WebdriverIO · Next-gen browser and mobile automation test framework for Node.js')13 })14})15describe('webdriver.io page', () => {16 it('should have the right title', () => {17 browser.setTimeout({18 })19 const title = browser.getTitle()20 expect(title).toEqual('WebdriverIO · Next-gen browser and mobile automation test framework for Node.js')21 })22})
Using AI Code Generation
1describe('webdriver.io page', function() {2 it('should have the right title - the fancy generator way', function () {3 var title = browser.getTitle();4 expect(title).to.be.equal('WebdriverIO - Selenium 2.0 javascript bindings for nodejs');5 });6 it('should have the right title - the fancy generator way', function () {7 var title = browser.getTitle();8 expect(title).to.be.equal('Google');9 });10 it('should have the right title - the fancy generator way', function () {11 var title = browser.getTitle();12 expect(title).to.be.equal('Yahoo');13 });14 it('should have the right title - the fancy generator way', function () {15 var title = browser.getTitle();16 expect(title).to.be.equal('Bing');17 });18 it('should have the right title - the fancy generator way', function () {19 browser.setWindowRect(0,0,800,600);20 var title = browser.getTitle();21 expect(title).to.be.equal('Bing');22 });23 it('should have the right title - the fancy generator way', function () {24 browser.setWindowRect(0,0,1024,768);25 var title = browser.getTitle();26 expect(title).to.be.equal('Bing');27 });28 it('should have the right title - the fancy generator way', function () {29 browser.setWindowRect(0,0,1280,1024);30 var title = browser.getTitle();31 expect(title).to.be.equal('Bing');32 });33 it('should have the right title - the fancy generator way', function () {34 browser.setWindowRect(0,0,1920,1080);35 var title = browser.getTitle();36 expect(title).to.be.equal('Bing');37 });38 it('should have the right title - the fancy generator way', function () {39 browser.setWindowRect(0,0,1440,900);40 var title = browser.getTitle();
Using AI Code Generation
1browser.setWindowRect(0, 0, 800, 600);2browser.getWindowRect().then(function (windowSize) {3 console.log(windowSize);4});5browser.maximizeWindow();6browser.fullscreenWindow();7browser.minimizeWindow();8browser.getTitle().then(function (title) {9 console.log('Title was: ' + title);10});11browser.getUrl().then(function (url) {12 console.log('Url was: ' + url);13});14browser.getTabIds().then(function (tabIds) {15 console.log('TabIds were: ' + tabIds);16});17browser.switchTab('tabId');18browser.close();19browser.refresh();20browser.forward();21browser.back();22browser.newWindow('url');
Using AI Code Generation
1describe('WebdriverIO API Demo', function () {2 it('setWindowRect', function () {3 browser.setWindowRect(0, 0, 600, 800);4 browser.pause(3000);5 });6});
Using AI Code Generation
1browser.setWindowRect(0, 0, 1200, 800, 'current');2browser.saveScreenshot('test.png');3var webdriver = require('selenium-webdriver');4var driver = new webdriver.Builder().forBrowser('chrome').build();5driver.manage().window().setRect({width: 1200, height: 800});6driver.takeScreenshot().then(function(data) {7 require('fs').writeFile('test.png', data, 'base64', function(err) {8 console.log(err);9 });10});11var webdriver = require('selenium-webdriver');12var driver = new webdriver.Builder().forBrowser('chrome').build();13driver.manage().window().setRect({width: 1200, height: 800});14driver.takeScreenshot().then(function(data) {15 require('fs').writeFile('test.png', data, 'base64', function(err) {16 console.log(err);17 });18});19var webdriverio = require('webdriverio');20var options = {21 desiredCapabilities: {22 }23};24var client = webdriverio.remote(options);25client.init();26client.windowHandleSize({width: 1200, height: 800});27client.saveScreenshot('test.png');28var webdriver = require('selenium-webdriver');29var driver = new webdriver.Builder().forBrowser('chrome').build();30driver.manage().window().setSize(1200, 800);31driver.takeScreenshot().then(function(data) {32 require('fs').writeFile('test.png', data, 'base64', function(err) {33 console.log(err);34 });35});36var webdriver = require('selenium-webdriver');37var driver = new webdriver.Builder().forBrowser('chrome').build();38driver.manage().window().setSize(1200, 800);39driver.takeScreenshot().then(function(data) {40 require('fs').write
Wondering what could be a next-gen browser and mobile test automation framework that is also simple and concise? Yes, that’s right, it's WebdriverIO. Since the setup is very easy to follow compared to Selenium testing configuration, you can configure the features manually thereby being the center of attraction for automation testing. Therefore the testers adopt WedriverIO to fulfill their needs of browser testing.
Learn to run automation testing with WebdriverIO tutorial. Go from a beginner to a professional automation test expert with LambdaTest WebdriverIO tutorial.
Running Your First Automation Script - Learn the steps involved to execute your first Test Automation Script using WebdriverIO since the setup is very easy to follow and the features can be configured manually.
Selenium Automation With WebdriverIO - Read more about automation testing with WebdriverIO and how it supports both browsers and mobile devices.
Browser Commands For Selenium Testing - Understand more about the barriers faced while working on your Selenium Automation Scripts in WebdriverIO, the ‘browser’ object and how to use them?
Handling Alerts & Overlay In Selenium - Learn different types of alerts faced during automation, how to handle these alerts and pops and also overlay modal in WebdriverIO.
How To Use Selenium Locators? - Understand how Webdriver uses selenium locators in a most unique way since having to choose web elements very carefully for script execution is very important to get stable test results.
Deep Selectors In Selenium WebdriverIO - The most popular automation testing framework that is extensively adopted by all the testers at a global level is WebdriverIO. Learn how you can use Deep Selectors in Selenium WebdriverIO.
Handling Dropdown In Selenium - Learn more about handling dropdowns and how it's important while performing automated browser testing.
Automated Monkey Testing with Selenium & WebdriverIO - Understand how you can leverage the amazing quality of WebdriverIO along with selenium framework to automate monkey testing of your website or web applications.
JavaScript Testing with Selenium and WebdriverIO - Speed up your Javascript testing with Selenium and WebdriverIO.
Cross Browser Testing With WebdriverIO - Learn more with this step-by-step tutorial about WebdriverIO framework and how cross-browser testing is done with WebdriverIO.
Get 100 minutes of automation test minutes FREE!!