CN111881043A - Page testing method and device, storage medium and processor - Google Patents

Page testing method and device, storage medium and processor Download PDF

Info

Publication number
CN111881043A
CN111881043A CN202010732905.3A CN202010732905A CN111881043A CN 111881043 A CN111881043 A CN 111881043A CN 202010732905 A CN202010732905 A CN 202010732905A CN 111881043 A CN111881043 A CN 111881043A
Authority
CN
China
Prior art keywords
page
unique identifier
document object
configuration data
target
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
CN202010732905.3A
Other languages
Chinese (zh)
Other versions
CN111881043B (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.)
Hillstone Networks Co Ltd
Original Assignee
Hillstone Networks 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 Hillstone Networks Co Ltd filed Critical Hillstone Networks Co Ltd
Priority to CN202010732905.3A priority Critical patent/CN111881043B/en
Publication of CN111881043A publication Critical patent/CN111881043A/en
Application granted granted Critical
Publication of CN111881043B publication Critical patent/CN111881043B/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
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3668Software testing
    • G06F11/3672Test management

Abstract

The invention discloses a page testing method, a page testing device, a storage medium and a processor. Wherein, the method comprises the following steps: under the condition of starting an automatic testing framework, obtaining configuration data, wherein the configuration data at least comprises a page to be tested; generating a code for acquiring the unique identifier of the corresponding target document object according to the attribute of the configuration data; injecting the code into a browser for execution to obtain the unique identifier of the target assembly, and transmitting the unique identifier of the target assembly back to the test frame; in the automated testing framework, the page to be tested is tested based on the unique identification of the target component. The invention solves the technical problem of low efficiency of the page test in the prior art.

Description

