# 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 re
from playwright.async_api import Page, expect
async def test_get_by_escaping(page: Page) -> None:
await page.set_content(
"""
"""
)
await page.eval_on_selector(
"input",
"""input => {
input.setAttribute('placeholder', 'hello my\\nwo"rld');
input.setAttribute('title', 'hello my\\nwo"rld');
input.setAttribute('alt', 'hello my\\nwo"rld');
}""",
)
await expect(page.get_by_text('hello my\nwo"rld')).to_have_attribute("id", "label")
await expect(page.get_by_text('hello my wo"rld')).to_have_attribute("id", "label")
await expect(page.get_by_label('hello my\nwo"rld')).to_have_attribute("id", "control")
await expect(page.get_by_placeholder('hello my\nwo"rld')).to_have_attribute("id", "control")
await expect(page.get_by_alt_text('hello my\nwo"rld')).to_have_attribute("id", "control")
await expect(page.get_by_title('hello my\nwo"rld')).to_have_attribute("id", "control")
await page.set_content(
"""
"""
)
await page.eval_on_selector(
"input",
"""input => {
input.setAttribute('placeholder', 'hello my\\nworld');
input.setAttribute('title', 'hello my\\nworld');
input.setAttribute('alt', 'hello my\\nworld');
}""",
)
await expect(page.get_by_text("hello my\nworld")).to_have_attribute("id", "label")
await expect(page.get_by_text("hello my world")).to_have_attribute("id", "label")
await expect(page.get_by_label("hello my\nworld")).to_have_attribute("id", "control")
await expect(page.get_by_placeholder("hello my\nworld")).to_have_attribute("id", "control")
await expect(page.get_by_alt_text("hello my\nworld")).to_have_attribute("id", "control")
await expect(page.get_by_title("hello my\nworld")).to_have_attribute("id", "control")
await page.set_content("""