Robot Framework同一关键字在不同测试套件中一通过一报错的问题排查
Let's break down why you're seeing this inconsistent behavior across your two test suites, even though both import Selenium2Library. Here are the most likely causes and fixes:
1. Missing Import for the Custom Keyword
The first suite works because it either:
- Defines
confirm page loadedin its own*** Keywords ***section, or - Imports a shared resource file (or custom library) that contains this keyword.
Your second suite is failing because it doesn't have this import. Check the top of your second test file—you need to add a Resource or Library statement pointing to where confirm page loaded is defined. For example:
*** Settings *** Library Selenium2Library Resource ../path/to/your/shared_keywords.resource # Update this path to match your project structure
2. Relative Path Mismatch
If your two test suites are in different subdirectories, the relative path to a shared resource file might not work for both. For example:
- Suite 1 in
tests/suite1/test.robotuses../shared/keywords.resource(correct) - Suite 2 in
tests/suite2/test.robotneeds../shared/keywords.resourcetoo (not../../shared/...unless your directory structure differs)
To avoid this, use a project-root relative path with Robot's built-in variables:
Resource ${CURDIR}/../../shared/keywords.resource
3. Typos or Syntax Errors in Imports
Double-check the second suite's *** Settings *** section for:
- Misspelled resource/library filenames
- Missing
ResourceorLibrarykeywords before the path - Extra spaces or typos in the import line
Even a tiny typo (like resouce instead of Resource) will prevent the keyword from being loaded.
4. Isolate the Second Suite to Test
Run the second suite alone (not in batch) to rule out batch-run environment issues:
robot tests/suite2/your_test_file.robot
If it fails alone, the problem is in the suite's configuration. If it passes, your batch command might be running from the wrong working directory, breaking relative path imports.
5. Check for Keyword Name Conflicts
While unlikely here, ensure the second suite doesn't have a test case or variable with the exact same name as confirm page loaded—Robot Framework might prioritize that over the imported keyword.
内容的提问来源于stack exchange,提问作者Nazia Hasan

