- I. Configuration Guide
- II. The Construction and Use of Knowledge Graph
- III. Code Structure Guidelines
- IV. Configure File Details
-
Python Version: 3.6 - 3.7 π
-
Package Installation: π¦
pip install -r requirements.txt
See
requirements.txtfile for the complete list of required packages. -
Picture Processing Environment: πΌοΈ Configure the relevant environment for picture processing according to
/PicAnalysis/README.md. This article makes adjustments to the Usage part, see below for details. -
Neo4j Database: ποΈ Download and configure Neo4j version 3.5.5 (or any 3.x.x version).
Neo4j is a graph database. For different function points, we should set up different graph databases. For example:
- Create a graph database named
loginto store all data related to the login function point - Create a graph database named
airportto store all data related to the subscription ticket
| Num. | Database Name | Description |
|---|---|---|
| 1 | π login | Login functionality |
| 2 | Airport/ticket booking | |
| 3 | π register | Registration functionality |
| 4 | π shopping | Shopping functionality |
| 5 | π§ email | Email functionality |
-
Modify the Neo4j Configuration File:
- Open the
conffile in the Neo4j folder - Edit the database name (default is
graph.db)
- Open the
-
Start Neo4j: π
- Open command line as administrator π¨βπΌ
- Run:
neo4j.bat console(for Windows; Mac users should check the equivalent command) - Open http://localhost:7474/ in your browser to access the knowledge graph interactive interface π
- Test with query:
MATCH (a) RETURN a(equivalent to MySQL'sSELECT *)
Run MobileKG/GenerateKG/main.py to start the knowledge graph generation process:
| Method/Parameter | Explanation |
|---|---|
analyze() | Feature extraction from the original test report |
connect() | Analyze the content of the test report extracted by feature, and extract the relationship of the relevant content |
generate() | Perform coreference resolution on the data extracted from the relationship and add it to the knowledge graph |
| Import RunConfig File | Configuration required at runtime, please refer to this file for specific parameter content |
Step 1οΈβ£: Configure Graph Type
- Modify the
graph_typeinMobileKG/Config/RunConfig.pyto the specified function point, such asloginorairport
Step 2οΈβ£: Prepare Original Data
- Put the original test report into the
MobileKG/Data/Originalfolder - Alternatively, use another folder and modify the
original_data_pathinMobileKG/Config/RunConfig.py
Step 3οΈβ£: Run Feature Extraction
- Run the
analyze()method inMobileKG/GenerateKG/main.py - The system will automatically disassemble the picture and text information of the test report
- Results are saved to the folder pointed to by
analyze_data_path(default:MobileKG/Data/Analyze)
Step 4οΈβ£: Run Relationship Extraction
- Run the
connect()method inMobileKG/GenerateKG/main.py - The system will automatically combine the disassembled data from the previous step
- A new folder with the current timestamp will be created
- Results are saved to the folder pointed to by
connect_data_path(default:MobileKG/Data/Result)
Step 5οΈβ£: Start Neo4j Database
- Configure the database of the specified function point according to Section 2.1
- Open command line as administrator
- Run:
neo4j.bat console
Step 6οΈβ£: Generate Knowledge Graph
- Modify
generate_data_pathinMobileKG/Config/RunConfig.py - Set the value to the path of the folder created with the timestamp in Step 4
- Run the
generate()method inMobileKG/GenerateKG/main.py
Step 7οΈβ£: Verify Generation
- Open http://localhost:7474/
- Enter
MATCH (a) RETURN ain the input box - If the knowledge graph is displayed, the generation is successful β
To load a pre-generated knowledge graph (e.g., login function):
- Set
generate_data_pathinMobileKG/Config/RunConfig.pyto../Data/Result/login/ - Run the
generate()method inMobileKG/GenerateKG/main.py - Open http://localhost:7474/ and enter
MATCH (a) RETURN ato verify β
synonyms package download timeout
The synonyms package needs to download words.vector.gz on first use, which may be very slow.
- β Solution 1: Set the proxy, please refer to the welcome section of https://github.com/chatopera/Synonyms
- β
Solution 2: Manually download the compressed package from https://github.com/chatopera/Synonyms/releases/download/3.15.0/words.vector.gz or use the pre-downloaded version (Baidu Pan link: https://pan.baidu.com/s/1PpHrOYEbW8xQ_25EgP2JQg, extraction code:
37j4). Place it in the folder indicated by the error message.
py2neo package cannot connect to Neo4j
Try the connection method described in: https://blog.csdn.net/sinat_33846443/article/details/109023259
Call the next_step() method in MobileKG/SearchKG/main.py. This method requires three parameters:
Scenario: Analyzing the start page of the login function point of the "Dewu" APP
Step 1οΈβ£: Prepare the Image and Split Data πΌοΈ
import cv2
from MobileKG.LayoutAnalysis.LayoutMain import split
picture = cv2.imread('../Test/pictures/dewu-01.png', 0)
split_dic = split('../Test/pictures/dewu-01.png')Step 2οΈβ£: Define Components π―
page1_components = {
"components": [
{"category": "Button", "x1": 262, "y1": 1761, "x2": 566, "y2": 1781, "ocr": 'εΎη©'},
{"category": "Button", "x1": 262, "y1": 1761, "x2": 566, "y2": 1781, "ocr": 'θ΄δΉ°'},
{"category": "Button", "x1": 262, "y1": 1761, "x2": 566, "y2": 1781, "ocr": 'ζε‘'},
{"category": "Button", "x1": 262, "y1": 1761, "x2": 566, "y2": 1781, "ocr": 'ζ'},
]
}Step 3οΈβ£: Set Parameters βοΈ
last_component_id: Set to0for the first screenshot (no predecessor node)search_all: Recommended to use the default value for faster search
Step 4οΈβ£: Execute Query π
result = next_step(picture, split_dic, page1_components, 0)
print(result)Step 5οΈβ£: Process Return Value π
The method returns an array containing all components that need to be operated on the page:
{
'status': 'success',
'data': [
{
'category': 'Button',
'ocr': 'ζ',
'operation': 'click',
'cnt': 'ζ',
'cnt_id': 12,
'x1': 262,
'y1': 1761,
'x2': 566,
'y2': 1781
}
]
}Complete Code Example π»
import cv2
from MobileKG.LayoutAnalysis.LayoutMain import split
from MobileKG.SearchKG.main import next_step
# Load image and perform layout analysis
picture = cv2.imread('../Test/pictures/dewu-01.png', 0)
split_dic = split('../Test/pictures/dewu-01.png')
# Define page components
page1_components = {
"components": [
{"category": "Button", "x1": 262, "y1": 1761, "x2": 566, "y2": 1781, "ocr": 'εΎη©'},
{"category": "Button", "x1": 262, "y1": 1761, "x2": 566, "y2": 1781, "ocr": 'θ΄δΉ°'},
{"category": "Button", "x1": 262, "y1": 1761, "x2": 566, "y2": 1781, "ocr": 'ζε‘'},
{"category": "Button", "x1": 262, "y1": 1761, "x2": 566, "y2": 1781, "ocr": 'ζ'},
]
}
# Query knowledge graph for next step
result = next_step(picture, split_dic, page1_components, 0)
print(result)MobileKG: Django backend π§kgfront: Vue frontend π₯οΈ
π Note: Due to time constraints, the front and back ends are not connected. The temporary front-end display strategy generates fake JSON data from the MobileKG/Test/FormFrontEnd file in the back-end.
This folder stores special configuration information for the knowledge graph.
| File | Description |
|---|---|
RunConfig.py |
Runtime parameter configuration (intermediate result paths, similarity thresholds, etc.) |
OperationConfig.csv |
Pre-defined operation types (click, input, etc.) |
WidgetConfig.csv |
Pre-defined widget types (button, text box, etc.) |
SimilarTXTConfig.json |
Configures which texts the knowledge graph considers similar (domain-specific thesaurus) |
TypicalLayoutConfig.json |
Configures similar layouts for finding operable controls during query |
SearchPolicy.json |
Configures two query modes available during knowledge graph querying |
π Note: OperationConfig.csv and WidgetConfig.csv store constant entities that can be directly loaded without analysis when generating a knowledge graph from scratch.
| Folder | Description |
|---|---|
Original |
Stores original data for building the knowledge graph (application level, not function point level) |
Analyze |
Stores intermediate data results after feature extraction from Original folder |
Result |
Stores data that has completed feature extraction and relation extraction, ready for generate() method |
| File/Folder | Description |
|---|---|
test.py |
Realizes the whole process of querying the map through a screenshot |
screenshot/ |
Used to store query results |
screenshot/origin/ |
Stores original images to be queried |
screenshot/widget_res/ |
Stores results after widget extraction |
screenshot/KG_res/ |
Draws the result controls from knowledge graph query |
π‘ Usage: Add the path to be queried to the parameters of the searchKG() method in FuncTest/test.py.
This folder handles knowledge graph generation.
| File/Folder | Description |
|---|---|
GenerateMain.py |
Startup entry file for building knowledge graphs |
Operation/ |
All operations in the generation process (feature extraction, relationship extraction, coreference resolution) |
PO/ |
Data classes needed to generate the knowledge graph |
This folder performs layout analysis operations on pictures.
π‘ Usage:
- Not used during construction, but during the query process
- Divides input screenshots into regions by horizontal dimension
- Performs SIFT similarity matching between divided regions and layout pictures in Config
- If threshold is exceeded, matching is successful and the control is locked
π Main File: LayoutMain.py
This folder contains operations for the Neo4j graph database.
| File | Description |
|---|---|
GraphAdd.py |
Creates a new database in Neo4j |
GraphSearch.py |
Searches for data in Neo4j database |
This folder is responsible for the recognition and extraction of text and controls from pictures.
Stores images used in README.md documentation.
This folder contains the general entry for querying the knowledge graph.
π‘ Usage:
- Call the
next_step()method inSearchMain.py - For specific usage and precautions, please refer to Section 2.3 and the notes in the document
This folder stores intermediate results when debugging the knowledge graph and provides interfaces for quick debugging.
| File | Description |
|---|---|
DrawLine.py |
Quickly draw control recognition results, layout analysis results, and map query results |
FormFrontEnd.py |
Quickly generate the JSON file that the front-end demo needs (requires data in Data folder) |
This folder contains tools for text analysis.
β¨ Features:
- Interface for
jiebaword segmentation - Segment the recurrence steps and analyze parts of speech
- Identify gerunds, etc.
π Note: LanguageChange.py has not been implemented. Currently only supports Chinese. π¨π³
Stores a pre-trained CNN model that identifies whether a widget in a picture is a button or a text box.
π― Purpose: Specifies synonyms under a knowledge domain.
This file helps the system understand that certain terms are equivalent in the context of mobile application testing.
π― Purpose: Locates specified controls through layout configuration.
For pictures where the text is not sufficient to help with positioning, this configuration provides a layout-based method to locate the specified control.
π― Purpose: Defines query strategies.
The system provides two query methods:
- Text-based similarity query π
- Layout-based identification query πΌοΈ
Both query methods are guaranteed to execute, with layout queries preceding text queries.
Configuration Options:
both: Execute both layout and text queries. βlayout: If layout query finds the control, skip text query. β‘
Use the type attribute to specify the desired behavior.
Please refer to the project license file for usage terms and conditions.
For questions or issues, please refer to the project repository or contact the development team.

