Skip to main content
Glama

create_login_test_case

Generates Robot Framework test case code for login functionality, returning the complete .robot file content. Input URL, username, and password to create automated login test scripts without execution.

Instructions

Generate Robot Framework test case code for login functionality. Returns the complete .robot file content as text - does not execute the test.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
passwordYes
template_typeNoappLocator
urlYes
usernameYes

Implementation Reference

  • Handler function for 'create_login_test_case' tool, decorated with @mcp.tool() for registration. Generates Robot Framework test case code using input validation, selector configs, and templating.
    @mcp.tool() def create_login_test_case(url: str, username: str, password: str, template_type: str = "appLocator") -> str: """Generate Robot Framework test case code for login functionality. Returns the complete .robot file content as text - does not execute the test.""" try: # Validate inputs validated_url = InputValidator.validate_url(url) validated_username, validated_password = InputValidator.validate_credentials(username, password) # Get selector configuration selectors = SELECTOR_CONFIGS.get(template_type.lower(), SELECTOR_CONFIGS["generic"]) # Use Template for safe variable substitution and correct Robot Framework syntax template = Template("""*** Settings *** Library SeleniumLibrary *** Variables *** $${URL} $url $${USERNAME} $username $${PASSWORD} $password $${BROWSER} Chrome # Selector Variables $${USERNAME_FIELD} $username_field $${PASSWORD_FIELD} $password_field $${LOGIN_BUTTON} $login_button $${SUCCESS_INDICATOR} $success_indicator *** Test Cases *** Login Test [Documentation] Test login functionality for $template_type [Tags] smoke login $template_type Open Browser $${URL} $${BROWSER} Maximize Browser Window Input Text $${USERNAME_FIELD} $${USERNAME} Input Text $${PASSWORD_FIELD} $${PASSWORD} Click Button $${LOGIN_BUTTON} Wait Until Page Contains Element $${SUCCESS_INDICATOR} 10s Element Text Should Be $${SUCCESS_INDICATOR} Products [Teardown] Close Browser """) return template.substitute( url=validated_url, username=validated_username, password=validated_password, template_type=template_type, username_field=selectors["username_field"], password_field=selectors["password_field"], login_button=selectors["login_button"], success_indicator=selectors["success_indicator"] ) except ValidationError as e: return f"# VALIDATION ERROR: {str(e)}\n# Please correct the input and try again." except Exception as e: return f"# UNEXPECTED ERROR: {str(e)}\n# Please contact support."
  • Predefined selector configurations for different application template types (appLocator, generic, bootstrap) used by the create_login_test_case tool.
    SELECTOR_CONFIGS = { "appLocator": { "username_field": "id=user-name", "password_field": "id=password", "login_button": "id=login-button", "success_indicator": "xpath=//span[@class='title']", "error_message": "xpath=//h3[@data-test='error']", "logout_button": "id=logout_sidebar_link" }, "generic": { "username_field": "id=username", "password_field": "id=password", "login_button": "css=button[type='submit']", "success_indicator": "css=.dashboard", "error_message": "css=.error", "logout_button": "css=.logout" }, "bootstrap": { "username_field": "css=input[name='username']", "password_field": "css=input[name='password']", "login_button": "css=.btn-primary", "success_indicator": "css=.navbar-brand", "error_message": "css=.alert-danger", "logout_button": "css=.btn-outline-secondary" } }
  • InputValidator class providing static methods for validating URL, credentials, and selectors used within the create_login_test_case tool.
    class InputValidator: """Centralized input validation for MCP tools""" @staticmethod def validate_url(url: str) -> str: """Validate and return sanitized URL""" if not url or not url.strip(): raise ValidationError("URL cannot be empty") url = url.strip() try: result = urlparse(url) if not all([result.scheme, result.netloc]): raise ValidationError(f"Invalid URL format: {url}") if result.scheme not in ['http', 'https']: raise ValidationError(f"URL must use http or https protocol: {url}") return url except Exception as e: raise ValidationError(f"URL validation failed: {str(e)}") @staticmethod def validate_credentials(username: str, password: str) -> tuple: """Validate and return sanitized credentials""" if not username or not username.strip(): raise ValidationError("Username cannot be empty") if not password or not password.strip(): raise ValidationError("Password cannot be empty") username = username.strip() password = password.strip() if len(username) > 100: raise ValidationError("Username too long (max 100 characters)") if len(password) > 100: raise ValidationError("Password too long (max 100 characters)") # Check for dangerous characters dangerous_chars = ['<', '>', '"', "'", '&', '\n', '\r', '\t'] for char in dangerous_chars: if char in username or char in password: raise ValidationError(f"Credentials contain invalid character: {char}") return username, password @staticmethod def validate_selector(selector: str) -> str: """Validate and return sanitized selector""" if not selector or not selector.strip(): raise ValidationError("Selector cannot be empty") selector = selector.strip() # Basic validation patterns valid_patterns = [ r'^id=.+', # id=element-id r'^name=.+', # name=element-name r'^class=.+', # class=element-class r'^css=.+', # css=.class-name r'^xpath=.+', # xpath=//div[@id='test'] r'^tag=.+', # tag=input r'^\w+', # plain CSS selector ] if not any(re.match(pattern, selector) for pattern in valid_patterns): raise ValidationError(f"Invalid selector format: {selector}") return selector

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/sourcefuse/robotframework-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server