Page testing method and device, storage medium and processor
Technical Field
The invention relates to the field of data processing, in particular to a page testing method, a page testing device, a storage medium and a processor.
Background
At present, in the process of testing a page, a tester can check whether the page display is correct or not according to a test case after loading the page; it is also possible to automatically test whether the page is correct by a test script.
The premise of the above method for performing page testing is that a corresponding Document Object (DOM) can be obtained according to an address (ID) or other attributes, and the ID of a page generated by a frame is uncertain, so that the DOM Object needs to be located in the testing process, so that the automatic testing of the page can be realized.
In the related art, a developer defines an attribute value (e.g., key) or a padding ID value for a dynamic component for testing. The tester can position the corresponding DOM object according to the fixed values, and then judge the attribute of the DOM object.
Externally, the current DOM object has a random ID and changes every time it is generated. In the process of testing, a developer is required to specify the ID of the current DOM object or separately define an attribute value for searching the DOM object in the process of development. After the DOM object is obtained, the tester can continue to write test cases to test the page logic.
However, the above method requires developers to separately fill the ID with a fixed value, or to specially define an attribute value for assignment, so as to search the DOM object; if the whole form is also dynamically generated, the fixed value has no way to be filled; a large number of test cases also need to be written, resulting in inefficient page testing.
Aiming at the technical problem of low efficiency of page testing in the prior art, no effective solution is provided at present.
Disclosure of Invention
The embodiment of the invention provides a page testing method, a page testing device, a storage medium and a processor, which are used for at least solving the technical problem of efficiency of technical page testing.
According to one aspect of the embodiment of the invention, a page testing method is provided. The method can comprise the following steps: under the condition of starting an automatic testing framework, obtaining configuration data, wherein the configuration data at least comprises a page to be tested; generating a code for acquiring the unique identifier of the corresponding target document object according to the attribute of the configuration data; injecting the code into a browser for execution to obtain a unique identifier of the target component; in the automated testing framework, the page to be tested is tested based on the unique identification of the target component.
Optionally, generating a code for acquiring a unique identifier of a corresponding target document object according to an attribute of the configuration data includes: acquiring a target document object stored in an automatic test framework through the attribute name of the configuration data; and acquiring the unique identifier of the target document object through the attribute of the configuration data, and acquiring the code.
Optionally, before generating a code for acquiring the unique identifier of the corresponding target document object according to the attribute of the configuration data, the method further includes: and querying the unique identification of the target document object corresponding to the configuration data through the target function in the automatic test framework.
Optionally, before generating a code for acquiring the unique identifier of the corresponding target document object according to the attribute of the configuration data, the method further includes: acquiring a plurality of document objects corresponding to configuration data and stored in an automatic test framework; determining a target document object in the plurality of document objects through cross validation; and acquiring the unique identification of the target document object.
Optionally, determining a target document object among the plurality of document objects through cross validation includes: acquiring unique identifiers of a plurality of document objects through attribute names, wherein configuration data comprises to-be-tested data, and a plurality of fields in the to-be-tested data comprise the attribute names; determining the unique identifier of the first document object from the unique identifiers of the plurality of document objects, wherein the unique identifier of the first document object obtained through the attribute name corresponding to the first document object is unique; determining the address of a parent container corresponding to the unique identifier of the first document object; the target document object is found based on the address of the parent container.
Optionally, injecting a code into a browser for execution, and obtaining a unique identifier of the target component, where the unique identifier includes: generating a target script based on the code; injecting a target script into a browser for execution, and acquiring query data based on a hidden document object node; a unique identification of the target component is obtained based on the query data.
Optionally, injecting a code into a browser for execution, and obtaining a unique identifier of the target component, where the unique identifier includes: generating a target script based on the code; injecting the target script into a browser for execution, and calling an injection function to inquire the unique identifier of the target document object; and acquiring the unique identifier of the target component corresponding to the unique identifier of the target document object.
According to another aspect of the embodiment of the invention, the invention further provides a page testing device. The apparatus may include: the system comprises an acquisition unit, a test unit and a test unit, wherein the acquisition unit is used for acquiring configuration data under the condition of starting an automatic test framework, and the configuration data at least comprises a page to be tested; the query unit is used for generating a code for acquiring the unique identifier of the corresponding target document object according to the attribute of the configuration data; the injection unit is used for injecting the code into the browser for execution to obtain the unique identifier of the target component; and the testing unit is used for testing the page to be tested based on the unique identifier of the target component in the automatic testing framework.
According to another aspect of the embodiments of the present invention, there is also provided a computer-readable storage medium. The computer readable storage medium comprises a stored program, wherein when the program runs, the device where the computer readable storage medium is located is controlled to execute the page testing method of the embodiment of the invention.
According to another aspect of the embodiments of the present invention, a processor is further provided, where the processor is configured to run a program, and the program executes the page testing method according to the embodiments of the present invention when running.
In the embodiment of the invention, under the condition of starting an automatic testing framework, configuration data is obtained, wherein the configuration data at least comprises a page to be tested; generating a code for acquiring the unique identifier of the corresponding target document object according to the attribute of the configuration data; injecting the code into a browser for execution to obtain a unique identifier of the target component; in the automated testing framework, the page to be tested is tested based on the unique identification of the target component. That is to say, the method and the device for testing the page have the advantages that the unique identification of the target document object to be filled or clicked is obtained by the aid of a dynamic pass-back mechanism according to the configuration data in a data-driven mode through the configuration data, then the unique identification of the corresponding target component can be obtained by the aid of an encapsulation Dom pass-back mechanism through an automatic testing framework, testing of the automatic page is achieved, test cases are prevented from being handwritten by testers, development period and cost are high, the problem that the testers cannot or need to test the dynamically generated page through a method for defining key values is solved, the technical problem of low efficiency of page testing is solved, and the technical effect of improving efficiency of page testing is achieved.
Drawings
The accompanying drawings, which are included to provide a further understanding of the invention and are incorporated in and constitute a part of this application, illustrate embodiment(s) of the invention and together with the description serve to explain the invention without limiting the invention. In the drawings:
FIG. 1 is a flow chart of a method of testing a page according to an embodiment of the invention;
FIG. 2 is a schematic diagram of nodes through a DOM tree according to one of the related art;
FIG. 3 is a schematic diagram of modifying a presentation of a page by adding nodes to a DOM tree, according to one of the related art;
FIG. 4 is a schematic diagram of modifying a presentation of a page by adding nodes to a DOM tree in accordance with another of the related art;
FIG. 5 is a schematic diagram of modifying a presentation of a page by deleting nodes in a DOM tree, according to one of the related art;
FIG. 6 is a schematic diagram of an automated test page according to an embodiment of the present invention;
FIG. 7 is a schematic diagram illustrating that a test script can obtain an ID of a target DOM to be filled or clicked through a dynamic feedback mechanism according to an embodiment of the present invention;
FIG. 8 is a flow chart of a method of returning an ID in accordance with an embodiment of the present invention;
FIG. 9 is a diagram illustrating return information of an API get function that directly calls a test framework according to an embodiment of the invention; and
FIG. 10 is a diagram of a page testing apparatus according to an embodiment of the present invention.
Detailed Description
In order to make the technical solutions of the present invention better understood, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
It should be noted that the terms "first," "second," and the like in the description and claims of the present invention and in the drawings described above are used for distinguishing between similar elements and not necessarily for describing a particular sequential or chronological order. It is to be understood that the data so used is interchangeable under appropriate circumstances such that the embodiments of the invention described herein are capable of operation in sequences other than those illustrated or described herein. Furthermore, the terms "comprises," "comprising," and "having," and any variations thereof, are intended to cover a non-exclusive inclusion, such that a process, method, system, article, or apparatus that comprises a list of steps or elements is not necessarily limited to those steps or elements expressly listed, but may include other steps or elements not expressly listed or inherent to such process, method, article, or apparatus.
Example 1
In accordance with an embodiment of the present invention, there is provided an embodiment of a page test method, it should be noted that the steps illustrated in the flowchart of the figure may be performed in a computer system such as a set of computer executable instructions, and that while a logical order is illustrated in the flowchart, in some cases the steps illustrated or described may be performed in an order different than here.
Fig. 1 is a flowchart of a page testing method according to an embodiment of the present invention. As shown in fig. 1, the method may include the steps of:
step S102, under the condition that the automatic testing framework is started, configuration data is obtained, wherein the configuration data at least comprises a page to be tested.
In the technical solution provided by step S102 of the present invention, an automatic test tool may be started first, where the automatic test tool may be referred to as a dynamic frame, and then configuration data is loaded, where the configuration data describes a test page to be tested, and may also include required test data and the like. The embodiment may load a test page according to the configuration data.
The automatic implementation of the page test in this embodiment is implemented in a data-driven manner, and the format of the data may be a lightweight data exchange format (JavaScript Object corporation, abbreviated as JSON) or an eXtensible Markup Language (XML). The key information required in the configuration data of this embodiment may include the following information: uniform Resource Locator (URL) (page to be tested), test data, violation mechanism of operation, verification mechanism of data, etc.
Optionally, in this embodiment, the configuration data is JSON data, and may be represented by the following code:
Figure BDA0002603837800000051
alternatively, the configuration data is XML data, and may be represented by the following code:
Figure BDA0002603837800000052
Figure BDA0002603837800000061
in the above configuration data, url: html can be used to represent the URL of the test page; action "create" can be used to indicate the behavior of the test, i.e., currently a create operation; data { } can be used to represent the Data to be tested, the system needs to fill the Data into the form, and then send the Data to the background or store it in other media.
And step S104, generating a code for acquiring the unique identifier of the corresponding target document object according to the attribute of the configuration data.
In the technical solution provided by step S104 of the present invention, after the configuration data is acquired, a code for acquiring a unique identifier of the corresponding target document object may be generated according to an attribute of the configuration data.
In this embodiment, a unique identifier of the target document object (DOM object), for example, an ID of the target document object, may be obtained according to the configuration data. In the embodiment, the IDs of the automated testing framework are dynamically generated, and a set of method is needed to obtain the dynamic IDs.
In this embodiment, the tester cannot obtain the dynamically generated ID, and if the DOM attribute is checked, the ID may be recorded in the automation script, and when the loaded page is run next time, the page is regenerated, and at this time, the ID changes, and the automation test script also fails. Therefore, the embodiment may adopt a dynamic backhaul mechanism, so that the test script may obtain the unique identifier of the target document object (ID of the target DOM) to be filled or clicked, so as to enable the automated test framework to obtain the unique identifier of the corresponding target component, for example, the ID of the target component, through the mechanism of packaging DOM backhaul.
In this embodiment, the automated test framework has a method for querying the DOM object internally, and after the DOM object is obtained, the corresponding ID can be obtained.
And step S106, injecting the code into the browser for execution to obtain the unique identifier of the target component.
In the technical solution provided by step S106 of the present invention, after generating a code for acquiring the unique identifier of the corresponding target document object according to the attribute of the configuration data, the code for acquiring the unique identifier of the target document object may be injected into the browser for execution, so as to obtain the unique identifier of the target component.
In this embodiment, the automation test framework performs unit test on the operation of the DOM object, and although the automation test framework can inject a script and execute the script, the automation test framework cannot acquire a return value, so that a data return mechanism is required to ensure the return value.
In this embodiment, the uniquely identified code of the target document object may be generated into a script that needs to be injected into the browser for execution, and the script may mainly include three parts: calling an interface Application Program Interface (API) in a Webpage (WEB) frame, and inquiring a script of DOM object information according to the name; packaging the inquired information into data objects such as JSON and the like which are convenient for data analysis; and creating a hidden DOM object, and writing the data information into the hidden DOM object node.
In this embodiment, code that is needed when performing unit testing may be injected into the browser for execution through the automated testing framework. After the execution is finished, a hidden DIV is generated, wherein the hidden DIV contains the required unique identification information of the target component, and then the ID of the target component can be acquired by reading the DOM data with the fixed ID by using an automatic test framework.
Optionally, in this embodiment, if the automated testing framework can directly execute the function in the testing page and obtain the return value, implementing the return information by the DIV may be omitted, and the API of the automated testing framework is directly called to obtain the return value of the function, so as to query the unique identifier of the target document object, obtain the unique identifier of the target component, and return the unique identifier of the target component to the testing framework.
And S108, testing the page to be tested based on the unique identifier of the target component in the automatic testing framework.
In the technical solution provided in step S108 of the present invention, after the code is injected into the browser for execution to obtain the unique identifier of the target component, and the unique identifier of the target component is transmitted back to the test frame, the page logic of the page to be tested may be automatically tested in the automatic test frame based on the unique identifier of the target component.
Through the steps S102 to S108, configuration data is obtained under the condition that an automated testing framework is started, wherein the configuration data at least comprises a page to be tested; generating a code for acquiring the unique identifier of the corresponding target document object according to the attribute of the configuration data; injecting the code into a browser for execution to obtain a unique identifier of the target component; in the automated testing framework, the page to be tested is tested based on the unique identification of the target component. That is to say, in the embodiment, the unique identifier of the target document object to be filled or clicked is obtained according to the configuration data by using a data-driven manner for the configuration data through a dynamic pass-back mechanism, and then the unique identifier of the corresponding target component can be obtained by an automated testing framework through a packaging Dom pass-back mechanism, so that the test of the automated page is realized, the test case is prevented from being handwritten by a tester, the development period and the cost are high, and the problem that the tester cannot or needs to test the dynamically generated page through a method for defining key values is also avoided, so that the technical problems that the efficiency of page testing is low and the dynamic page testing cannot be performed are solved, and the technical effects of improving the efficiency of page testing and performing the dynamic page testing are achieved.
The above-described method of this embodiment is further described below.
As an optional implementation manner, step S104, generating a code for acquiring a unique identifier of a corresponding target document object according to an attribute of the configuration data, includes: acquiring a target document object stored in an automatic test framework through the attribute name of the configuration data; and acquiring the unique identification of the target document object through the attribute of the configuration data.
In this embodiment, the automated testing framework has a method for querying the target document object internally, and after the target document object is obtained, the corresponding address can be obtained. Optionally, in this embodiment, the target document object stored in the automated testing framework may be obtained by an attribute name (name) of the configuration data, and then the unique identifier of the target document object may be obtained by an attribute of the configuration data, which may be implemented by the following pseudo code:
var userDom=getDomByName(‘username’)[0];
varuserDomId=userDom.el.dom.id.
as an optional implementation manner, before generating, in step S104, a code for acquiring a unique identifier of a corresponding target document object according to an attribute of the configuration data, the method further includes: and querying the unique identification of the target document object corresponding to the configuration data through the target function in the automatic test framework.
In this embodiment, before generating a code for acquiring a unique identifier of a corresponding target document object according to an attribute of configuration data, the unique identifier of the target document object may also be directly acquired inside an automation test framework through an objective function, where the objective function may be getDomByName () [0], and may be implemented by the following pseudo code:
Var userDomId=getDomByName(‘username’)[0];
varuserDomId=userDom.id.
as an optional implementation manner, before generating, in step S104, a code for acquiring a unique identifier of a corresponding target document object according to an attribute of the configuration data, the method further includes: acquiring a plurality of document objects corresponding to configuration data and stored in an automatic test framework; determining a target document object in the plurality of document objects through cross validation; and acquiring the unique identification of the target document object.
In this embodiment, the unique identifier of the target document object is not obtained through the unique identifier (if the unique identifier exists, the unique identifier of the target document object does not need to be obtained separately). This embodiment acquires a plurality of document objects (DOM objects) corresponding to configuration data stored in an automation test framework, but when a plurality of DOM objects are acquired by an internal method, there is a case where the query is invalid at this time. Therefore, the embodiment determines the target document object from the plurality of document objects through cross validation, that is, the target document object needs to be positioned through cross validation, and then the unique identifier of the target document object is obtained.
As an optional implementation manner, determining a target document object in a plurality of document objects through cross validation includes: acquiring unique identifiers of a plurality of document objects through attribute names, wherein configuration data comprises to-be-tested data, and a plurality of fields in the to-be-tested data comprise the attribute names; determining the unique identifier of the first document object from the unique identifiers of the plurality of document objects, wherein the unique identifier of the first document object obtained through the attribute name corresponding to the first document object is unique; determining the address of a parent container corresponding to the unique identifier of the first document object; the target document object is found based on the address of the parent container.
In this embodiment, when a target document object is determined among a plurality of document objects through cross validation, the configuration Data includes Data to be tested (Data) having a plurality of fields, and at this time, unique identifiers of the plurality of document objects, that is, IDs of all DOMs are obtained by attribute names. The embodiment can determine the unique identifier of the first document object from the unique identifiers of the plurality of document objects, the unique identifier of the first document object obtained through the attribute name corresponding to the first document object is unique, then the address of the parent container corresponding to the unique identifier of the first document object is determined, namely, when the ID of the DOM object obtained through any one attribute name is unique, the ID of the parent container of the current DOM can be confirmed. After determining the address of the parent container corresponding to the unique identifier of the first document object, the target document object may be searched based on the address of the parent container, and optionally, the embodiment may search, starting from the parent container, for a DOM object under the current parent container, and determine it as the target document object.
As an optional implementation, injecting code into a browser for execution to obtain a unique identifier of a target component includes: generating a target script based on the code; injecting a target script into a browser for execution, and acquiring query data based on a hidden document object node; a unique identification of the target component is obtained based on the query data.
In this embodiment, the automation test framework performs unit test on the operation of the DOM object, and the automation test framework can inject a script and execute the script, but cannot acquire a return value. A data backhaul mechanism is needed to guarantee this. In the embodiment, the code of the unique identifier of the target document object is injected into the browser for execution, and the method for obtaining the unique identifier of the target component is a method for returning the ID. The embodiment starts the browser through the automatic test framework and loads the test page, and generates the code to be injected into the target script executed by the browser, wherein the target script is a JS script generated according to Data to be injected into the browser. Optionally, the function of the target script in this embodiment may include three parts, which may be a script that calls an internal API of the WEB framework, queries DOM object information according to a name, and executes an ID query of a DOM object; the queried information can also be packaged into data objects such as JSON and the like which are convenient for data analysis, namely the queried data is packaged into JSON data; and a hidden DOM object can be created, and the data information of the JSON is written into the node of the hidden DOM object, namely, the data information of the JSON is written into the hidden DOM script.
Optionally, the embodiment injects the target script into the browser for execution, and obtains query data based on a hidden document object node (hidden DOM node), where the query data may include information such as a unique identifier of the target document object, and then obtains a unique identifier of the target component based on the query data.
In this embodiment, the basic logic for injecting a target script into a browser may be as follows:
Figure BDA0002603837800000101
Figure BDA0002603837800000111
the resulting ID is encapsulated in the following DOM manner:
<div id=”>
var div_test=document.createElement('div');
div_test.id='test_id';
document.body.appendChild(div_test);
div_test.style.display=”none”;
var id _ str ═ getcomid (querystr); // obtaining strings of the corresponding id or list of ids by the previous method
document.getElementById('test_id').innerText=str.
After the preparation work is completed, the above codes need to be injected into the browser for execution through the test framework when the unit test is performed. After execution is complete, a hidden DIV can be generated that contains the unique identification of the desired target component. And then reading the data of the target document object with the fixed address by using an automatic test framework to obtain the unique identification of the corresponding target component.
As an optional implementation manner, step S106, injecting a code into the browser for execution, and obtaining a unique identifier of the target component, includes: generating a target script based on the code; injecting the target script into a browser for execution, and calling an injection function to inquire the unique identifier of the target document object; and acquiring the unique identifier of the target component corresponding to the unique identifier of the target document object.
In this embodiment, if the function in the test page can be directly executed in the automated test framework and the return value is obtained, the return information realized by the DIV can be directly omitted, and the API of the test framework can be directly called to obtain the return value of the function. The browser is started, the JS script of the query DOM is generated and injected into the browser to be executed, the injection function is called to query the unique identifier of the target document object, and then the unique identifier of the target component corresponding to the unique identifier of the target document object is obtained.
The embodiment can be suitable for application of a web browser (web browser) and an application system with data entry operation, the web browser is realized by a frame and automatically generates a DOM ID, and unit testing can be realized in a data-driven mode.
By adopting the data-driven dynamic page testing method and the dynamic page DOMID query feedback method, the embodiment can realize automatic testing of the dynamic page, avoid the operation of customizing the attribute aiming at the test requirement in order to test the page, solve the problem that a tester writes a test case by hand, lead the development period and the cost to be higher, and also avoid the problem that the tester can not or needs to test the dynamically generated page by defining key values, thereby solving the technical problems of low efficiency of page testing and incapability of testing the dynamic page, and further achieving the technical effects of improving the efficiency of page testing and testing the dynamic page.
Example 2
The technical solutions of the embodiments of the present invention are further described below with reference to preferred embodiments.
Browser-based applications are becoming more popular, and the advent of cloud services has made browsers the most important means for graphical presentations. With the popularization of browser application, the front-end framework is more and more abundant, in order to improve the efficiency of developers, the framework can also generate complex pages through simple codes, and the premise of meeting the requirements of the complex pages is that the generation and management of DOM objects are automatically realized by bottom-layer codes. The management is mainly realized by ID inquiry, and in order to ensure that the IDs are not repeated, the frame generates the IDs by a certain rule and manages the IDs in the system.
Pages in the browser are rendered according to the DOM of the hypertext Markup Language (HTML). Fig. 2 is a schematic diagram of nodes passing through a DOM tree according to one of the related art. As shown in FIG. 2, each element on the page corresponds to a node on the DOM tree, and the program can modify the presentation of the page directly by modifying the node properties of the DOM tree or adding (deleting) nodes.
FIG. 3 is a schematic diagram of modifying a presentation of a page by adding nodes in a DOM tree according to one of the related art. As shown in fig. 3, when a node < div id ═ div _ name > name [ ] is added to the DOM tree, the word "name" is displayed in the page.
FIG. 4 is a schematic diagram of modifying a presentation of a page by adding nodes to a DOM tree according to another of the related art. As shown in FIG. 4, a button id ═ button "> OK may be added to the DOM tree, and a button with the word" OK "is added to the page.
FIG. 5 is a schematic diagram of modifying a presentation of a page by deleting nodes in a DOM tree according to one of the related art. As shown in fig. 5, when the < div > name </div > is deleted, the "name" disappears from the page.
In the process of testing the page, there are two main ways: after the tester loads the page, checking whether the page display is correct or not according to the test case; and automatically testing whether the page is correct or not through the test script.
The premise of the above-mentioned page test is that the corresponding DOM object can be obtained according to the ID or other attributes, and the ID of the page generated by the frame is uncertain, so how to accurately locate the DOM object in the test process needs to be solved, so as to implement the automatic test of the page.
Alternatively, the developer may define attributes (e.g., key) or padding ID values for the dynamic component for testing. The tester can position the corresponding DOM object according to the fixed values, and then judge the attribute of the DOM object.
An ID or a fixed attribute value can be automatically generated in a normal automatic test frame to carry out component positioning, and the corresponding relation between a component and a DOM object can be automatically stored in the automatic test frame. For the external part, the current DOM object is a random ID and changes every time it is generated. The automatically generated DOM structure may be:
<div id=”div_34716345”>
</div>.
in the process of testing, a developer is required to specify the ID of the current DOM object or separately define an attribute value for searching the DOM object in the process of development. The DOM structure after adjustment is:
<div id=”div_username”>
</div>.
or
<div id=”div_34716345”key=”div_usernane”>
</div>.
The test framework can obtain the current DOM by having the ID value "div _ username" (or the key value "div _ username"). After the DOM object can be obtained, the tester can continue to write test cases to test the page logic.
In the related art, developers are required to independently fill the ID with a fixed value or specially define an attribute for assignment so as to search the DOM object; if the whole form is also dynamically generated, the fixed value has no way to be filled; a large number of test cases need to be written.
The embodiment can realize the test of the automatic page by adopting a data driving mode, can solve the problems of high development period and high cost caused by the fact that a tester writes a test case by hand, and can also solve the problem that the tester can not or needs to test the dynamically generated page by a method for defining key values.
FIG. 6 is a schematic diagram of an automated test page according to an embodiment of the invention. As shown in fig. 6, the method may include the steps of:
step S601, starting an automated testing framework.
Step S602, load configuration data.
In this embodiment, a page to be tested, test data, and the like are described in the configuration data.
Step S603, loading a test page according to the configuration data.
And step S604, acquiring the ID of the DOM according to the configuration data.
In this embodiment, the IDs are all dynamically generated, so a set of methods is required to obtain the dynamic IDs.
Step S605, fill data and perform a distribution operation.
In this embodiment, the automated implementation of testing is driven by configuration data. The format of the data can adopt JSON or XML, and the data comprises the following key information: URL (page to be tested), test data, offender mechanism of operation, verification mechanism of data.
The IDs of many automated test frameworks are dynamically generated. The dynamic generation has no way for ID testers to obtain, if DOM attributes need to be checked, the ID is recorded in the automatic script, when a page is loaded in the next running, the page is regenerated, the ID is changed, and at the moment, the automatic test script fails.
Therefore, a dynamic backhaul mechanism is needed to enable the test script to obtain the ID of the target DOM to be filled or clicked, and then a package DOM backhaul mechanism is needed to enable the test framework to obtain the ID of the corresponding component.
FIG. 7 is a schematic diagram of a mechanism for dynamic feedback to enable a test script to obtain an ID of a target DOM to be filled or clicked. As shown in fig. 7, the DOM may be searched according to the data object attribute, DOM1, DOM2, and DOM3 may be acquired according to getDomByName ('Username'), DOM1, and DOM2 may be acquired according to getByName ('AGE'), DOM _ provision may be acquired according to getByName ('provision'), and then the corresponding parent container may be determined, and the corresponding DOM _ AGE, DOM _ Username may be acquired.
In this embodiment, the dynamic framework has a method for querying the DOM object internally, and the corresponding ID can be obtained after the internal object is obtained.
In this embodiment, the object stored in the frame may be obtained by the name first, and then the corresponding ID may be obtained by the internal attribute of the object, or the DOM object may be directly obtained.
None of the above IDs is obtained by unique identification (if unique identification is available, it is not necessary to obtain ID separately). When multiple DOM objects are obtained through an internal method according to the attributes of the data objects, the query is invalid, and at the moment, cross validation is needed to locate one object.
When any DOM object obtained by any one attribute is unique, the ID of a parent container of the current DOM can be confirmed, and then the DOM object under the current container is searched by taking the parent container as a starting point.
The method of returning the ID of this embodiment is described below.
The automatic test framework performs unit test on the operation of the DOM object, can inject a script and execute the script, but cannot acquire a return value. A data backhaul mechanism is needed to guarantee this.
Fig. 8 is a flowchart of a method for returning an ID according to an embodiment of the present invention. As shown in fig. 8, the method may include the steps of:
step S801, the automated testing framework starts a browser and loads a test page.
And step S802, the automatic test framework generates a JS script which needs to be injected into the browser to be executed according to the Data.
And step S803, the browser calls an API inside the WEB framework, and queries the script of the DOM object information according to the name.
This embodiment may execute a script that queries the DOM object ID.
Step S804, the browser packages the inquired information into data objects such as JSON and the like which are convenient for data analysis.
The embodiment may encapsulate the query data into JSON data.
In step S805, the browser creates a hidden DOM object, and writes the data information into the node of the hidden DOM object.
This embodiment may write JSON data to a script that hides the DOM.
Step S806, the automatic test framework inquires the information of the hidden DOM node.
In step S807, return information of the browser is acquired.
The return message of this embodiment may include query data, which may include ID information of the DOM, etc.
After the preparation work is completed, the above codes need to be injected into the browser for execution through the test framework when the unit test is performed. Upon completion of execution, a hidden DIV is generated that contains the ID information of the required component. The ID of the component can be obtained by reading out the DOM data of the fixed ID by using the test framework.
In this embodiment, if the test framework can directly execute the function in the page and obtain the return value, the return information implemented by the DIV may be omitted, and the API of the automated test framework is directly called to obtain the return information of the function.
FIG. 9 is a diagram illustrating return information of an API get function that directly calls a test framework according to an embodiment of the present invention. As shown in fig. 9, the method may include the steps of:
step S901, the automated testing framework starts a browser.
In step S902, the automated test framework may query the function for DOM node IDs and inject the function into the browser.
This embodiment can generate a JS script that queries the DOM to be injected into the browser.
Step S903, the automatic test framework calls the injection function to the ID of the DOM node needing to be inquired.
Step S904, the automation test framework obtains the return information of the browser.
The return information may include ID information of the DOM, etc.
The embodiment can be suitable for application of a web browser and an application system with data entry operation, the ID information of the DOM is automatically generated and is realized through a frame with a page, and unit testing can be realized in a data-driven mode.
By adopting the test method of the data-driven dynamic page and the DOMID query feedback method of the dynamic page, the embodiment can realize the automatic test of the dynamic page, avoid the operation of customizing the attribute aiming at the test requirement in order to test the page, solve the problem that a tester writes a test case by hand, lead the development period and the cost to be higher, and also avoid that the tester can not test the dynamically generated page or needs to test the dynamically generated page by defining key values, thereby solving the technical problems of low efficiency of page test and incapability of testing the dynamic page, and further achieving the technical effect of improving the efficiency of page test and dynamic page test.
Example 3
The embodiment of the invention also provides a page testing device. It should be noted that the page testing apparatus of this embodiment can be used to execute the page testing method of this embodiment of the present invention,
FIG. 10 is a diagram of a page testing apparatus according to an embodiment of the present invention. As shown in fig. 10, the page test apparatus 10 may include: an acquisition unit 11, a query unit 12, an injection unit 13 and a test unit 14.
The obtaining unit 11 is configured to obtain configuration data when the automated testing framework is started, where the configuration data at least includes a page to be tested.
And the query unit 12 is configured to generate a code for acquiring a unique identifier of the corresponding target document object according to the attribute of the configuration data.
And the injection unit 13 is configured to inject a code into the browser for execution, so as to obtain a unique identifier of the target component.
And the testing unit 14 is used for testing the page to be tested based on the unique identification of the target component in the automatic testing framework.
In the page testing device of this embodiment, a data-driven manner is used for the configuration data, a dynamic return mechanism is used to obtain the unique identifier of the target document object to be filled or clicked according to the configuration data, and then an encapsulation Dom return mechanism is used to enable an automatic testing framework to obtain the unique identifier of the corresponding target component, so as to implement the test of the automatic page, avoid test cases being handwritten by a tester, increase the development period and cost, and avoid the tester failing or needing to test the dynamically generated page by defining key values, thereby solving the technical problems of low efficiency of page testing and failing to perform dynamic page testing, and achieving the technical effects of improving the efficiency of page testing and performing dynamic page testing.
Example 4
According to an embodiment of the present invention, there is also provided a computer-readable storage medium. The computer readable storage medium includes a stored program, wherein the computer readable storage medium controls an apparatus in which the computer readable storage medium is located to execute the computer readable storage medium of the embodiments of the present invention when the program runs.
Example 5
According to an embodiment of the present invention, there is also provided a processor, configured to run a program, where the program executes the page testing method described in embodiment 1 when running.
The above-mentioned serial numbers of the embodiments of the present invention are merely for description and do not represent the merits of the embodiments.
In the above embodiments of the present invention, the descriptions of the respective embodiments have respective emphasis, and for parts that are not described in detail in a certain embodiment, reference may be made to related descriptions of other embodiments.
In the embodiments provided in the present application, it should be understood that the disclosed technology can be implemented in other ways. The above-described embodiments of the apparatus are merely illustrative, and for example, the division of the units may be a logical division, and in actual implementation, there may be another division, for example, multiple units or components may be combined or integrated into another system, or some features may be omitted, or not executed. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection through some interfaces, units or modules, and may be in an electrical or other form.
The units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of the embodiment.
In addition, functional units in the embodiments of the present invention may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit. The integrated unit can be realized in a form of hardware, and can also be realized in a form of a software functional unit.
The integrated unit, if implemented in the form of a software functional unit and sold or used as a stand-alone product, may be stored in a computer readable storage medium. Based on such understanding, the technical solution of the present invention may be embodied in the form of a software product, which is stored in a storage medium and includes instructions for causing a computer device (which may be a personal computer, a server, or a network device) to execute all or part of the steps of the method according to the embodiments of the present invention. And the aforementioned storage medium includes: a U-disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a removable hard disk, a magnetic or optical disk, and other various media capable of storing program codes.
The foregoing is only a preferred embodiment of the present invention, and it should be noted that, for those skilled in the art, various modifications and decorations can be made without departing from the principle of the present invention, and these modifications and decorations should also be regarded as the protection scope of the present invention.

