如何在Ranorex中从SQL数据库获取用户名和密码?自动化测试新手咨询
Hey there! Let's walk through your questions since you're just getting started with Ranorex and mobile test automation—great choice picking up this tool for cross-platform testing.
Is Fetching Login Data From SQL Reasonable?
Absolutely, but it depends on your test scale and data needs. Let's break it down:
- When it makes sense:
- You need multiple sets of test data (e.g., 5+ valid user accounts, various invalid cases like empty fields, wrong passwords, malformed usernames)
- Your test data needs to stay in sync with other systems (e.g., your app's user database)
- You want to centralize and maintain test data across multiple test cases or teams
- When variables are simpler:
- You only have 1-2 sets of static test data (e.g., one valid login, one invalid login)
- You're just prototyping your test workflow and don't want to set up a database connection yet
For your two specific scenarios (VALID-LOGIN-data and INVALID-LOGIN-data), both approaches work—but SQL will scale way better if you ever need to add more test cases later.
How to Retrieve Username/Password From SQL in Ranorex
Here's a step-by-step guide tailored to mobile login tests:
- Add a Database Data Source
- Open your Ranorex Test Suite, right-click on
Data Sources>Add>Database Connection - Fill in your SQL server details (server name, authentication type, database name) and click
Test Connectionto confirm it works
- Open your Ranorex Test Suite, right-click on
- Write Targeted Queries for Your Scenarios
- For valid login data, use a query like:
SELECT username, password FROM login_test_data WHERE test_scenario = 'VALID-LOGIN-data' - For invalid login data, adjust the query to:
SELECT username, password FROM login_test_data WHERE test_scenario = 'INVALID-LOGIN-data'
test_scenariocolumn to your SQL table to easily filter between valid/invalid cases) - For valid login data, use a query like:
- Bind Data to Your Login Actions
- Open your recorded login test case. Select the "Enter Username" action, go to the
Data Bindingtab in the properties panel - Choose your database data source, then map the
usernamecolumn to the input value. Repeat this for the password field
- Open your recorded login test case. Select the "Enter Username" action, go to the
- Loop Through Multiple Data Rows
- If you have multiple valid/invalid entries, right-click your test case >
Properties> UnderData Source, select your SQL data source. Ranorex will automatically run the test for every row in your query results
- If you have multiple valid/invalid entries, right-click your test case >
Database vs. Variables: Which to Use for Your Scenarios?
Let's match each scenario to the best approach:
- VALID-LOGIN-data:
- Use variables if you only need to test one valid account (quick to set up: create
ValidUsernameandValidPasswordtest variables, bind them to your input fields) - Use SQL if you need to test multiple valid accounts (e.g., admin user, regular user, restricted user) or if the valid accounts change frequently
- Use variables if you only need to test one valid account (quick to set up: create
- INVALID-LOGIN-data:
- Variables work for a single invalid case, but SQL is way better here—you can store all invalid edge cases (empty username, wrong password, too-short password, etc.) in one table and run them all in a single test suite execution without modifying your test code
Final Recommendation for Beginners
Start with variables to get your login test up and running quickly—this helps you learn Ranorex's core features without getting bogged down in database setup. Once you're comfortable, migrate to SQL as you add more test cases or need to manage larger sets of test data.
内容的提问来源于stack exchange,提问作者Ghasem Tabatabaei

