Skip to content

Instantly share code, notes, and snippets.

@tomppa65
Created November 24, 2024 17:49
Show Gist options
  • Save tomppa65/4ddea187309e41401869e0f1e3ffb35b to your computer and use it in GitHub Desktop.
Save tomppa65/4ddea187309e41401869e0f1e3ffb35b to your computer and use it in GitHub Desktop.
This gist shows the difference of using locator.fill in playwright when small strings are separated by a single space compared to being separated by a newline. Also, the difference between the three major browsers is staggering!
"""Test Playwright in entering text to textarea element.
"""
import time
from playwright.sync_api import sync_playwright, Page, expect
T_O = 300000 # Five minutes
def textarea_fill_separated_by(page: Page, sep: str):
"""Test entering data to textarea when separated by blanks and newlines.
"""
for i in range(1000, 4001, 1000):
joined_string = sep.join(['some text'] * i)
start = time.time()
page.get_by_label('Message:').fill(joined_string, timeout=T_O)
end = time.time()
combinator = 'blanks' if sep == ' ' else 'newlines'
delta = round((end - start), 3)
print(f'Entering {i} text separated by {combinator} took {delta}'
' seconds')
page.locator('css=textarea#message-text').fill('')
with sync_playwright() as p:
for browser in [p.firefox.launch(headless=False),
p.webkit.launch(headless=False),
p.chromium.launch(headless=False)]:
print('\n')
print(f'Browser is: {browser.browser_type.name}')
page = browser.new_page()
page.goto("https://demoblaze.com/index.html")
# Expect a title
expect(page).to_have_title('STORE')
#
page.get_by_role("link", name="Contact").click()
#
textarea_fill_separated_by(page, ' ')
textarea_fill_separated_by(page, '\n')
browser.close()
@tomppa65
Copy link
Author

tomppa65 commented Nov 24, 2024

Firefox has no problem with multiline texts, four thousand lines are filled under a second,
webkit starts to choke a bit at 3000 lines but.
chromium takes well over a minute to enter 4000 lines to a textarea element!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment