-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[JS] Implement fullPageScreenshot functionality for Firefox (#13301)
- Loading branch information
Showing
5 changed files
with
296 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
139 changes: 139 additions & 0 deletions
139
javascript/node/selenium-webdriver/test/firefox/addon_test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
/* | ||
* Licensed to the Software Freedom Conservancy (SFC) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The SFC licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
'use strict' | ||
|
||
const assert = require('assert') | ||
const { Browser } = require('../../index') | ||
const { Pages, suite } = require('../../lib/test') | ||
const { locate } = require('../../lib/test/resources') | ||
const { until, By } = require('../../index') | ||
|
||
const EXT_XPI = locate('common/extensions/webextensions-selenium-example.xpi') | ||
const EXT_UNSIGNED_ZIP = locate('common/extensions/webextensions-selenium-example-unsigned.zip') | ||
const EXT_SIGNED_ZIP = locate('common/extensions/webextensions-selenium-example.zip') | ||
const EXT_UNSIGNED_DIR = locate('common/extensions/webextensions-selenium-example') | ||
const EXT_SIGNED_DIR = locate('common/extensions/webextensions-selenium-example') | ||
|
||
suite( | ||
function (env) { | ||
describe('firefox', function () { | ||
let driver | ||
|
||
beforeEach(function () { | ||
driver = null | ||
}) | ||
|
||
afterEach(function () { | ||
return driver && driver.quit() | ||
}) | ||
|
||
describe('installAddon', function () { | ||
beforeEach(function () { | ||
driver = env.builder().build() | ||
}) | ||
|
||
it('installs and uninstalls by xpi file', async function () { | ||
await driver.get(Pages.blankPage) | ||
await verifyWebExtensionNotInstalled() | ||
|
||
let id = await driver.installAddon(EXT_XPI) | ||
|
||
await driver.navigate().refresh() | ||
await verifyWebExtensionWasInstalled() | ||
|
||
await driver.uninstallAddon(id) | ||
await driver.navigate().refresh() | ||
await verifyWebExtensionNotInstalled() | ||
}) | ||
|
||
it('installs and uninstalls by unsigned zip file', async function () { | ||
await driver.get(Pages.blankPage) | ||
await verifyWebExtensionNotInstalled() | ||
|
||
let id = await driver.installAddon(EXT_UNSIGNED_ZIP, true) | ||
|
||
await driver.navigate().refresh() | ||
await verifyWebExtensionWasInstalled() | ||
|
||
await driver.uninstallAddon(id) | ||
await driver.navigate().refresh() | ||
await verifyWebExtensionNotInstalled() | ||
}) | ||
|
||
it('installs and uninstalls by signed zip file', async function () { | ||
await driver.get(Pages.blankPage) | ||
await verifyWebExtensionNotInstalled() | ||
|
||
let id = await driver.installAddon(EXT_SIGNED_ZIP) | ||
|
||
await driver.navigate().refresh() | ||
await verifyWebExtensionWasInstalled() | ||
|
||
await driver.uninstallAddon(id) | ||
await driver.navigate().refresh() | ||
await verifyWebExtensionNotInstalled() | ||
}) | ||
|
||
it('installs and uninstalls by unsigned directory', async function () { | ||
await driver.get(Pages.blankPage) | ||
await verifyWebExtensionNotInstalled() | ||
|
||
let id = await driver.installAddon(EXT_UNSIGNED_DIR, true) | ||
|
||
await driver.navigate().refresh() | ||
await verifyWebExtensionWasInstalled() | ||
|
||
await driver.uninstallAddon(id) | ||
await driver.navigate().refresh() | ||
await verifyWebExtensionNotInstalled() | ||
}) | ||
|
||
it('installs and uninstalls by signed directory', async function () { | ||
await driver.get(Pages.blankPage) | ||
await verifyWebExtensionNotInstalled() | ||
|
||
let id = await driver.installAddon(EXT_SIGNED_DIR, true) | ||
|
||
await driver.navigate().refresh() | ||
await verifyWebExtensionWasInstalled() | ||
|
||
await driver.uninstallAddon(id) | ||
await driver.navigate().refresh() | ||
await verifyWebExtensionNotInstalled() | ||
}) | ||
}) | ||
|
||
async function verifyWebExtensionNotInstalled() { | ||
let found = await driver.findElements({ | ||
id: 'webextensions-selenium-example', | ||
}) | ||
assert.strictEqual(found.length, 0) | ||
} | ||
|
||
async function verifyWebExtensionWasInstalled() { | ||
let footer = await driver.wait(until.elementLocated(By.id('webextensions-selenium-example')), 5000) | ||
|
||
let text = await footer.getText() | ||
assert.strictEqual(text, 'Content injected by webextensions-selenium-example') | ||
} | ||
}) | ||
}, | ||
{ browsers: [Browser.FIREFOX] }, | ||
) |
69 changes: 69 additions & 0 deletions
69
javascript/node/selenium-webdriver/test/firefox/contextSwitching_test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* Licensed to the Software Freedom Conservancy (SFC) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The SFC licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
'use strict' | ||
|
||
const assert = require('assert') | ||
const error = require('../../lib/error') | ||
const { Browser } = require('../../index') | ||
const { Context } = require('../../firefox') | ||
const { suite } = require('../../lib/test') | ||
|
||
suite( | ||
function (env) { | ||
describe('firefox', function () { | ||
let driver | ||
|
||
beforeEach(function () { | ||
driver = null | ||
}) | ||
|
||
afterEach(function () { | ||
return driver && driver.quit() | ||
}) | ||
|
||
describe('context switching', function () { | ||
beforeEach(async function () { | ||
driver = await env.builder().build() | ||
}) | ||
|
||
it('can get context', async function () { | ||
assert.strictEqual(await driver.getContext(), Context.CONTENT) | ||
}) | ||
|
||
it('can set context', async function () { | ||
await driver.setContext(Context.CHROME) | ||
let ctxt = await driver.getContext() | ||
assert.strictEqual(ctxt, Context.CHROME) | ||
|
||
await driver.setContext(Context.CONTENT) | ||
ctxt = await driver.getContext() | ||
assert.strictEqual(ctxt, Context.CONTENT) | ||
}) | ||
|
||
it('throws on unknown context', function () { | ||
return driver.setContext('foo').then(assert.fail, function (e) { | ||
assert(e instanceof error.InvalidArgumentError) | ||
}) | ||
}) | ||
}) | ||
}) | ||
}, | ||
{ browsers: [Browser.FIREFOX] }, | ||
) |
51 changes: 51 additions & 0 deletions
51
javascript/node/selenium-webdriver/test/firefox/full_page_screenshot_test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Licensed to the Software Freedom Conservancy (SFC) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The SFC licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
'use strict' | ||
|
||
const assert = require('assert') | ||
const { Browser } = require('../../index') | ||
const { Pages, suite } = require('../../lib/test') | ||
let startIndex = 0 | ||
let endIndex = 5 | ||
let pngMagicNumber = 'iVBOR' | ||
suite( | ||
function (env) { | ||
describe('firefox', function () { | ||
let driver | ||
|
||
beforeEach(function () { | ||
driver = null | ||
}) | ||
|
||
afterEach(function () { | ||
return driver && driver.quit() | ||
}) | ||
|
||
it('Should be able to take full page screenshot', async function () { | ||
driver = env.builder().build() | ||
await driver.get(Pages.simpleTestPage) | ||
let encoding = await driver.takeFullPageScreenshot() | ||
const base64code = encoding.slice(startIndex, endIndex) | ||
assert.equal(base64code, pngMagicNumber) | ||
}) | ||
}) | ||
}, | ||
{ browsers: [Browser.FIREFOX] }, | ||
) |
Oops, something went wrong.