CN110781091A - Application program testing method and device, electronic equipment and storage medium - Google Patents

Application program testing method and device, electronic equipment and storage medium Download PDF

Info

Publication number
CN110781091A
CN110781091A CN201911054050.7A CN201911054050A CN110781091A CN 110781091 A CN110781091 A CN 110781091A CN 201911054050 A CN201911054050 A CN 201911054050A CN 110781091 A CN110781091 A CN 110781091A
Authority
CN
China
Prior art keywords
page
tested
information
hash table
controlled
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
CN201911054050.7A
Other languages
Chinese (zh)
Other versions
CN110781091B (en
Inventor
金凌云
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing QIYI Century Science and Technology Co Ltd
Original Assignee
Beijing QIYI Century Science and Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing QIYI Century Science and Technology Co Ltd filed Critical Beijing QIYI Century Science and Technology Co Ltd
Priority to CN201911054050.7A priority Critical patent/CN110781091B/en
Publication of CN110781091A publication Critical patent/CN110781091A/en
Application granted granted Critical
Publication of CN110781091B publication Critical patent/CN110781091B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3668Software testing
    • G06F11/3672Test management
    • G06F11/3688Test management for test execution, e.g. scheduling of test suites
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/90Details of database functions independent of the retrieved data types
    • G06F16/901Indexing; Data structures therefor; Storage structures
    • G06F16/9014Indexing; Data structures therefor; Storage structures hash tables
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/90Details of database functions independent of the retrieved data types
    • G06F16/901Indexing; Data structures therefor; Storage structures
    • G06F16/9027Trees

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Databases & Information Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Software Systems (AREA)
  • Data Mining & Analysis (AREA)
  • Computer Hardware Design (AREA)
  • Quality & Reliability (AREA)
  • Debugging And Monitoring (AREA)

Abstract

The embodiment of the invention provides a method and a device for testing an application program, electronic equipment and a storage medium. The method comprises the following steps: determining a page to be tested of the application program to be tested; obtaining an element hash table of a page to be detected; the element hash table stores elements in an element tree of the page to be detected, and a key code required for accessing the elements stored in the element hash table is constructed based on element information; obtaining a test script corresponding to a page to be tested; an operation instruction for operating and controlling the element to be operated and controlled in the page to be tested is recorded in the test script; executing the test script to test the page to be tested; when the test is executed, the element to be controlled is positioned based on the element hash table and the key code corresponding to the element to be controlled indicated by the control instruction; after the positioning, executing a control action of controlling the element to be controlled, which is indicated by the control instruction; the embodiment of the invention can improve the testing efficiency of the application program.

Description

Application program testing method and device, electronic equipment and storage medium
Technical Field
The present invention relates to the field of application test technologies, and in particular, to a method and an apparatus for testing an application, an electronic device, and a storage medium.
Background
In the technical field of application program testing, in order to save labor and improve testing efficiency, automated testing is generally adopted to simulate human operation and control actions on elements on a page to be tested of an application program.
The existing test method of the application program comprises the following steps: determining a page to be tested of the application program to be tested; obtaining and executing a test script corresponding to the page to be tested; in the test script, an instruction for positioning an element to be controlled and a control instruction for controlling the element after positioning are recorded. When an instruction for positioning the element to be controlled, which is recorded by the test script, is executed, positioning the element with the element identifier according to the element identifier; for an element without an element identifier, the element is located according to the absolute path Xpath of the element. Here, Xpath is a path from the root element of the page to be tested to the element to be manipulated.
However, the inventor finds that the prior art has at least the following problems in the process of implementing the invention:
because a large number of elements without element identifiers exist in the page to be tested, element positioning is carried out according to the XPath, element traversal needs to be carried out from the root element until the element to be controlled is traversed, so that the consumed time is undoubtedly longer, and the test efficiency of the existing test method of the application program is lower.
Disclosure of Invention
The embodiment of the invention aims to provide a method and a device for testing an application program, an electronic device and a storage medium, so as to improve the testing efficiency of the application program. The specific technical scheme is as follows:
in a first aspect, an embodiment of the present invention provides a method for testing an application program, where the method includes:
determining a page to be tested of the application program to be tested;
obtaining an element hash table of the page to be detected; the element hash table stores elements in an element tree of the page to be tested, and a key code required for accessing the elements stored in the element hash table is constructed based on element information of the elements;
obtaining a test script corresponding to the page to be tested; an operation instruction for operating and controlling the element to be operated and controlled in the page to be tested is recorded in the test script;
executing the test script to test the page to be tested; when the page to be controlled is tested during the execution of the test script, the element to be controlled is positioned based on the element hash table and a key code corresponding to the element to be controlled and indicated by the control instruction; and after the positioning, executing the control action which is indicated by the control instruction and is used for controlling the element to be controlled.
Optionally, the method for constructing a key required to access the element stored in the element hash table based on the element information of the element includes:
determining whether the element information of the element comprises an element identifier;
and if the element information of the element comprises the element identifier of the element, determining that the element identifier of the element is the key code corresponding to the element, otherwise, constructing the key code uniquely corresponding to the element based on at least two kinds of element information in the element information of the element.
Optionally, the step of constructing a key uniquely corresponding to the element based on at least two kinds of element information of the element includes:
acquiring the element type of the element and the image-text information in the element from the element information of the element; the image-text information is text information in the element or identification information of the picture in the element.
And generating a key code uniquely corresponding to the element by using a preset key code generation algorithm according to the acquired element type and the image-text information.
Optionally, the key generation algorithm is an algorithm for character splicing of characters representing the element types, characters representing the image-text information, and characters representing additional information;
wherein the additional information is: and the numbers are used for distinguishing elements with the same element types and the same image-text information.
Optionally, the obtaining the element hash table of the page to be tested includes:
judging whether an element hash table of the page to be detected exists or not;
if the page to be detected exists, obtaining an existing element hash table of the page to be detected;
if the element tree does not exist, determining each element which can be controlled by a user in the element tree of the page to be tested; and constructing an element hash table of the page to be tested based on each element which can be controlled by the user.
In a second aspect, an embodiment of the present invention provides an apparatus for testing an application, including:
the determining module is used for determining a page to be tested of the application program to be tested;
the first obtaining module is used for obtaining an element hash table of the page to be detected; the element hash table stores elements in an element tree of the page to be tested, and a key code required for accessing the elements stored in the element hash table is constructed based on element information of the elements;
the second obtaining module is used for obtaining a test script corresponding to the page to be tested; an operation instruction for operating and controlling the element to be operated and controlled in the page to be tested is recorded in the test script;
the script execution module is used for executing the test script to test the page to be tested; when the page to be controlled is tested during the execution of the test script, the element to be controlled is positioned based on the element hash table and a key code corresponding to the element to be controlled and indicated by the control instruction; and after the positioning, executing the control action which is indicated by the control instruction and is used for controlling the element to be controlled.
Optionally, the method for constructing a key required to access the element stored in the element hash table based on the element information of the element includes:
determining whether the element information of the element comprises an element identifier;
and if the element information of the element comprises the element identifier of the element, determining that the element identifier of the element is the key code corresponding to the element, otherwise, constructing the key code uniquely corresponding to the element based on at least two kinds of element information in the element information of the element.
Optionally, constructing a key uniquely corresponding to the element based on at least two kinds of element information in the element information of the element includes:
acquiring the element type of the element and the image-text information in the element from the element information of the element; the image-text information is text information in the element or identification information of a picture in the element;
and generating a key code uniquely corresponding to the element by using a preset key code generation algorithm according to the acquired element type and the image-text information.
Optionally, the key generation algorithm is an algorithm for character splicing of characters representing the element types, characters representing the image-text information, and characters representing additional information;
wherein the additional information is: and the numbers are used for distinguishing elements with the same element types and the same image-text information.
Optionally, the first obtaining module is specifically configured to:
judging whether an element hash table of the page to be detected exists or not;
if the page to be detected exists, obtaining an existing element hash table of the page to be detected;
if the element tree does not exist, determining each element which can be controlled by a user in the element tree of the page to be tested; and constructing an element hash table of the page to be tested based on each element which can be controlled by the user.
In a third aspect, an embodiment of the present invention provides an electronic device, including a processor, a communication interface, a memory, and a communication bus, where the processor and the communication interface complete communication between the memory and the processor through the communication bus;
a memory for storing a computer program; and the processor is used for realizing the testing method of any application program when executing the program stored in the memory.
In yet another aspect of the present invention, there is also provided a computer-readable storage medium having stored therein instructions, which when run on a computer, cause the computer to execute the method for testing an application program as described in any one of the above.
In another aspect of the present invention, the present invention also provides a computer program product containing instructions, which when run on a computer, causes the computer to execute any of the above-mentioned methods for testing an application program.
In the method for testing an application program provided in the embodiment of the present invention, the page to be tested has the element hash table, the element hash table stores elements in the element tree of the page to be tested, and the key code required for accessing the elements stored in the element hash table is constructed based on the element information of the elements. When the test script is executed to test the page to be tested, the element to be controlled is positioned based on the key code corresponding to the element to be controlled and recorded by the test script and the element hash table. Therefore, for the elements without element identification, element traversal is not needed from the root element until the element to be tested is traversed, and the time consumed by element positioning during application program testing is shortened. Of course, it is not necessary for any product or method of practicing the invention to achieve all of the above-described advantages at the same time.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below.
Fig. 1 is a flowchart of a method for testing an application according to an embodiment of the present invention;
FIG. 2 is a flowchart illustrating a process of constructing an element hash table of a page to be tested based on an element tree of the page to be tested in the method shown in FIG. 1;
fig. 3 is a schematic structural diagram of an apparatus for testing an application according to an embodiment of the present invention;
fig. 4 is a schematic structural diagram of an electronic device according to an embodiment of the present invention.
Detailed Description
The technical solutions in the embodiments of the present invention will be described below with reference to the drawings in the embodiments of the present invention.
In order to improve the testing efficiency of the application program, embodiments of the present invention provide a method and an apparatus for testing an application program, an electronic device, and a storage medium.
It should be noted that the method for testing the application program provided by the embodiment of the present invention may be applied to an electronic device. In a specific application, the electronic device may be a computer or any other electronic device capable of performing application testing. It can be understood that the main body of the test method for implementing the application program is application program test software in the electronic device, and the application program test software is associated with a test script of a page to be tested of the application program to be tested. When the application program test software runs the instruction in the test script, the test of the page to be tested of the application program to be tested can be realized. In practical applications, the application Test software may be, for example, Appium, QTP (Quick Test professional), robotframe, Selenium, or the like.
First, a method for testing an application provided in an embodiment of the present invention is described in detail. As shown in fig. 1, the method may include the steps of:
s101: and determining a page to be tested of the application program to be tested.
In this step, a page to be tested of the application to be tested is determined, that is, the application test software calls the page to be tested. Here, the page to be tested of the application to be tested may be an HTML (Hypertext Markup Language) page. The HTML page contains many elements such as buttons, progress bars, pictures, tags, and text boxes on the page to be tested.
It can be understood that the application under test may have a plurality of pages to be tested, and for clarity of the solution, the embodiment of the present invention describes a test process of one page to be tested of the application under test, and the test process of other pages to be tested may refer to this process.
S102: obtaining an element hash table of a page to be detected; the element hash table stores elements in an element tree of the page to be tested, and a key code required for accessing the elements stored in the element hash table is constructed based on element information of the elements.
It will be appreciated that a hash table is a data structure that directly accesses data based on a key. Specifically, according to the key code, a hash algorithm is utilized to calculate a hash address mapped by the key code; the data stored at the hash address is then accessed. Therefore, in the embodiment of the present invention, the element hash table of the page to be tested has an effect of directly accessing the elements in the element tree of the page to be tested according to the key codes corresponding to the elements.
In this step, the element hash table of the page to be tested may be obtained from the cache of the application test software or the disk of the electronic device where the application test software is located, that is, the element hash table of the page to be tested is pre-constructed. If the element hash table of the page to be tested is not obtained in the cache or the disk, the element hash table of the page to be tested can be currently constructed when the test method of the application program is executed. Whenever the element hash table of the page to be detected is constructed, in the specific construction, a key code of an element can be constructed firstly based on element information of the element, wherein the key code is a key code required for accessing the element stored in the subsequently constructed element hash table; and then, calculating the hash address mapped by the key corresponding to the element by using a preset hash algorithm, and storing the element in the position indicated by the calculated hash address. Thus, the element hash table of the page to be detected is constructed. There are various preset hash algorithms, such as MD2, MD4, MD5, SHA, etc., but not limited thereto; the MD2, MD4 and MD5 are different versions of message digest algorithm, SHA is secure hash algorithm, and the secure hash algorithm also has multiple versions, such as SHA-1, SHA-2 or SHA-3.
When the element hash table of the page to be detected is constructed, various ways exist for constructing the key code required for accessing the elements stored in the element hash table based on the element information of the elements. For example, in one implementation, the manner of constructing the key required to access the element stored in the element hash table based on the element information of the element may include:
determining whether element information of the element comprises an element identifier;
and if the element information of the element comprises the element identifier of the element, determining that the element identifier of the element is the key code corresponding to the element, otherwise, constructing the key code uniquely corresponding to the element based on at least two kinds of element information in the element information of the element.
Here, for an element having an element identification, the element information may include: element identification, element size, graphic and text information in the element, element type and the like; for elements without element identifiers, the element information may include the size of the element, the teletext information in the element, the type of the element, and so on. The image-text information in the element is text information in the element or identification information of a picture in the element. For example, if the element is a tag type element and the text information in the tag is "login", the text information in the element is "login"; for another example, if the element is an element of a button type and the identification information of the picture contained in the button is "pic.
It is to be understood that an element identification is a unique identification of an element, that is, the element identification of different elements is different for each element having an element identification. Therefore, the element identifier is determined as the key code corresponding to the element, and is not confused with the key codes corresponding to other elements. Similarly, for an element without an element identifier, when a key uniquely corresponding to the element is constructed based on at least two kinds of information in element information of the element, the constructed key should be different for different elements. Therefore, the one-to-one correspondence relationship between the key and the element can be ensured, and confusion is avoided. For clarity of the scheme and clarity of layout, the specific construction manner of the key of the element without the element identifier is illustrated in the following.
S103: and obtaining a test script corresponding to the page to be tested.
It can be understood that after writing the test script of the page to be tested, the tester can associate the test script with the page to be tested in the application test software. Therefore, when the application program test software calls the page to be tested, the test script related to the page to be tested can be obtained.
And recording an operation instruction for operating and controlling the element to be operated and controlled in the page to be tested in the test script. And in the control instruction, a key code corresponding to the element to be controlled and a control action for controlling the element to be controlled are indicated.
It is understood that the application program is tested, that is, a test script is used to simulate the operation performed by the user on some elements on the page to be tested of the application program under test, such as clicking on an element, sliding an element, and entering text in an element. Therefore, the implementation object of the operation to be simulated is the element to be manipulated in the page to be tested. In practical application, the control instruction recorded in the test script is usually a function, and in the field of software, the function may also be called a method; different methods can correspond to different control actions, and the key codes corresponding to the elements to be controlled are input parameters of the method. Since what kind of manipulation is performed on the element to be manipulated and how to implement the manipulation is not the point of the invention, and is the same as or similar to the prior art, the detailed description is omitted here.
S104: executing the test script to test the page to be tested; when the test script is executed to test the page to be tested, the element to be controlled is positioned based on the element hash table and the key code corresponding to the element to be controlled and indicated by the control instruction; and after the positioning, executing the control action of controlling the element to be controlled, which is indicated by the control instruction.
Here, the test script is executed to test the page to be tested, that is, the application test software executes each control instruction recorded in the test script. Of course, other instructions recorded in the test script may also be executed by the application test software.
When each control instruction is executed, based on the element hash table and the key corresponding to the element to be controlled indicated by the control instruction, the positioning of the element to be controlled may specifically include:
inputting a key code corresponding to an element to be controlled in the control instruction into a hash algorithm corresponding to an element hash table, and calculating a hash address mapped by the key code; from the element hash table obtained in step S102, the element to be manipulated is located at the position indicated by the hash address. It can be understood that, when the hash address mapped by the key is obtained through calculation, the element stored in the hash address in the element hash table can be accessed, that is, the element to be controlled is to be positioned. The hash algorithm corresponding to the element hash table is a hash algorithm used when the element hash table is constructed.
Compared with the prior art, in the embodiment of the invention, the element is positioned by accessing the element stored in the element hash table, so that the speed of positioning the element can be increased.
In the method for testing an application program provided in the embodiment of the present invention, the page to be tested has the element hash table, the element hash table stores elements in the element tree of the page to be tested, and the key code required for accessing the elements stored in the element hash table is constructed based on the element information of the elements. When the test script is executed to test the page to be tested, the element to be controlled is positioned based on the key code corresponding to the element to be controlled and recorded by the test script and the element hash table. Therefore, for the elements without element identification, element traversal is not needed from the root element until the element to be tested is traversed, and the time consumed by element positioning during application program testing is shortened.
For clarity of the scheme and clarity of layout, the following illustrates how to construct the key corresponding to the element without the element identifier.
For example, in an implementation manner, for each element without an element identifier, the step of constructing a key uniquely corresponding to the element based on at least two element information of the element may include:
acquiring the element type of the element and the image-text information in the element from the element information of the element;
and generating a key code uniquely corresponding to the element by using a preset key code generation algorithm according to the acquired element type and the image-text information.
The key generation algorithm may be: and performing character splicing on the characters representing the element types and the characters representing the image-text information. That is, the key constructed in this implementation is specifically a character string.
For example, assume that the key generation algorithm is:
Key=Type[Info=’text’]
wherein, Key represents a Key code, Type represents an element Type, and text represents image-text information; assuming that a Button type element C is provided, the image-text information is an identifier "pic.png" of a picture, and at this time, the key code corresponding to the element C generated by using the key code generation algorithm may be: button [ info ═ pic.
When there is an element in the element tree whose element type and the graphic and text information of the element are the same, in order to construct a key corresponding to the element one to one, the key generating algorithm may be: and performing character splicing on the characters representing the element types, the characters representing the image and text information and the characters representing the additional information. Here, the additional information is: the number for distinguishing the element having the same element type and the same teletext information, for example, the additional information may be the number of repetitions of the element having the same element type and the same teletext information.
For example, assume that the key generation algorithm is:
Key=Type[Info=’text’][index];
wherein, Key represents a Key code, Type represents an element Type, text represents image-text information, and index represents additional information; suppose there is a label type element A, and the text information in the label is "logic"; another label type element B, and the literal information in the label is "logic"; there is also a Button type element C, and the image-text information is a picture mark "pic.png"; the type is label, and the element whose text information in the label is "login" appears twice in the element tree, then, by using the key generation algorithm, the key corresponding to the first appearing element a is label [ info ═ login ] [0 ]; the key corresponding to the second occurrence of element B is label [ info ═ logic ] [1 ]. Since the type is Button and the element with "pic.png" of the picture attached to the Button appears for the first time on the element tree, the key code corresponding to element C is Button [ info ═ pic.png "] [0] by using the key code generation algorithm.
It should be noted that, for an element without an element identifier, at least two kinds of keys may be optionally selected from the element information to construct the key of the element on the premise of ensuring that the constructed key corresponds to the element one to one, and the two kinds of keys are not limited to the element type and the teletext information shown above.
In addition, in step S102, when the element hash table is obtained from a cache or a disk, the pre-constructed element hash table may be constructed based on an element tree of the page to be tested. Specifically, an element hash table of the page to be detected can be constructed based on all elements in the element tree of the page to be detected; or, the element hash table of the page to be tested may be constructed based on each element that can be controlled by the user in the element tree of the page to be tested. Here, whether an element is user-manipulable or not may be recognized by an element type, may be specified by a tester when constructing an element hash table, or the like, which is reasonable. Wherein the user can manipulate the element types such as button, input box, clickable picture, clickable link, slidable progress bar, etc.
Similarly, in step S102, if the pre-constructed element hash table of the page to be detected does not exist in the cache or the disk, and the element hash table of the page to be detected needs to be constructed at present, the element hash table of the page to be detected may be constructed based on all elements in the element tree of the page to be detected; or, based on each element which can be controlled by the user, an element hash table of the page to be tested is constructed. Here, whether an element is user-manipulable or not can be identified by the element type.
For the sake of clarity, the following describes a specific process of constructing an element hash table of a page to be tested based on an element tree of the page to be tested. As shown in fig. 2, the process may include:
s21: determining each element which can be controlled by a user in an element tree of a page to be detected;
s22: for each determined element, if the element information of the element comprises the element identifier of the element, determining that the element identifier of the element is a key code corresponding to the element, otherwise, acquiring the element type of the element and the image-text information in the element from the element information of the element; generating a key code uniquely corresponding to the element by using a preset key code generation algorithm according to the acquired element type and the image-text information;
s23: and aiming at each determined element, calculating a hash address mapped by the key corresponding to the element by using a preset hash algorithm, and storing the element into a position indicated by the calculated hash address to obtain an element hash table of the page to be detected.
In step S21, how to determine the specific implementation manner of each element that can be controlled by the user in the element tree of the page to be tested, and in step S22, the specific implementation manner of the key uniquely corresponding to the element is generated by using a preset key generation algorithm according to the acquired element type and the image-text information.
In addition, after the element hash table of the page to be tested is constructed, the element hash table may be archived and stored in the cache and/or the disk. Therefore, when the test script is used again to test the page to be tested, the element hash table of the page to be tested can be directly obtained from the cache and/or the disk.
Optionally, in an implementation manner, if the element hash table of the page to be detected that is pre-constructed does not exist in the cache or the disk, when the element hash table of the page to be detected needs to be constructed at present, if the element tree of the page to be detected does not exist in the cache or the disk, the element tree of the page to be detected may also be constructed first, and then the element hash table of the page to be detected may be constructed based on the element tree of the page to be detected. Specifically, a class of an element type is defined, and several kinds of key information are selected from element information of elements in a page to be tested as attributes of the class, so that each element of the page to be tested can generate an element under the class; then, traversing the elements of the page to be detected from the root element of the page to be detected; during traversal, elements under class generated by each element of the page to be detected are used as nodes of the tree data structure, and the tree data structure is constructed according to the parent-child connection relation among the elements in the page to be detected and used as an element tree of the page to be detected.
There are many kinds of key information that can be selected when defining class. Illustratively, an element identification, a type of the element, coordinates of the element, a size of the element, a parent element pointer of the element, and an array of child elements of the element, among others, may be selected. Besides the information, the key corresponding to the element can be constructed in advance at the stage of constructing the element tree, and the key of the element can be used as an attribute of the defined class. Therefore, when the element hash table is constructed based on the element tree subsequently, the key corresponding to the element can be directly obtained from the node of the element tree.
It can be understood that the implementation manner for constructing the element tree of the page to be tested in advance before the test method of the application program is not started may be the same as or similar to the implementation manner for constructing the element tree of the page to be tested shown here, and therefore, the implementation manner for constructing the element tree of the page to be tested in advance before the test method of the application program is not started is not described in detail. In practical applications, the tree data structure may be a binary tree or a multi-branch tree.
In addition, after the element tree of the page to be tested is constructed, the element tree of the page to be tested can be filed. For example, the element tree of the page to be tested is archived in an XML (eXtensible Markup Language) format or a JSON (Java Script Object notification) format, and stored in the cache and/or the disk. During storage, in order to facilitate indexing, the archive file in the XML format or the JSON format can be named according to the name of the page to be detected and the storage time. When the element tree of the page to be tested needs to be obtained, the archive file can be called from the cache or the disk, and the archive file is converted into the available element tree of the page to be tested.
Corresponding to the above method for testing an application program, an embodiment of the present invention further provides an apparatus for testing an application program, as shown in fig. 3, the apparatus may include:
a determining module 301, configured to determine a page to be tested of a tested application program;
a first obtaining module 302, configured to obtain an element hash table of the page to be tested; the element hash table stores elements in an element tree of the page to be tested, and a key code required for accessing the elements stored in the element hash table is constructed based on element information of the elements;
a second obtaining module 303, configured to obtain a test script corresponding to the page to be tested; an operation instruction for operating and controlling the element to be operated and controlled in the page to be tested is recorded in the test script;
the script execution module 304 is configured to execute the test script to test the page to be tested; when the page to be controlled is tested during the execution of the test script, the element to be controlled is positioned based on the element hash table and a key code corresponding to the element to be controlled and indicated by the control instruction; and after the positioning, executing the control action which is indicated by the control instruction and is used for controlling the element to be controlled.
Optionally, the method for constructing a key required to access the element stored in the element hash table based on the element information of the element includes:
determining whether the element information of the element comprises an element identifier;
and if the element information of the element comprises the element identifier of the element, determining that the element identifier of the element is the key code corresponding to the element, otherwise, constructing the key code uniquely corresponding to the element based on at least two kinds of element information in the element information of the element.
Optionally, constructing a key uniquely corresponding to the element based on at least two kinds of element information in the element information of the element includes:
acquiring the element type of the element and the image-text information in the element from the element information of the element; the image-text information is text information in the element or identification information of a picture in the element;
and generating a key code uniquely corresponding to the element by using a preset key code generation algorithm according to the acquired element type and the image-text information.
Optionally, the key generation algorithm is an algorithm for character splicing of characters representing the element types, characters representing the image-text information, and characters representing additional information;
wherein the additional information is: and the numbers are used for distinguishing elements with the same element types and the same image-text information.
Optionally, the first obtaining module 302 is specifically configured to:
judging whether an element hash table of the page to be detected exists or not;
if the page to be detected exists, obtaining an existing element hash table of the page to be detected;
if the element tree does not exist, determining each element which can be controlled by a user in the element tree of the page to be tested; and constructing an element hash table of the page to be tested based on each element which can be controlled by the user.
In the device for testing an application program provided in the embodiment of the present invention, the page to be tested has the element hash table, the element hash table stores elements in the element tree of the page to be tested, and the key code required for accessing the elements stored in the element hash table is constructed based on the element information of the elements. When the test script is executed to test the page to be tested, the element to be controlled is positioned based on the key code corresponding to the element to be controlled and recorded by the test script and the element hash table. Therefore, for the elements without element identification, element traversal is not needed from the root element until the element to be tested is traversed, and the time consumed by element positioning during application program testing is shortened.
An embodiment of the present invention further provides an electronic device, as shown in fig. 4, including a processor 401, a communication interface 402, a memory 403, and a communication bus 404, where the processor 401, the communication interface 402, and the memory 403 complete mutual communication through the communication bus 404,
a memory 403 for storing a computer program;
the processor 401, when executing the program stored in the memory 403, implements the following steps:
determining a page to be tested of the application program to be tested;
obtaining an element hash table of the page to be detected; the element hash table stores elements in an element tree of the page to be tested, and a key code required for accessing the elements stored in the element hash table is constructed based on element information of the elements;
obtaining a test script corresponding to the page to be tested; an operation instruction for operating and controlling the element to be operated and controlled in the page to be tested is recorded in the test script;
executing the test script to test the page to be tested; when the page to be controlled is tested during the execution of the test script, the element to be controlled is positioned based on the element hash table and a key code corresponding to the element to be controlled and indicated by the control instruction; and after the positioning, executing the control action which is indicated by the control instruction and is used for controlling the element to be controlled.
Optionally, the method for constructing a key required to access the element stored in the element hash table based on the element information of the element includes:
determining whether the element information of the element comprises an element identifier;
and if the element information of the element comprises the element identifier of the element, determining that the element identifier of the element is the key code corresponding to the element, otherwise, constructing the key code uniquely corresponding to the element based on at least two kinds of element information in the element information of the element.
Optionally, the step of constructing a key uniquely corresponding to the element based on at least two kinds of element information of the element includes:
acquiring the element type of the element and the image-text information in the element from the element information of the element; the image-text information is text information in the element or identification information of a picture in the element;
and generating a key code uniquely corresponding to the element by using a preset key code generation algorithm according to the acquired element type and the image-text information.
Optionally, the key generation algorithm is an algorithm for character splicing of characters representing the element types, characters representing the image-text information, and characters representing additional information;
wherein the additional information is: and the numbers are used for distinguishing elements with the same element types and the same image-text information.
Optionally, the obtaining the element hash table of the page to be tested includes:
judging whether an element hash table of the page to be detected exists or not;
if the page to be detected exists, obtaining an existing element hash table of the page to be detected;
if the element tree does not exist, determining each element which can be controlled by a user in the element tree of the page to be tested; and constructing an element hash table of the page to be tested based on each element which can be controlled by the user.
In the electronic device provided in the embodiment of the present invention, the page to be tested of the application to be tested has the element hash table, the element hash table stores elements in the element tree of the page to be tested, and the key code required for accessing the elements stored in the element hash table is constructed based on the element information of the elements. When the test script is executed to test the page to be tested, the element to be controlled is positioned based on the key code corresponding to the element to be controlled and recorded by the test script and the element hash table. Therefore, for the element without the element identifier, element traversal is not required from the root element until the element to be tested is traversed, and time consumed by element positioning during application program testing is shortened.
The communication bus mentioned in the electronic device may be a Peripheral Component Interconnect (PCI) bus, an Extended Industry Standard Architecture (EISA) bus, or the like. The communication bus may be divided into an address bus, a data bus, a control bus, etc. For ease of illustration, only one thick line is shown, but this does not mean that there is only one bus or one type of bus.
The communication interface is used for communication between the electronic equipment and other equipment.
The Memory may include a Random Access Memory (RAM) or a non-volatile Memory (non-volatile Memory), such as at least one disk Memory. Optionally, the memory may also be at least one memory device located remotely from the processor.
The Processor may be a general-purpose Processor, and includes a Central Processing Unit (CPU), a Network Processor (NP), and the like; the device can also be a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), a Field Programmable Gate Array (FPGA) or other Programmable logic device, a discrete Gate or transistor logic device, or a discrete hardware component.
In another embodiment of the present invention, a computer-readable storage medium is further provided, which stores instructions that, when executed on a computer, cause the computer to execute the method for testing an application program described in any one of the above embodiments.
In a further embodiment of the present invention, there is also provided a computer program product containing instructions which, when run on a computer, cause the computer to perform the method for testing an application program as described in any of the above embodiments.
In the above embodiments, the implementation may be wholly or partially realized by software, hardware, firmware, or any combination thereof. When implemented in software, may be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When loaded and executed on a computer, cause the processes or functions described in accordance with the embodiments of the invention to occur, in whole or in part. The computer may be a general purpose computer, a special purpose computer, a network of computers, or other programmable device. The computer instructions may be stored in a computer readable storage medium or transmitted from one computer readable storage medium to another, for example, from one website site, computer, server, or data center to another website site, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, Digital Subscriber Line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.). The computer-readable storage medium can be any available medium that can be accessed by a computer or a data storage device, such as a server, a data center, etc., that incorporates one or more of the available media. The usable medium may be a magnetic medium (e.g., floppy Disk, hard Disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., Solid State Disk (SSD)), among others.
It is noted that, herein, relational terms such as first and second, and the like may be used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Also, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other identical elements in a process, method, article, or apparatus that comprises the element.
All the embodiments in the present specification are described in a related manner, and the same and similar parts among the embodiments may be referred to each other, and each embodiment focuses on the differences from the other embodiments. In particular, as for the device, the electronic apparatus and the storage medium embodiments, since they are substantially similar to the method embodiments, the description is relatively simple, and the relevant points can be referred to the partial description of the method embodiments.
The above description is only for the preferred embodiment of the present invention, and is not intended to limit the scope of the present invention. Any modification, equivalent replacement, or improvement made within the spirit and principle of the present invention shall fall within the protection scope of the present invention.

Claims (12)

1. A method for testing an application program, comprising:
determining a page to be tested of the application program to be tested;
obtaining an element hash table of the page to be detected; the element hash table stores elements in an element tree of the page to be tested, and a key code required for accessing the elements stored in the element hash table is constructed based on element information of the elements;
obtaining a test script corresponding to the page to be tested; an operation instruction for operating and controlling the element to be operated and controlled in the page to be tested is recorded in the test script;
executing the test script to test the page to be tested; when the test script is executed to test the page to be tested, the element to be controlled is positioned based on the element hash table and a key code corresponding to the element to be controlled and indicated by the control instruction; and after the positioning, executing the control action which is indicated by the control instruction and is used for controlling the element to be controlled.
2. The method of claim 1, wherein constructing a key required to access an element stored in the element hash table based on element information of the element comprises:
determining whether the element information of the element comprises an element identifier;
and if the element information of the element comprises the element identifier of the element, determining that the element identifier of the element is the key code corresponding to the element, otherwise, constructing the key code uniquely corresponding to the element based on at least two kinds of element information in the element information of the element.
3. The method according to claim 2, wherein the step of constructing a key uniquely corresponding to the element based on at least two kinds of element information among the element information of the element comprises:
acquiring the element type of the element and the image-text information in the element from the element information of the element; the image-text information is text information in the element or identification information of a picture in the element;
and generating a key code uniquely corresponding to the element by using a preset key code generation algorithm according to the acquired element type and the image-text information.
4. The method according to claim 3, wherein the key generation algorithm is an algorithm for character concatenation of characters characterizing the element type, characters characterizing the teletext information, and characters characterizing additional information;
wherein the additional information is: and the numbers are used for distinguishing elements with the same element types and the same image-text information.
5. The method according to any one of claims 1 to 4, wherein the obtaining the element hash table of the page to be tested comprises:
judging whether an element hash table of the page to be detected exists or not;
if the page to be detected exists, obtaining an existing element hash table of the page to be detected;
if the element tree does not exist, determining each element which can be controlled by a user in the element tree of the page to be tested; and constructing an element hash table of the page to be tested based on each element which can be controlled by the user.
6. An apparatus for testing an application, comprising:
the determining module is used for determining a page to be tested of the application program to be tested;
the first obtaining module is used for obtaining an element hash table of the page to be detected; the element hash table stores elements in an element tree of the page to be tested, and a key code required for accessing the elements stored in the element hash table is constructed based on element information of the elements;
the second obtaining module is used for obtaining a test script corresponding to the page to be tested; an operation instruction for operating and controlling the element to be operated and controlled in the page to be tested is recorded in the test script;
the script execution module is used for executing the test script to test the page to be tested; when the page to be controlled is tested during the execution of the test script, the element to be controlled is positioned based on the element hash table and a key code corresponding to the element to be controlled and indicated by the control instruction; and after the positioning, executing the control action which is indicated by the control instruction and is used for controlling the element to be controlled.
7. The apparatus of claim 6, wherein the means for constructing a key required to access the element stored in the element hash table based on the element information of the element comprises:
determining whether the element information of the element comprises an element identifier;
and if the element information of the element comprises the element identifier of the element, determining that the element identifier of the element is the key code corresponding to the element, otherwise, constructing the key code uniquely corresponding to the element based on at least two kinds of element information in the element information of the element.
8. The apparatus of claim 7, wherein constructing a key uniquely corresponding to the element based on at least two of the element information of the element comprises:
acquiring the element type of the element and the image-text information in the element from the element information of the element; the image-text information is text information in the element or identification information of a picture in the element;
and generating a key code uniquely corresponding to the element by using a preset key code generation algorithm according to the acquired element type and the image-text information.
9. The apparatus according to claim 8, wherein the key generation algorithm is an algorithm for character concatenation of characters characterizing the element type, characters characterizing the teletext information, and characters characterizing additional information;
wherein the additional information is: and the numbers are used for distinguishing elements with the same element types and the same image-text information.
10. The apparatus of claim 9, wherein the first obtaining module is specifically configured to:
judging whether an element hash table of the page to be detected exists or not;
if the page to be detected exists, obtaining an existing element hash table of the page to be detected;
if the element tree does not exist, determining each element which can be controlled by a user in the element tree of the page to be tested; and constructing an element hash table of the page to be tested based on each element which can be controlled by the user.
11. An electronic device is characterized by comprising a processor, a communication interface, a memory and a communication bus, wherein the processor and the communication interface are used for realizing mutual communication by the memory through the communication bus;
a memory for storing a computer program; a processor for implementing the method steps of any one of claims 1 to 5 when executing a program stored in the memory.
12. A computer-readable storage medium, having stored therein instructions, which, when run on a computer, cause the computer to perform the method steps of any of claims 1-5.
CN201911054050.7A 2019-10-31 2019-10-31 Application program testing method and device, electronic equipment and storage medium Active CN110781091B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201911054050.7A CN110781091B (en) 2019-10-31 2019-10-31 Application program testing method and device, electronic equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201911054050.7A CN110781091B (en) 2019-10-31 2019-10-31 Application program testing method and device, electronic equipment and storage medium

Publications (2)

Publication Number Publication Date
CN110781091A true CN110781091A (en) 2020-02-11
CN110781091B CN110781091B (en) 2023-10-27

Family

ID=69388250

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201911054050.7A Active CN110781091B (en) 2019-10-31 2019-10-31 Application program testing method and device, electronic equipment and storage medium

Country Status (1)

Country Link
CN (1) CN110781091B (en)

Cited By (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111552627A (en) * 2020-03-16 2020-08-18 平安科技(深圳)有限公司 User interface testing method and device, storage medium and computer equipment
CN111737697A (en) * 2020-08-06 2020-10-02 中国人民解放军国防科技大学 Safety scanning system and scanning method based on atomization function
CN112115051A (en) * 2020-09-09 2020-12-22 福建新大陆软件工程有限公司 Page traversal detection method, device and equipment for application and readable storage medium
CN113094625A (en) * 2021-05-10 2021-07-09 北京京东振世信息技术有限公司 Page element positioning method and device, electronic equipment and storage medium
CN113791786A (en) * 2021-09-23 2021-12-14 安然 APP page control automation method and device based on IOS system

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20140250426A1 (en) * 2011-11-18 2014-09-04 Huawei Technologies Co., Ltd. Page testing method and page testing apparatus
CN107153707A (en) * 2017-05-12 2017-09-12 华中科技大学 A kind of Hash table construction method and system for nonvolatile memory
CN108153757A (en) * 2016-12-02 2018-06-12 深圳市中兴微电子技术有限公司 A kind of method and apparatus of Hash table management
CN109189688A (en) * 2018-09-11 2019-01-11 北京奇艺世纪科技有限公司 A kind of generation method, generating means and the electronic equipment of test case script
CN110221959A (en) * 2019-04-16 2019-09-10 阿里巴巴集团控股有限公司 Test method, equipment and the computer-readable medium of application program

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20140250426A1 (en) * 2011-11-18 2014-09-04 Huawei Technologies Co., Ltd. Page testing method and page testing apparatus
CN108153757A (en) * 2016-12-02 2018-06-12 深圳市中兴微电子技术有限公司 A kind of method and apparatus of Hash table management
CN107153707A (en) * 2017-05-12 2017-09-12 华中科技大学 A kind of Hash table construction method and system for nonvolatile memory
CN109189688A (en) * 2018-09-11 2019-01-11 北京奇艺世纪科技有限公司 A kind of generation method, generating means and the electronic equipment of test case script
CN110221959A (en) * 2019-04-16 2019-09-10 阿里巴巴集团控股有限公司 Test method, equipment and the computer-readable medium of application program

Cited By (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111552627A (en) * 2020-03-16 2020-08-18 平安科技(深圳)有限公司 User interface testing method and device, storage medium and computer equipment
WO2021184725A1 (en) * 2020-03-16 2021-09-23 平安科技(深圳)有限公司 User interface test method and apparatus, storage medium, and computer device
CN111737697A (en) * 2020-08-06 2020-10-02 中国人民解放军国防科技大学 Safety scanning system and scanning method based on atomization function
CN112115051A (en) * 2020-09-09 2020-12-22 福建新大陆软件工程有限公司 Page traversal detection method, device and equipment for application and readable storage medium
CN113094625A (en) * 2021-05-10 2021-07-09 北京京东振世信息技术有限公司 Page element positioning method and device, electronic equipment and storage medium
CN113094625B (en) * 2021-05-10 2023-09-05 北京京东振世信息技术有限公司 Page element positioning method and device, electronic equipment and storage medium
CN113791786A (en) * 2021-09-23 2021-12-14 安然 APP page control automation method and device based on IOS system
CN113791786B (en) * 2021-09-23 2024-01-19 安然 APP page control automation method and device based on IOS system

Also Published As

Publication number Publication date
CN110781091B (en) 2023-10-27

Similar Documents

Publication Publication Date Title
CN110781091B (en) Application program testing method and device, electronic equipment and storage medium
CN110795088B (en) Front-end engineering project construction method and tool, and computer-readable storage medium
CN110287696B (en) Detection method, device and equipment for rebound shell process
CN103164334A (en) System and method for detecting breaking point in web application automatic test case
US11741002B2 (en) Test automation systems and methods using logical identifiers
US20050137844A1 (en) Method for generating a language-independent regression test script
JP6440895B2 (en) Software analysis apparatus and software analysis method
US7669192B2 (en) Method to find a violation of a coding rule in program
JPWO2018092237A1 (en) PROGRAM CODE GENERATION DEVICE, PROGRAM CODE GENERATION METHOD, AND PROGRAM CODE GENERATION PROGRAM
CN109189688B (en) Test case script generation method and device and electronic equipment
US10678864B2 (en) Analysis model preparing system, programming apparatus, and analysis model preparing method
CN112231197A (en) Page testing method and device and storage medium
US8813036B2 (en) Visual representation of a difference between Cartesian product models
CN111078529B (en) Client writing module testing method and device and electronic equipment
JP7318704B2 (en) Test equipment, test method and program
CN111221610B (en) Page element acquisition method and device
CN109726376B (en) Standard template generation method and device and electronic equipment
JP6739599B1 (en) Information processing program, information processing method, and information processing apparatus
CN111104318B (en) Unit test result export method and device and electronic equipment
US12001324B2 (en) Operation pattern generation apparatus, operation pattern generation method and program
CN115129355B (en) Page repair method, system and computer equipment thereof
JP2014059699A (en) Demo application generation system and demo application generation program
CN113220307B (en) Optimization method and device for code coverage analysis and electronic equipment
CN113220596B (en) Application testing method, device, equipment, storage medium and program product
CN114416641A (en) File data processing method and device, electronic equipment and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant