@@ -263,6 +263,12 @@ class="profile-picture" />
263263 <!-- Elements for Event Testing -->
264264 <div class =" section" >
265265 <h2 >Event Testing</h2 >
266+ <div id =" focus-display" data-testid =" focus-display" class =" p-2 bg-blue-50 border text-sm mb-2" >No element focused yet</div >
267+ <div id =" hover-display" data-testid =" hover-display" class =" p-2 bg-green-50 border text-sm mb-2" >No element hovered yet</div >
268+ <div id =" hover-target" data-testid =" hover-target" class =" p-4 border bg-blue-100 hover:bg-blue-200 transition-colors cursor-pointer mb-4" >
269+ Hover Target
270+ </div >
271+ <input id =" focus-target" data-testid =" focus-target" type =" text" class =" bg-white text-black p-2 border focus:border-blue-500 mb-4" placeholder =" Focus on me" />
266272 <button id =" event-button" data-testid =" event-button" >Click Me</button >
267273 <div id =" event-result" data-testid =" event-result" ></div >
268274 </div >
@@ -273,9 +279,7 @@ class="profile-picture" />
273279 <div data-testid =" scroll-target" style =" margin-top : 500px ;" >
274280 This element is far down the page for scroll testing
275281 </div >
276- </div >
277-
278- <script >
282+ </div > <script >
279283 // Counter for click testing
280284 let clickCounter = 0 ;
281285
@@ -284,6 +288,22 @@ function incrementCounter() {
284288 document .querySelector (' [data-testid="click-counter"]' ).textContent = clickCounter;
285289 }
286290
291+ // Focus tracking function
292+ function trackFocus (elementId ) {
293+ const focusDisplay = document .getElementById (' focus-display' );
294+ if (focusDisplay) {
295+ focusDisplay .textContent = ' Last focused: ' + elementId;
296+ }
297+ }
298+
299+ // Hover tracking function
300+ function trackHover (elementId ) {
301+ const hoverDisplay = document .getElementById (' hover-display' );
302+ if (hoverDisplay) {
303+ hoverDisplay .textContent = ' Last hovered: ' + elementId;
304+ }
305+ }
306+
287307 // Add some basic interactivity for testing
288308 document .addEventListener (' DOMContentLoaded' , function () {
289309 // Event button click handler
@@ -296,6 +316,40 @@ function incrementCounter() {
296316 });
297317 }
298318
319+ // Add focus tracking event listeners
320+ document .getElementById (' focus-target' ).addEventListener (' focus' , function () {
321+ trackFocus (' focus-target' );
322+ });
323+ document .getElementById (' username' ).addEventListener (' focus' , function () {
324+ trackFocus (' username' );
325+ });
326+ document .getElementById (' password' ).addEventListener (' focus' , function () {
327+ trackFocus (' password' );
328+ });
329+ document .getElementById (' search' ).addEventListener (' focus' , function () {
330+ trackFocus (' search' );
331+ });
332+ document .getElementById (' comments' ).addEventListener (' focus' , function () {
333+ trackFocus (' comments' );
334+ });
335+
336+ // Hover tracking
337+ const hoverTarget = document .getElementById (' hover-target' );
338+ if (hoverTarget) {
339+ [' mouseenter' , ' mouseover' , ' pointerenter' ].forEach (event => {
340+ hoverTarget .addEventListener (event , function () {
341+ trackHover (' hover-target' );
342+ });
343+ });
344+ }
345+
346+ // Add global hover detection for Playwright compatibility
347+ document .addEventListener (' mousemove' , function (e ) {
348+ if (e .target .id === ' hover-target' ) {
349+ trackHover (' hover-target' );
350+ }
351+ });
352+
299353 // Make forms more interactive
300354 const usernameInput = document .getElementById (' username' );
301355 if (usernameInput) {
0 commit comments