Claims (10)

1. A page testing method is characterized by comprising the following steps:
under the condition of starting an automatic testing framework, obtaining configuration data, wherein the configuration data at least comprises a page to be tested;
generating a code for acquiring the unique identifier of the corresponding target document object according to the attribute of the configuration data;
injecting the code into a browser for execution to obtain a unique identifier of the target component;
and in the automatic testing framework, testing the page to be tested based on the unique identification of the target component.
2. The method of claim 1, wherein generating a code for obtaining a unique identifier of a corresponding target document object according to the attributes of the configuration data comprises:
acquiring the target document object stored in the automatic test framework through the attribute name of the configuration data;
and acquiring the unique identifier of the target document object through the attribute of the configuration data, and acquiring the code.
3. The method of claim 1, prior to generating a code for obtaining a unique identification of a corresponding target document object according to the attributes of the configuration data, the method further comprising:
and querying the unique identification of the target document object corresponding to the configuration data through an objective function in the automatic test framework.
4. The method of claim 1, prior to generating a code for obtaining a unique identification of a corresponding target document object according to the attributes of the configuration data, the method further comprising:
acquiring a plurality of document objects which are stored in the automatic test framework and correspond to the configuration data;
determining the target document object in the plurality of document objects through cross validation;
and acquiring the unique identification of the target document object.
5. The method of claim 4, wherein determining the target document object among the plurality of document objects by cross-validation comprises:
acquiring unique identifiers of the plurality of document objects through attribute names, wherein the configuration data comprises data to be tested, and a plurality of fields in the data to be tested comprise the attribute names;
determining the unique identifier of a first document object from the unique identifiers of the plurality of document objects, wherein the unique identifier of the first document object obtained through the attribute name corresponding to the first document object is unique;
determining the address of a parent container corresponding to the unique identifier of the first document object;
and searching the target document object based on the address of the parent container.
6. The method of claim 1, wherein injecting the code into a browser for execution to obtain the unique identifier of the target component comprises:
generating a target script based on the code;
injecting the target script into the browser for execution, and acquiring query data based on a hidden document object node;
obtaining a unique identification of the target component based on the query data.
7. The method of claim 1, wherein injecting the code into a browser for execution to obtain the unique identifier of the target component comprises:
generating a target script based on the code;
injecting the target script into the browser for execution, and calling an injection function to inquire the unique identifier of the target document object;
and acquiring the unique identifier of the target component corresponding to the unique identifier of the target document object.
8. A page testing apparatus, comprising:
the system comprises an acquisition unit, a test unit and a test unit, wherein the acquisition unit is used for acquiring configuration data under the condition of starting an automatic test framework, and the configuration data at least comprises a page to be tested;
the query unit is used for generating a code for acquiring the unique identifier of the corresponding target document object according to the attribute of the configuration data;
the injection unit is used for injecting the code into the browser for execution to obtain the unique identifier of the target component;
and the testing unit is used for testing the page to be tested based on the unique identifier of the target component in the automatic testing framework.
9. A computer-readable storage medium, comprising a stored program, wherein the program, when executed, controls an apparatus in which the computer-readable storage medium is located to perform the method of any one of claims 1 to 7.
10. A processor, characterized in that the processor is configured to run a program, wherein the program when running performs the method of any of claims 1 to 7.
CN202010732905.3A 2020-07-27 2020-07-27 Page testing method and device, storage medium and processor Active CN111881043B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010732905.3A CN111881043B (en) 2020-07-27 2020-07-27 Page testing method and device, storage medium and processor

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010732905.3A CN111881043B (en) 2020-07-27 2020-07-27 Page testing method and device, storage medium and processor

