-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathadvanced_example.py
More file actions
130 lines (98 loc) · 4.28 KB
/
advanced_example.py
File metadata and controls
130 lines (98 loc) · 4.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
"""
Advanced HumanTyping Example
=============================
This example demonstrates advanced features and customization options.
"""
import asyncio
from playwright.async_api import async_playwright
from humantyping import HumanTyper
async def main():
print("🚀 Advanced HumanTyping Demo\n")
async with async_playwright() as p:
browser = await p.chromium.launch(headless=False)
page = await browser.new_page()
# Navigate to a form page
await page.goto("https://www.google.com/forms/about/")
print("✓ Navigated to Google Forms\n")
# Example 1: Different typing speeds
print("Example 1: Different Typing Speeds")
print("-" * 40)
slow_typer = HumanTyper(wpm=40)
normal_typer = HumanTyper(wpm=70)
fast_typer = HumanTyper(wpm=100)
print(f"Slow typer: {slow_typer.wpm} WPM")
print(f"Normal typer: {normal_typer.wpm} WPM")
print(f"Fast typer: {fast_typer.wpm} WPM\n")
# Example 2: Multiple input fields
print("Example 2: Filling Multiple Fields")
print("-" * 40)
await page.goto("https://www.google.com")
# Create a typer for this session
typer = HumanTyper(wpm=75)
# Type into search box
search_box = page.locator("[name='q']")
await search_box.click()
print("Typing search query...")
await typer.type(search_box, "realistic typing simulation")
print("✓ Typed search query\n")
await asyncio.sleep(2)
# Clear and type again
await search_box.press("Control+A")
await asyncio.sleep(0.2)
print("Typing new query with different speed...")
fast_typer = HumanTyper(wpm=95)
await fast_typer.type(search_box, "playwright automation")
print("✓ Typed with faster speed\n")
await asyncio.sleep(2)
# Example 3: Different keyboard layout
print("Example 3: AZERTY Keyboard Layout")
print("-" * 40)
azerty_typer = HumanTyper(wpm=60, layout="azerty")
print(f"Using layout: {azerty_typer.layout}")
await search_box.press("Control+A")
await asyncio.sleep(0.2)
await azerty_typer.type(search_box, "AZERTY keyboard test")
print("✓ Typed with AZERTY layout\n")
await asyncio.sleep(2)
# Example 4: Simulating different user personas
print("Example 4: User Personas")
print("-" * 40)
personas = {
"Beginner": HumanTyper(wpm=35),
"Average User": HumanTyper(wpm=60),
"Professional": HumanTyper(wpm=85),
"Expert Typist": HumanTyper(wpm=110),
}
for persona_name, persona_typer in personas.items():
print(f"{persona_name:20} - {persona_typer.wpm} WPM")
print()
# Example 5: Long text simulation
print("Example 5: Long Text (with Fatigue)")
print("-" * 40)
long_text = (
"This is a longer piece of text that will demonstrate "
"the fatigue modeling feature. As the typing continues, "
"the speed will gradually decrease, simulating real human behavior. "
"This makes the automation much more realistic and harder to detect."
)
await search_box.press("Control+A")
await asyncio.sleep(0.2)
print("Typing long text (watch the gradual slowdown)...")
await normal_typer.type(search_box, long_text)
print("✓ Completed long text typing\n")
await asyncio.sleep(3)
# Summary
print("\n" + "=" * 50)
print("✨ Demo Complete!")
print("=" * 50)
print("\nKey Features Demonstrated:")
print(" ✓ Variable typing speeds (WPM)")
print(" ✓ Multiple keyboard layouts")
print(" ✓ User personas")
print(" ✓ Fatigue modeling over long texts")
print(" ✓ Natural errors and corrections")
print("\nTry adjusting the WPM values to see the difference!")
print()
await browser.close()
if __name__ == "__main__":
asyncio.run(main())