Path: blob/trunk/javascript/selenium-webdriver/test/frame_test.js
2884 views
// Licensed to the Software Freedom Conservancy (SFC) under one1// or more contributor license agreements. See the NOTICE file2// distributed with this work for additional information3// regarding copyright ownership. The SFC licenses this file4// to you under the Apache License, Version 2.0 (the5// "License"); you may not use this file except in compliance6// with the License. You may obtain a copy of the License at7//8// http://www.apache.org/licenses/LICENSE-2.09//10// Unless required by applicable law or agreed to in writing,11// software distributed under the License is distributed on an12// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY13// KIND, either express or implied. See the License for the14// specific language governing permissions and limitations15// under the License.1617'use strict'1819const assert = require('node:assert')20const test = require('../lib/test')21const { By } = require('selenium-webdriver')2223test.suite(function (env) {24var driver2526before(async function () {27driver = await env.builder().build()28})29after(function () {30return driver.quit()31})3233beforeEach(function () {34return driver.switchTo().defaultContent()35})3637it('can switch to a frame and back to the parent frame', async function () {38await driver.get(test.Pages.iframePage)3940let frame = await driver.findElement(By.name('iframe1-name'))41await driver.switchTo().frame(frame)42assert.strictEqual(await driver.executeScript('return document.title'), 'We Leave From Here')43await driver.switchTo().parentFrame()44assert.strictEqual(await driver.executeScript('return document.title'), 'This page has iframes')45})4647it('can switch to a frame by id', async function () {48await driver.get(test.Pages.iframePage)49await driver.switchTo().frame('iframe1')50assert.strictEqual(await driver.executeScript('return document.title'), 'We Leave From Here')51await driver.switchTo().parentFrame()52assert.strictEqual(await driver.executeScript('return document.title'), 'This page has iframes')53})5455it('can switch to a frame by name', async function () {56await driver.get(test.Pages.iframePage)57await driver.switchTo().frame('iframe1-name')58assert.strictEqual(await driver.executeScript('return document.title'), 'We Leave From Here')59await driver.switchTo().parentFrame()60assert.strictEqual(await driver.executeScript('return document.title'), 'This page has iframes')61})62})636465