/** * Copyright (c) Microsoft Corporation. * * Licensed 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. */ import { test, expect } from './inspectorTest'; test.describe('cli codegen', () => { test.skip(({ mode }) => mode !== 'default'); test('should click locator.first', async ({ page, openRecorder }) => { const recorder = await openRecorder(); await recorder.setContentAndWait(` `); const selector = await recorder.hoverOverElement('button'); expect(selector).toBe('role=button[name=\"Submit\"] >> nth=0'); const [message, sources] = await Promise.all([ page.waitForEvent('console', msg => msg.type() !== 'error'), recorder.waitForOutput('JavaScript', 'click'), page.dispatchEvent('button', 'click', { detail: 1 }) ]); expect.soft(sources.get('JavaScript').text).toContain(` await page.getByRole('button', { name: 'Submit' }).first().click();`); expect.soft(sources.get('Python').text).toContain(` page.get_by_role("button", name="Submit").first.click()`); expect.soft(sources.get('Python Async').text).toContain(` await page.get_by_role("button", name="Submit").first.click()`); expect.soft(sources.get('Java').text).toContain(` page.getByRole("button", new Page.GetByRoleOptions().setName("Submit")).first().click();`); expect.soft(sources.get('C#').text).toContain(` await page.GetByRole("button", new () { Name = "Submit" }).First.ClickAsync();`); expect(message.text()).toBe('click1'); }); test('should click locator.nth', async ({ page, openRecorder }) => { const recorder = await openRecorder(); await recorder.setContentAndWait(` `); const selector = await recorder.hoverOverElement('button >> nth=1'); expect(selector).toBe('role=button[name=\"Submit\"] >> nth=1'); const [message, sources] = await Promise.all([ page.waitForEvent('console', msg => msg.type() !== 'error'), recorder.waitForOutput('JavaScript', 'click'), page.dispatchEvent('button', 'click', { detail: 1 }) ]); expect.soft(sources.get('JavaScript').text).toContain(` await page.getByRole('button', { name: 'Submit' }).nth(1).click();`); expect.soft(sources.get('Python').text).toContain(` page.get_by_role("button", name="Submit").nth(1).click()`); expect.soft(sources.get('Python Async').text).toContain(` await page.get_by_role("button", name="Submit").nth(1).click()`); expect.soft(sources.get('Java').text).toContain(` page.getByRole("button", new Page.GetByRoleOptions().setName("Submit")).nth(1).click();`); expect.soft(sources.get('C#').text).toContain(` await page.GetByRole("button", new () { Name = "Submit" }).Nth(1).ClickAsync();`); expect(message.text()).toBe('click2'); }); test('should generate frame locators', async ({ page, openRecorder, server }) => { const recorder = await openRecorder(); /* iframe div Hello1 iframe div Hello2 iframe[name=one] div HelloNameOne iframe[name=two] dev HelloNameTwo iframe dev HelloAnonymous */ await recorder.setContentAndWait(`