Publications (2)

Publication Number Publication Date
CN111881043A true CN111881043A (en) 2020-11-03
CN111881043B CN111881043B (en) 2022-10-14

Family

ID=73201742

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010732905.3A Active CN111881043B (en) 2020-07-27 2020-07-27 Page testing method and device, storage medium and processor

Country Status (1)

Country Link
CN (1) CN111881043B (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112835809A (en) * 2021-03-22 2021-05-25 亿企赢网络科技有限公司 Test data setting method, device, equipment and medium based on browser
CN115412458A (en) * 2022-08-29 2022-11-29 山石网科通信技术股份有限公司 Network equipment testing method and device and electronic equipment

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110297752A (en) * 2018-03-23 2019-10-01 华为软件技术有限公司 Acquisition methods and device, automatization test system, the storage medium of control element
CN110928772A (en) * 2019-11-05 2020-03-27 深圳前海微众银行股份有限公司 Test method and device

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110297752A (en) * 2018-03-23 2019-10-01 华为软件技术有限公司 Acquisition methods and device, automatization test system, the storage medium of control element
CN110928772A (en) * 2019-11-05 2020-03-27 深圳前海微众银行股份有限公司 Test method and device

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112835809A (en) * 2021-03-22 2021-05-25 亿企赢网络科技有限公司 Test data setting method, device, equipment and medium based on browser
CN115412458A (en) * 2022-08-29 2022-11-29 山石网科通信技术股份有限公司 Network equipment testing method and device and electronic equipment
CN115412458B (en) * 2022-08-29 2023-11-03 山石网科通信技术股份有限公司 Network equipment testing method and device and electronic equipment

Also Published As

Publication number Publication date
CN111881043B (en) 2022-10-14

Similar Documents

Publication Publication Date Title
US10162738B2 (en) System, method, and computer readable medium for universal software testing
US9483260B1 (en) Documentation generation for web APIs based on byte code analysis
US20120191840A1 (en) Managing Application State Information By Means Of A Uniform Resource Identifier (URI)
US9411782B2 (en) Real time web development testing and reporting system
US8065667B2 (en) Injecting content into third party documents for document processing
CN110806863A (en) Interface document generation method and device, electronic equipment and storage medium
US20170109271A1 (en) User interface testing abstraction
CN107766344B (en) Template rendering method and device and browser
US9311303B2 (en) Interpreted language translation system and method
US11580001B2 (en) Dynamic generation of instrumentation locators from a document object model
US9262311B1 (en) Network page test system and methods
CN111881043B (en) Page testing method and device, storage medium and processor
CN104063401A (en) Webpage style address merging method and device
CN106776318A (en) A kind of test script method for recording and system
CN112187713B (en) Message conversion method, device, computer equipment and storage medium
CN111628975A (en) Method and device for assembling XML message
CN115599386A (en) Code generation method, device, equipment and storage medium
CN111679828B (en) Data processing method and device, electronic equipment and storage medium
CN117519877A (en) Rendering method and device of quick application card, storage medium and electronic equipment
CN111880789A (en) Page rendering method, device, server and computer-readable storage medium
CN116185825A (en) Front-end self-test method, front-end device, and computer-readable storage medium
CN115470127B (en) Page compatibility processing method, device, computer equipment and storage medium
CN116340156A (en) Method, device, equipment and medium for testing Web page of application program
CN114528013A (en) Text generation method and device, electronic equipment, storage medium and product
Donley et al. Web application testing challenges

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