create_extended_selenium_keywords
Generate extended Robot Framework keywords for screenshots, performance monitoring, and window management in Selenium-based test automation. Produces .robot file content for enhanced web testing capabilities.
Instructions
Generate extended Robot Framework keywords for screenshots, performance monitoring, and window management. Returns .robot file content as text - does not execute.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- mcp_server.py:409-701 (handler)The @mcp.tool() decorator registers this function as an MCP tool, and the function implements the core logic by returning a multiline string containing extended Robot Framework Selenium keywords for screenshots, performance monitoring, window management, and more.@mcp.tool() def create_extended_selenium_keywords() -> str: """Generate extended Robot Framework keywords for screenshots, performance monitoring, and window management. Returns .robot file content as text - does not execute.""" return """*** Settings *** Library SeleniumLibrary Library Collections Library String Library DateTime *** Keywords *** # Screenshot Capabilities Capture Full Page Screenshot [Arguments] ${filename}=page_screenshot.png [Documentation] Capture screenshot of entire page Capture Page Screenshot ${filename} Log Screenshot saved as: ${filename} Capture Element Screenshot [Arguments] ${locator} ${filename}=element_screenshot.png [Documentation] Capture screenshot of specific element Wait Until Element Is Visible ${locator} 10s Capture Element Screenshot ${locator} ${filename} Log Element screenshot saved as: ${filename} Capture Screenshot With Timestamp [Documentation] Capture screenshot with current timestamp in filename ${timestamp}= Get Current Date result_format=%Y%m%d_%H%M%S ${filename}= Set Variable screenshot_${timestamp}.png Capture Page Screenshot ${filename} RETURN ${filename} Set Screenshot Directory [Arguments] ${directory_path} [Documentation] Set custom directory for screenshots Set Screenshot Directory ${directory_path} Log Screenshot directory set to: ${directory_path} # Text Retrieval Operations Get Element Text Value [Arguments] ${locator} [Documentation] Get text content from an element Wait Until Element Is Visible ${locator} 10s ${text}= Get Text ${locator} RETURN ${text} Get Input Field Value [Arguments] ${locator} [Documentation] Get value from input field Wait Until Element Is Visible ${locator} 10s ${value}= Get Value ${locator} RETURN ${value} Switch To Window By Title [Documentation] Switch to browser window by title [Arguments] ${expected_title} @{windows}= Get Window Handles FOR ${window} IN @{windows} Switch Window ${window} ${title}= Get Title IF '${title}' == '${expected_title}' RETURN END END Fail Window with title '${expected_title}' not found Switch To Window By URL [Documentation] Switch to browser window by URL pattern [Arguments] ${url_pattern} @{windows}= Get Window Handles FOR ${window} IN @{windows} Switch Window ${window} ${current_url}= Get Location IF '${url_pattern}' in '${current_url}' RETURN END END Fail Window with URL pattern '${url_pattern}' not found Close Other Windows [Documentation] Close all windows except the current one ${main_window}= Get Window Handles ${main_window}= Get From List ${main_window} 0 @{all_windows}= Get Window Handles FOR ${window} IN @{all_windows} IF '${window}' != '${main_window}' Switch Window ${window} Close Window END END Switch Window ${main_window} Get Page Performance Metrics [Documentation] Get basic page performance metrics using JavaScript ${load_time}= Execute Javascript return window.performance.timing.loadEventEnd - window.performance.timing.navigationStart ${dom_ready}= Execute Javascript return window.performance.timing.domContentLoadedEventEnd - window.performance.timing.navigationStart ${metrics}= Create Dictionary load_time=${load_time} dom_ready=${dom_ready} [Return] ${metrics} Scroll To Element Smoothly [Documentation] Scroll to element with smooth animation [Arguments] ${locator} Execute Javascript ... var element = document.evaluate("${locator}", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; ... if (element) { element.scrollIntoView({behavior: 'smooth', block: 'center'}); } Check Element Visibility Percentage [Documentation] Check what percentage of element is visible in viewport [Arguments] ${locator} ${visibility}= Execute Javascript ... var element = document.evaluate("${locator}", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; ... if (!element) return 0; ... var rect = element.getBoundingClientRect(); ... var viewport = {width: window.innerWidth, height: window.innerHeight}; ... var visible = Math.max(0, Math.min(rect.right, viewport.width) - Math.max(rect.left, 0)) * ... Math.max(0, Math.min(rect.bottom, viewport.height) - Math.max(rect.top, 0)); ... var total = rect.width * rect.height; ... return total > 0 ? (visible / total * 100).toFixed(2) : 0; [Return] ${visibility} Take Element Screenshot [Documentation] Take screenshot of specific element [Arguments] ${locator} ${filename}=element_screenshot.png Capture Element Screenshot ${locator} ${filename} [Return] ${filename} Get All List Labels [Arguments] ${locator} [Documentation] Get all available option labels from dropdown Wait Until Element Is Visible ${locator} 10s ${labels}= Get List Items ${locator} RETURN ${labels} Get Page Title [Documentation] Get current page title ${title}= Get Title RETURN ${title} Get Current URL [Documentation] Get current page URL ${url}= Get Location RETURN ${url} Get Page Source [Documentation] Get complete page source HTML ${source}= Get Source RETURN ${source} # Window Management Operations Get Current Window Position [Documentation] Get current window position coordinates ${position}= Get Window Position Log Current window position: ${position} RETURN ${position} Set Window Position [Arguments] ${x} ${y} [Documentation] Set window position to specific coordinates Set Window Position ${x} ${y} Log Window position set to: ${x}, ${y} Get Current Window Size [Documentation] Get current window size dimensions ${size}= Get Window Size Log Current window size: ${size} RETURN ${size} Set Window Size [Arguments] ${width} ${height} [Documentation] Set window size to specific dimensions Set Window Size ${width} ${height} Log Window size set to: ${width}x${height} Center Window On Screen [Documentation] Center the browser window on screen ${screen_width}= Execute JavaScript return screen.width; ${screen_height}= Execute JavaScript return screen.height; ${window_width}= Set Variable 1200 ${window_height}= Set Variable 800 ${x}= Evaluate (${screen_width} - ${window_width}) // 2 ${y}= Evaluate (${screen_height} - ${window_height}) // 2 Set Window Size ${window_width} ${window_height} Set Window Position ${x} ${y} Minimize Browser Window [Documentation] Minimize the browser window Execute JavaScript window.blur(); Restore Window Size [Arguments] ${width}=1024 ${height}=768 [Documentation] Restore window to default size Set Window Size ${width} ${height} Maximize Browser Window # Performance and Logging Operations Get Browser Console Logs [Documentation] Retrieve browser console logs ${logs}= Get Browser Logs Log Many @{logs} RETURN ${logs} Log Performance Metrics [Documentation] Log browser performance metrics ${navigation_timing}= Execute JavaScript return JSON.stringify(performance.getEntriesByType('navigation')[0]); ${paint_timing}= Execute JavaScript return JSON.stringify(performance.getEntriesByType('paint')); Log Navigation Timing: ${navigation_timing} Log Paint Timing: ${paint_timing} Measure Page Load Time [Documentation] Measure and return page load time in milliseconds ${load_time}= Execute JavaScript return performance.getEntriesByType('navigation')[0].loadEventEnd - performance.getEntriesByType('navigation')[0].navigationStart; Log Page load time: ${load_time} ms RETURN ${load_time} Get Network Performance [Documentation] Get network performance information ${network_info}= Execute JavaScript ... return JSON.stringify({ ... connection: navigator.connection || navigator.mozConnection || navigator.webkitConnection, ... onLine: navigator.onLine, ... cookieEnabled: navigator.cookieEnabled ... }); Log Network Info: ${network_info} RETURN ${network_info} Set Browser Implicit Wait [Arguments] ${timeout}=10s [Documentation] Set implicit wait timeout for element finding Set Browser Implicit Wait ${timeout} Log Browser implicit wait set to: ${timeout} Log Browser Information [Documentation] Log comprehensive browser information ${user_agent}= Execute JavaScript return navigator.userAgent; ${viewport}= Execute JavaScript return window.innerWidth + 'x' + window.innerHeight; ${screen_resolution}= Execute JavaScript return screen.width + 'x' + screen.height; ${color_depth}= Execute JavaScript return screen.colorDepth; Log User Agent: ${user_agent} Log Viewport Size: ${viewport} Log Screen Resolution: ${screen_resolution} Log Color Depth: ${color_depth} Monitor Page Resources [Documentation] Monitor and log page resource loading ${resources}= Execute JavaScript ... var resources = performance.getEntriesByType('resource'); ... var resourceInfo = resources.map(function(resource) { ... return { ... name: resource.name, ... type: resource.initiatorType, ... size: resource.transferSize, ... duration: resource.duration ... }; ... }); ... return JSON.stringify(resourceInfo); Log Page Resources: ${resources} RETURN ${resources} Clear Browser Performance Data [Documentation] Clear browser performance timing data Execute JavaScript performance.clearResourceTimings(); Execute JavaScript performance.clearMarks(); Execute JavaScript performance.clearMeasures(); Log Browser performance data cleared # Enhanced Screenshot Operations with Elements Compare Screenshots [Arguments] ${baseline_screenshot} ${current_screenshot} ${threshold}=0.95 [Documentation] Compare two screenshots (requires additional image comparison library) Log Comparing ${baseline_screenshot} with ${current_screenshot} # Note: This would require additional image comparison library like Pillow # For now, just logging the comparison request Take Screenshot On Failure [Documentation] Take screenshot when test fails (for teardown use) ${test_name}= Get Variable Value ${TEST_NAME} unknown_test ${timestamp}= Get Current Date result_format=%Y%m%d_%H%M%S ${filename}= Set Variable failure_${test_name}_${timestamp}.png Capture Page Screenshot ${filename} Log Failure screenshot saved: ${filename} Take Element Screenshot With Highlight [Arguments] ${locator} ${filename}=highlighted_element.png [Documentation] Take screenshot of element with visual highlight Wait Until Element Is Visible ${locator} 10s # Add visual highlight Execute JavaScript arguments[0].style.border = '3px solid red'; ARGUMENTS ${locator} Sleep 0.5s Capture Element Screenshot ${locator} ${filename} # Remove highlight Execute JavaScript arguments[0].style.border = ''; ARGUMENTS ${locator} Log Highlighted element screenshot saved: ${filename} """ return template
- mcp_server.py:409-409 (registration)The @mcp.tool() decorator registers the 'create_extended_selenium_keywords' tool with the MCP server.@mcp.tool()