CN114428736A - JavaScript-based component testing method and device, terminal equipment and medium - Google Patents

JavaScript-based component testing method and device, terminal equipment and medium Download PDF

Info

Publication number
CN114428736A
CN114428736A CN202210066961.7A CN202210066961A CN114428736A CN 114428736 A CN114428736 A CN 114428736A CN 202210066961 A CN202210066961 A CN 202210066961A CN 114428736 A CN114428736 A CN 114428736A
Authority
CN
China
Prior art keywords
interface
tested
component
javascript
test data
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.)
Pending
Application number
CN202210066961.7A
Other languages
Chinese (zh)
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.)
Shenzhen Digital Certificate Authority Center Co ltd
Original Assignee
Shenzhen Digital Certificate Authority Center 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 Shenzhen Digital Certificate Authority Center Co ltd filed Critical Shenzhen Digital Certificate Authority Center Co ltd
Priority to CN202210066961.7A priority Critical patent/CN114428736A/en
Publication of CN114428736A publication Critical patent/CN114428736A/en
Pending legal-status Critical Current

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
    • G06F11/3692Test management for test results analysis

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Computer Hardware Design (AREA)
  • Quality & Reliability (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Debugging And Monitoring (AREA)

Abstract

The application is applicable to the technical field of interface testing, and particularly relates to a JavaScript-based component testing method, device, terminal equipment and medium. The method comprises the steps of calling a JavaScript file corresponding to each interface name according to the interface names of N interfaces to be tested in a component to be tested, creating a corresponding input box, obtaining test data input by a user in each input box, calling an interface function corresponding to the interface name of the interface to be tested according to each interface name, sending the test data input in the input box of the corresponding JavaScript file to the component to be tested, judging whether the component to be tested is qualified or not according to the similarity between the interface output parameters corresponding to each interface name fed back by the component to be tested and the corresponding target output parameters, testing the component, avoiding dependence on an operating system, directly generating the corresponding input box based on the JavaScript file of an HTML page, having low requirement on assembly language and high universality and being beneficial to improving the testing efficiency.

Description

JavaScript-based component testing method and device, terminal equipment and medium
Technical Field
The application is applicable to the technical field of interface testing, and particularly relates to a JavaScript-based component testing method, device, terminal equipment and medium.
Background
At present, there are components capable of providing services for tools such as operating systems and application programs developed under different assembly languages, an interface is a basis for providing services for tools outside the components, and is used for realizing interaction between the components and the tools outside the components, and the quality of the components affects the quality of the interaction, so that the component products need to write test codes under a development environment before being released to perform white box testing on functions of each interface in the component products, and since most of the development languages used under the development environment are mastered by developers, testing of the component products needs to be completed by the developers, that is, the developers need to both develop the component products and test the component products, so that the development and testing efficiency cannot be improved, and testing the components through software applications becomes a main solution, but for the components composed of different assembly languages, software applications written in different languages are required to be used for testing, compatibility is poor, and testing efficiency is low. Therefore, how to effectively improve the testing efficiency of the component product becomes an urgent problem to be solved.
Disclosure of Invention
In view of this, embodiments of the present application provide a component testing method and apparatus based on JavaScript, a terminal device, and a medium, so as to solve a problem how to effectively improve testing efficiency of a component product.
In a first aspect, an embodiment of the present application provides a JavaScript-based component testing method, where the component testing method includes:
after the to-be-tested assembly is installed, acquiring interface names of N to-be-tested interfaces in the to-be-tested assembly, wherein N is a positive integer greater than zero;
calling JavaScript files corresponding to the interface names, creating corresponding input frames on the preset HTML page, and acquiring test data input by a user in each input frame;
calling an interface function corresponding to the interface name of each interface to be tested, sending test data input by the user in an input frame of a corresponding JavaScript file to the components to be tested, and acquiring interface parameters corresponding to the interface names fed back by the components to be tested;
and detecting the similarity between the interface output participation corresponding to each interface name and the target output participation corresponding to the interface name, and if the interface output participation with the similarity lower than a preset value is detected, determining that the test result of the component to be tested is unqualified.
In a second aspect, an embodiment of the present application provides a JavaScript-based component testing apparatus, where the component testing apparatus includes:
the interface name acquisition module is used for acquiring interface names of N to-be-tested interfaces in the to-be-tested components after the to-be-tested components are installed, wherein N is a positive integer greater than zero;
the test data acquisition module is used for calling JavaScript files corresponding to the interface names, creating corresponding input frames on the preset HTML page and acquiring test data input by a user in each input frame;
the sending and receiving module is used for calling an interface function corresponding to the interface name of each interface to be tested, sending the test data input by the user in the input box of the corresponding JavaScript file to the components to be tested, and acquiring the interface output parameters corresponding to the interface names fed back by the components to be tested;
and the component testing module is used for detecting the similarity between the interface output participation corresponding to each interface name and the target output participation corresponding to the interface name, and if the interface output participation with the similarity lower than a preset value is detected, determining that the testing result of the component to be tested is unqualified. In a third aspect, an embodiment of the present application provides a terminal device, where the terminal device includes a processor, a memory, and a computer program stored in the memory and executable on the processor, and the processor, when executing the computer program, implements the component testing method according to the first aspect.
In a fourth aspect, the present application provides a computer-readable storage medium, which stores a computer program, and when the computer program is executed by a processor, the computer program implements the component testing method according to the first aspect.
In a fifth aspect, an embodiment of the present application provides a computer program product, which, when running on a terminal device, causes the terminal device to execute the component testing method according to the first aspect.
Compared with the prior art, the embodiment of the application has the advantages that: after the installation of the components to be tested is completed, interface names of N interfaces to be tested in the components to be tested are obtained, JavaScript files corresponding to the interface names are called, namely, corresponding input frames can be created on the preset HTML page, test data input by a user in each input frame are obtained, interface functions corresponding to the interface names of the interfaces to be tested are called according to the interface names, the test data input in the input frames of the corresponding JavaScript files are sent to the components to be tested, whether the components to be tested are qualified or not is judged according to the similarity between the interface output participation corresponding to the interface names fed back by the components to be tested and the corresponding target output parameters, so that the testing of the components is realized, the dependence on an operating system is avoided, the corresponding input frames can be directly generated based on the JavaScript files of the HTML page, and the requirement on assembly language is low, the universality is higher, and the test efficiency is improved.
Drawings
In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings needed to be used in the embodiments or the prior art descriptions will be briefly described below, and it is obvious that the drawings in the following description are only some embodiments of the present application, and it is obvious for those skilled in the art to obtain other drawings based on these drawings without inventive exercise.
Fig. 1 is a schematic flowchart of a JavaScript-based component testing method according to an embodiment of the present application;
fig. 2 is a schematic flowchart of a JavaScript-based component testing method according to a second embodiment of the present application;
fig. 3 is a schematic structural diagram of a JavaScript-based component testing apparatus according to a third embodiment of the present application;
fig. 4 is a schematic structural diagram of a terminal device according to a fourth embodiment of the present application.
Detailed Description
In the following description, for purposes of explanation and not limitation, specific details are set forth, such as particular system structures, techniques, etc. in order to provide a thorough understanding of the embodiments of the present application. It will be apparent, however, to one skilled in the art that the present application may be practiced in other embodiments that depart from these specific details. In other instances, detailed descriptions of well-known systems, devices, circuits, and methods are omitted so as not to obscure the description of the present application with unnecessary detail.
It will be understood that the terms "comprises" and/or "comprising," when used in this specification and the appended claims, specify the presence of stated features, integers, steps, operations, elements, and/or components, but do not preclude the presence or addition of one or more other features, integers, steps, operations, elements, components, and/or groups thereof.
It should also be understood that the term "and/or" as used in this specification and the appended claims refers to and includes any and all possible combinations of one or more of the associated listed items.
As used in this specification and the appended claims, the term "if" may be interpreted contextually as "when", "upon" or "in response to" determining "or" in response to detecting ". Similarly, the phrase "if it is determined" or "if a [ described condition or event ] is detected" may be interpreted contextually to mean "upon determining" or "in response to determining" or "upon detecting [ described condition or event ]" or "in response to detecting [ described condition or event ]".
Furthermore, in the description of the present application and the appended claims, the terms "first," "second," "third," and the like are used for distinguishing between descriptions and not necessarily for describing or implying relative importance.
Reference throughout this specification to "one embodiment" or "some embodiments," or the like, means that a particular feature, structure, or characteristic described in connection with the embodiment is included in one or more embodiments of the present application. Thus, appearances of the phrases "in one embodiment," "in some embodiments," "in other embodiments," or the like, in various places throughout this specification are not necessarily all referring to the same embodiment, but rather "one or more but not all embodiments" unless specifically stated otherwise. The terms "comprising," "including," "having," and variations thereof mean "including, but not limited to," unless otherwise specifically stated.
The terminal device in the embodiment of the present application may be a palm top computer, a desktop computer, a notebook computer, an ultra-mobile personal computer (UMPC), a netbook, a cloud terminal device, a Personal Digital Assistant (PDA), and the like, and the specific type of the terminal device is not limited in this embodiment of the present application.
It should be understood that, the sequence numbers of the steps in the following embodiments do not mean the execution sequence, and the execution sequence of each process should be determined by the function and the inherent logic of the process, and should not constitute any limitation to the implementation process of the embodiments of the present application.
In order to explain the technical means of the present application, the following description will be given by way of specific examples.
Referring to fig. 1, a flowchart of a JavaScript-based component testing method provided in an embodiment of the present application is shown, where the component testing method is applied to a terminal device, and the terminal device may be a computer device running any operating system, and a browser supporting assembly using an HTML language exists in the operating system. As shown in fig. 1, the component testing method may include the steps of:
step S101, after the installation of the components to be tested is completed, the interface names of N interfaces to be tested in the components to be tested are obtained.
In the application, the component product is a software product obtained by packaging various interfaces, methods and the like, and can provide interface transmission service and feedback data for an application program, an operating system and other components. Aiming at a component product to be tested, the component product is required to be installed in terminal equipment to form a component to be tested, and the component testing method in the terminal equipment can call the component to be tested, execute a corresponding testing process and further form a testing report.
The component testing method can be packaged in a corresponding software program, detection of all component products on the terminal equipment can be started by triggering the software program, all installed components in the terminal equipment are obtained, and meanwhile, any browser in the terminal equipment can be started by the software program after the software program is triggered, so that the functions of data collection and data output are achieved.
In one embodiment, the software program can only detect a certain memory area after being triggered to obtain the installed components in the memory area, and therefore, the components to be tested need to be installed in the designated memory area to realize further testing.
In this application, the terminal device may determine whether the to-be-tested component is completely installed by detecting an installation state of the to-be-tested component, and after the to-be-tested component is completely installed, the to-be-tested component is analyzed or analyzed, so as to extract the to-be-tested interfaces in the to-be-tested component, and all the interfaces in the to-be-tested component are used as the to-be-tested interfaces, including N to-be-tested interfaces, where N is a positive integer greater than zero, and therefore, information of all the interfaces in the to-be-tested component needs to be extracted, including an interface function and/or an interface name and the like.
If the extracted interface information of the N interfaces to be tested in the components to be tested is an interface function, the interface function of each interface to be tested is used as an interface name corresponding to the interface to be tested, so that the interface name, namely the interface function, can be directly used after the interface name is combined with the JavaScript file, and the parameters in the JavaScript file are sent to the components to be tested.
If the extracted interface information of the N interfaces to be tested in the components to be tested is the interface name, the corresponding relation between the interface name and the interface function is configured in advance, when a JavaScript script file is used, the corresponding interface function can be determined according to the interface name in the JavaScript script file, then the interface function is called, and the parameters in the JavaScript script file are sent to the components to be tested.
In one embodiment, all the interfaces in the component to be tested are acquired, and the interfaces in the component to be tested are selected to determine that the interfaces to be tested are the interfaces to be tested finally, so that after all the interfaces in the component to be tested are acquired, a selection item is output for a user to select, the process can be used for repeated testing to realize refined detection, or after all the interfaces in the component to be tested are acquired, the interfaces to be tested are screened out according to screening conditions, and an interface white list can be preset in the process, so that unnecessary testing of the interfaces is avoided.
In an embodiment, the terminal device may send corresponding data to the installed component, detect feedback of the component, and determine whether the component is installed according to a feedback result. For example, Asynchronous JavaScript And XML (Asynchronous JavaScript And XML, Ajax) technology is used to send a request to create a corresponding control to any component, And if the feedback result is that creation is successful, the component is installed.
Step S102, calling JavaScript files corresponding to the interface names, creating corresponding input boxes on a preset HTML page, and acquiring test data input by a user in each input box.
In the application, when the software program is run on the terminal device, the browser on the terminal device is called, a preset HTML page is generated in the browser, and a JavaScript file is run in the HTML page, so that a corresponding input box can be created, wherein the JavaScript file has a function of creating the input box to obtain the input parameter data. For example, the preset HTML page may be a demo page, a JavaScript script file is run in the demo page, and a corresponding input box may be created in the demo page.
One interface name corresponds to one JavaScript script file, in the application, the corresponding relation between the interface name and the script file is configured in advance, the corresponding script file can be matched through the interface name, and the script file is called. Therefore, if the function of one script file is to create one input box, the JavaScript script file corresponding to each interface name is called, the number of created input boxes is the same as the number of interface names, and the created input boxes are associated with the JavaScript script file corresponding to the interface names.
Because the input box is associated with the JavaScript file corresponding to the interface name, the data input in the input box is associated with the JavaScript file corresponding to the interface name, and the data input in the input box is the input parameter of the corresponding JavaScript file.
In one embodiment, a JavaScript script template is configured in advance, the interface name is combined with the JavaScript script template to generate a JavaScript script file corresponding to the interface name, that is, the JavaScript script template is obtained, and each interface name is combined with the JavaScript script template to obtain the JavaScript script file corresponding to each interface name. Further, if the interface name is an interface function, combining the interface function with the JavaScript template to form a corresponding JavaScript script file.
The JavaScript is a high-level scripting language belonging to the internet, has a simple and compact design, is easy to use, and has been widely used for Web application development. The JavaScript script has a cross-platform characteristic and can run under various platforms, such as Windows, Linux, Mac, Android, iOS and the like, so that the dependence degree on an operating system is low, the JavaScript script can be supported by more browsers and does not need the support of a server.
According to the method and the device for testing the interface of the to-be-tested component, the input box established in the preset HTML page can directly input corresponding data, a user can input corresponding test data into the input box according to test requirements, the test data can be obtained through the JavaScript file corresponding to the input box, the corresponding interface function is used for executing a sending step, and the test of the interface corresponding to the to-be-tested component is achieved.
After the test data is input in the input box by the user, the input parameter is formed in the JavaScript script file corresponding to the input box. Specifically, after the input box created by the JavaScript script file, the content in the input box may be monitored and obtained in a variable manner in real time, so that the test data input in the input box is associated with the corresponding JavaScript script file and the interface name.
For example, the JavaScript script file 1 creates an input box 1, where the input box 1 has a unique Identity Document (ID), that is, a definition statement is set in the JavaScript script file 1 as:
<inpput type="text"id="bar1"/>;
the object of the input box is obtained through the getElementById method, namely an obtaining statement is set in the JavaScript script file 1 as follows:
<script>
var kuang1=document.getElementById("bar1")
wherein kuang1 represents an input box, and the value of the input box is an attribute of the input box, and the attribute can be obtained.
Optionally, before acquiring the test data input by the user in each input box, the method further includes:
extracting the character type of the test data input in each input box;
matching the character type corresponding to each input box with the entry type, wherein if the character type is matched with the entry type, the test data accords with the entry condition, and if the character type is not matched with the entry type, the test data does not accord with the entry condition;
the method for acquiring the test data input by the user in each input box comprises the following steps:
if the test data input in an input box is detected to accord with the entry condition, the test data in the input box is obtained;
and if the test data input in an input box is detected not to accord with the entry condition, outputting an error prompt in the input box.
The data input in the input box is to be written into the JavaScript script file, so that whether the data input in the input box meets the requirement can be detected according to the entry condition that the JavaScript script file writes a variable (i.e., input data) as a parameter.
And if the test data input in the input box is detected not to be in accordance with the entry condition, displaying an error prompt in the input box to prompt the user to pay attention to the input box.
And calling the interface function corresponding to the interface name of each interface to be tested in step S103, sending the test data input by the user in the input box of the corresponding JavaScript file to the component to be tested, and acquiring the interface output parameters corresponding to the interface names fed back by the component to be tested.
As can be seen from the step S102, the interface name, the interface function, and the JavaScript script file are in a one-to-one correspondence relationship, so that the corresponding interface function can be determined according to the interface name, the corresponding JavaScript script file can be determined according to the interface name, and then the test data input by the input box corresponding to the JavaScript script file is determined.
And calling an interface function of the interface to be tested aiming at one interface to be tested, and sending corresponding parameters to the component to be tested, wherein the parameters are test data obtained by an input box corresponding to the JavaScript script file. The calling can be realized by combining the interface function with the JavaScript file and running the JavaScript file, and then sending the test data acquired by the input frame corresponding to the JavaScript file to the component to be tested.
In one implementation mode, the interface name corresponds to a JavaScript file, the JavaScript file comprises an interface function corresponding to the interface name, and the JavaScript file corresponding to the interface name of the interface to be tested is operated, so that the access parameters can be sent to the component to be tested.
In one embodiment, the interface name is an interface function, and the interface name is written into a corresponding JavaScript script file, that is, the written JavaScript script file can be run, so that the test data is sent to the component to be tested.
Optionally, after obtaining the interface parameters corresponding to the interface names fed back by the component to be tested, the method further includes:
creating pop-up boxes corresponding to the interface names on a preset HTML page;
and displaying the interface output references corresponding to the interface names in the corresponding pop-up boxes.
After the test data are sent to the to-be-tested component, the to-be-tested component uses the method to calculate the test data, then feeds back a corresponding result, and the feedback result is used as an interface output parameter of the to-be-tested interface to be transmitted. After receiving the interface participation of the interface to be tested, the terminal equipment creates and pops up a corresponding pop-up box on the HTML page, and the interface participation is displayed in the pop-up box, so that a user can observe the interface participation to judge whether the functions of the component to be tested and the interface to be tested are normal.
And step S104, detecting the similarity between the interface output participation corresponding to each interface name and the target output participation corresponding to the interface name, and if the interface output participation with the similarity lower than a preset value is detected, determining that the test result of the component to be tested is unqualified.
In the application, after the test data is sent to the component to be tested, a corresponding result is generated after the test data is processed by a method or logic in the component to be tested, and the result is output through an interface and fed back to the terminal equipment. If the component to be tested is a qualified component, the interface output parameter of each interface to be tested is a target output parameter, for example, for the qualified COM component, the test data is sent to the COM component through a signature interface, the interface output parameter obtained by the interface signature is 1 (namely the target output parameter is 1), for the unqualified COM component, the test data is sent to the COM component through the signature interface, the interface output parameter obtained by the interface signature is 0, and the target output parameter is inconsistent with the target output parameter.
And each interface name in the qualified to-be-tested component corresponds to a target parameter, and if the target parameter similarity of the interface parameter corresponding to the interface name acquired by a certain interface name is lower than a preset value, the qualified to-be-tested component is indicated to be unqualified.
Specifically, the preset value may be 100%, that is, when the interface participation target participation parameters are completely consistent, it is indicated that the detection result of the component to be tested is qualified. Due to the fact that N to-be-tested interfaces exist in the to-be-tested assembly, the target output participation corresponding to the interface output participation of one to-be-tested interface in the N to-be-tested interfaces is inconsistent, and the detection result of the to-be-tested assembly is unqualified.
Different input parameters are different in output parameters fed back after passing through the to-be-tested component, if the output parameters show that no test data exists, the transmission dysfunction of the to-be-tested interface can be shown, and if the output parameters do not correspond to the test data, the method in the to-be-tested component can be shown to have a bug. For example, COM components (i.e., COM components) are used as components to be tested, and the COM components can provide services for applications, operating systems, and other components developed in different languages and different platforms. Interfaces are functions implemented by COM components that are provided for use by a client, and applications interface with COM components through the interfaces. And pre-configuring an HTML page and a corresponding JavaScript file, wherein interface functions aiming at any interface of the COM component are configured in the JavaScript file, and the interface functions correspond to the interface names. In the application, the configured JavaScript script file may be run by using a browser of the JavaScript script file under the Windows operating system, and the COM component may be tested only by installing and registering the COM component under the environment of the Windows operating system.
After the COM component is installed, acquiring the interface of the interface to be tested in the COM component as a signature interface, wherein the interface name corresponding to the signature interface can be an interface ID, namely, the interface name is 01, a preconfigured HTML page (demo page) is opened, a configured JavaScript script is used, an input box is generated on the HTML page aiming at the 01 interface, the name of the input box can be named as 01, a tester inputs corresponding test data X in the 01 input box, the change of the content of the input box can cause the change of a corresponding variable in the JavaScript script, the JavaScript script can acquire the test data X, and because the test data X is the data of the 01 input box, the test data X is associated with 01 in the JavaScript, a 01 interface is used, an interface function corresponding to the 01 interface in the JavaScript is a signature function, and the signature function is called to send the test data X associated with the 01 interface to a COM component; after receiving the test data X, the COM component authenticates the standard signature certificate by using the test data X, that is, tests the COM component, and feeds back a corresponding test result, and the process of obtaining the test result is executed in the COM component and needs to be implemented based on the test data X.
In practical application, taking a COM component for realizing the application of the hardware Ukey digital certificate as an example, a signature interface of the COM component is tested, the signature interface is used for realizing the signature of data by using the digital certificate in the hardware Ukey, and the test process is as follows:
the method comprises the steps that a COM component is installed in a terminal device, a Ukey is accessed into the terminal device through a USB interface, a demo page runs in a browser of the terminal device, a signature interface to be tested is obtained, a corresponding data input box is generated, a user inputs test data in the data input box, an interface function of the signature interface is called to send the test data to the COM component, the COM component reads a Ukey digital signature certificate, signature is executed to generate a result, the result is returned, namely the result (namely interface parameter) is returned to the demo page through the signature interface, a pop-up box corresponding to the signature interface is created on the demo page, the result is displayed in the corresponding pop-up box, and the user determines a test result according to the returned result.
The same interface in the component has different processing performances for different participants, for example, whether input content is input, different character types of the input content, different lengths, special character containing conditions and the like, and the interface needs to return a correct result according to expected processing. When it is necessary to test whether the interface function is normal under these different input parameters in a covering manner, only different types of test data need to be input into the input box of step S102, and the code does not need to be changed in the test process.
In the embodiment of the application, after the installation of the to-be-tested component is completed, interface names of N to-be-tested interfaces in the to-be-tested component are obtained, JavaScript files corresponding to the interface names are called, namely, corresponding input frames can be created on the preset HTML page, test data input by a user in each input frame are obtained, interface functions corresponding to the interface names of the to-be-tested interfaces are called according to the interface names, the test data input in the input frames of the corresponding JavaScript files are sent to the to-be-tested component, whether the to-be-tested component is qualified or not is judged according to the similarity between the corresponding target output parameters of the interface output corresponding to the interface names fed back by the to-be-tested component, the testing of the component is realized, the dependence on an operating system is avoided, the corresponding input frames can be directly generated based on the JavaScript files of the HTML page, and the requirement on assembly language is low, the universality is higher, and the test efficiency is improved.
Referring to fig. 2, which is a schematic flow chart of a JavaScript-based component testing method according to a second embodiment of the present application, as shown in fig. 2, the component testing method may include the following steps:
step S201, sending a creating instruction to the component to be tested, and obtaining a creating result fed back by the component to be tested.
The terminal device can send corresponding data to the installed component, detect feedback of the component, and judge whether the component is installed or not according to a feedback result. For example, the Ajax technology is used for sending a request to any component to create a corresponding control, and if the feedback result is that the creation is successful, the component installation is completed.
Step S202, if the creating result is successful, the installation of the components to be tested is determined to be completed, and interface functions of N interfaces to be tested in the components to be tested are collected.
In the application, after the to-be-tested component is installed, the header file of the to-be-tested component is obtained, and the header file is analyzed, so that the interface function contained in the header file is determined, and the interface corresponding to the interface function is the to-be-tested interface.
In one embodiment, the interface that can be implemented by the corresponding component can be viewed using an Object Viewer (Object Viewer), and the corresponding interface function can be determined.
Optionally, if it is detected that the installation of the to-be-tested component is completed, acquiring interface functions of N to-be-tested interfaces in the to-be-tested component includes:
if the installation of the component to be tested is detected to be finished, acquiring all interface functions in the component to be tested;
and taking the interface corresponding to the interface function selected by the user as the interface to be tested, and determining N interfaces to be tested.
In order to improve the testing efficiency, after all the interface functions in the to-be-tested component are acquired, an interface function selection item can be output so that a user can select the interface function to be tested.
In an embodiment, a user may preset a testing white list, that is, the interface functions in the white list may not need to be tested, so that the interface to be tested may be screened from all the interface functions by using the white list as a screening condition.
Step S203, using each interface function as the interface name of the corresponding interface to be tested.
In the application, the interface function is used as the interface name corresponding to the interface to be tested, so that the complexity of the program can be reduced, the interface name or the interface function does not need to correspond to other information, and the interface function of the interface to be tested can be directly called when the interface function corresponding to the interface name of the interface to be tested is called subsequently.
Step S204, calling the JavaScript files corresponding to the interface names, creating corresponding input boxes on a preset HTML page, and acquiring the test data input by the user in each input box.
Step S205, calling an interface function corresponding to the interface name of each interface to be tested, sending test data input by the user in the input box of the corresponding JavaScript script file to the component to be tested, and obtaining an interface parameter corresponding to each interface name fed back by the component to be tested.
Step S206, detecting the similarity between the interface output participation corresponding to each interface name and the target output participation corresponding to the interface name, and if detecting that the interface output participation with the similarity lower than the preset value exists, determining that the test result of the component to be tested is unqualified.
The contents of steps S204 to S206 are the same as those of steps S102 to S104, and reference may be made to the description of steps S102 to S104, which is not repeated herein.
Optionally, before invoking the JavaScript script file corresponding to each interface name and creating the corresponding input box on the preset HTML page, the method further includes:
acquiring a JavaScript template;
and combining the interface names with a JavaScript template to obtain JavaScript files corresponding to the interface names.
The method comprises the steps of providing a JavaScript template, wherein the JavaScript template can realize the functions of creating an input frame and an output frame, obtaining the input content of the input frame and displaying the output frame, only an interface function of an interface to be tested is lacked in the JavaScript template, and writing the interface function into the JavaScript template to form a JavaScript file corresponding to the interface function.
Optionally, calling an interface function corresponding to the interface name of each interface to be tested, and sending test data input by a user in an input box of a corresponding JavaScript script file to the component to be tested includes:
writing the test data corresponding to each interface name into a corresponding JavaScript script file to obtain a correspondingly written JavaScript script file;
and calling an interface function in each written JavaScript file, and sending test data in the correspondingly written JavaScript file to the component to be tested.
After the input box is created by the JavaScript file, the user inputs the test data, the test data is written into the JavaScript file to obtain the written JavaScript file, namely the test script file, and the test of the component to be tested can be realized by running the test script file.
Because the interface name in each test script file is the interface function corresponding to the test script file, the process of running the test script file is to call the interface function in the test script file and send the test data in the test file to the component to be tested.
After the testing component is detected to be installed, the embodiment of the application acquires the interface functions of N interfaces to be tested in the testing component, takes each interface function as the interface name corresponding to the interface to be tested, calls the JavaScript file corresponding to each interface name, namely, creates a corresponding input frame on the preset HTML page, acquires the test data input by a user in each input frame, calls the interface function corresponding to the interface name of the interface to be tested according to each interface name, sends the test data input in the input frame of the corresponding JavaScript file to the testing component, judges whether the testing component is qualified according to the similarity between the target output parameters participated in by the interface corresponding to each interface name fed back by the testing component, realizes the testing of the component, and effectively reduces the complexity of a program by taking the interface function as the interface name, the test efficiency is improved.
Corresponding to the component testing method in the foregoing embodiment, fig. 3 shows a structural block diagram of a JavaScript-based component testing apparatus provided in the third embodiment of the present application, where the component testing apparatus is applied to a terminal device, the terminal device may be a computer device running any operating system, and a browser supporting assembly using an HTML language exists in the operating system. For convenience of explanation, only portions related to the embodiments of the present application are shown.
Referring to fig. 3, the component testing apparatus includes:
the interface name obtaining module 31 is configured to obtain interface names of N to-be-tested interfaces in the to-be-tested component after the to-be-tested component is installed, where N is a positive integer greater than zero;
the test data acquisition module 32 is configured to call JavaScript script files corresponding to the interface names, create corresponding input boxes on a preset HTML page, and acquire test data input by a user in each input box;
the sending and receiving module 33 is configured to call an interface function corresponding to an interface name of each interface to be tested, send test data input by a user in an input box of a corresponding JavaScript script file to the component to be tested, and obtain an interface output parameter corresponding to each interface name fed back by the component to be tested;
and the component testing module 34 is configured to detect similarity between the interface output participation corresponding to each interface name and the target output participation corresponding to the interface name, and determine that the test result of the component to be tested is unqualified if the interface output participation with the similarity lower than a preset value is detected. Optionally, the device for testing an assembly further includes:
the pop-up box module is used for creating pop-up boxes corresponding to the interface names on a preset HTML page after the interface output parameters corresponding to the interface names fed back by the component to be tested are acquired;
and the interface participation display module is used for displaying the interface participation corresponding to each interface name in the corresponding pop-up box.
Optionally, the device for testing an assembly further includes:
the creation result acquisition module is used for sending a creation instruction to the to-be-tested component and acquiring a creation result fed back by the to-be-tested component after the to-be-tested component is installed and before the interface names of N to-be-tested interfaces in the to-be-tested component are acquired;
the installation result determining module is used for determining that the installation of the component to be tested is finished if the creation result is successful;
the interface name obtaining module 31 includes:
the interface function acquisition unit is used for acquiring interface functions of N interfaces to be tested in the components to be tested;
and the interface name determining unit is used for taking each interface function as the interface name of the corresponding interface to be tested.
Optionally, the interface function acquiring unit includes:
the first subunit is used for acquiring all interface functions in the component to be tested;
and the second subunit is used for taking the interface corresponding to the interface function selected by the user as the interface to be tested, and determining N interfaces to be tested and the corresponding interface functions.
Optionally, the device for testing an assembly further includes:
the script template acquisition module is used for acquiring a JavaScript template before calling the JavaScript files corresponding to the interface names and creating corresponding input frames on a preset HTML page;
and the script file determining module is used for combining the interface names with the JavaScript template to obtain the JavaScript files corresponding to the interface names.
Optionally, the sending and receiving module 33 includes:
the test data writing unit is used for writing the test data corresponding to each interface name into the corresponding JavaScript file to obtain the correspondingly written JavaScript file;
and the test data sending unit is used for calling an interface function in each written JavaScript file and sending the test data in the corresponding written JavaScript file to the component to be tested.
Optionally, the device for testing an assembly further includes:
the character type extraction module is used for extracting the character type of the test data input in each input box before the test data input in each input box by the user is obtained;
the type matching module is used for matching the character types corresponding to the input boxes with the entry types, if the character types are matched, the test data accord with entry conditions, and if the character types do not accord with the entry conditions, the test data do not accord with the entry conditions;
the test data acquisition module 32 includes:
the test data acquisition unit is used for acquiring test data in an input frame if the test data input in the input frame is detected to accord with the entry condition;
and the error prompt output unit is used for outputting an error prompt in an input box if the test data input in the input box is detected not to accord with the entry condition.
It should be noted that, because the contents of information interaction, execution process, and the like between the modules are based on the same concept as that of the embodiment of the method of the present application, specific functions and technical effects thereof may be specifically referred to a part of the embodiment of the method, and details are not described here.
Fig. 4 is a schematic structural diagram of a terminal device according to a fourth embodiment of the present application. As shown in fig. 4, the terminal device 4 of this embodiment includes: at least one processor 40 (only one shown in fig. 4), a memory 41, and a computer program 42 stored in the memory 41 and executable on the at least one processor 40, the steps of any of the various component testing method embodiments described above being implemented when the computer program 42 is executed by the processor 40.
The terminal device 4 may include, but is not limited to, a processor 40, a memory 41. Those skilled in the art will appreciate that fig. 4 is merely an example of the terminal device 4, and does not constitute a limitation of the terminal device 4, and may include more or less components than those shown, or combine some components, or different components, such as an input-output device, a network access device, and the like.
The Processor 40 may be a CPU, and the Processor 40 may also be other general purpose processors, Digital Signal Processors (DSPs), Application Specific Integrated Circuits (ASICs), Field-Programmable Gate arrays (FPGAs) or other Programmable logic devices, discrete Gate or transistor logic devices, discrete hardware components, etc. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like.
The memory 41 may in some embodiments be an internal storage unit of the terminal device 4, such as a hard disk or a memory of the terminal device 4. The memory 41 may be an external storage device of the terminal device 4 in other embodiments, such as a plug-in hard disk provided on the terminal device 4, a Smart Media Card (SMC), a Secure Digital (SD) Card, a Flash memory Card (Flash Card), and the like. Further, the memory 41 may also include both an internal storage unit of the terminal device 4 and an external storage device. The memory 41 is used for storing an operating system, an application program, a BootLoader (BootLoader), data, and other programs, such as program codes of a computer program. The memory 41 may also be used to temporarily store data that has been output or is to be output.
It will be apparent to those skilled in the art that, for convenience and brevity of description, only the above-mentioned division of the functional units and modules is illustrated, and in practical applications, the above-mentioned function distribution may be performed by different functional units and modules according to needs, that is, the internal structure of the apparatus is divided into different functional units or modules, so as to perform all or part of the functions described above. Each functional unit and module in the embodiments may be integrated in one processing unit, or each unit may exist alone physically, or two or more units are integrated in one unit, and the integrated unit may be implemented in a form of hardware, or in a form of software functional unit. In addition, specific names of the functional units and modules are only used for distinguishing one functional unit from another, and are not used for limiting the protection scope of the present application. The specific working processes of the units and modules in the above-mentioned apparatus may refer to the corresponding processes in the foregoing method embodiments, and are not described herein again. 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, all or part of the flow of the method of the embodiments described above can be implemented by a computer program, which can be stored in a computer readable storage medium and can implement the steps of the embodiments of the methods described above when the computer program is executed by a processor. Wherein the computer program comprises computer program code, which may be in the form of source code, object code, an executable file or some intermediate form, etc. The computer readable medium may include at least: any entity or device capable of carrying computer program code, recording medium, computer Memory, Read-Only Memory (ROM), Random Access Memory (RAM), electrical carrier wave signals, telecommunications signals, and software distribution media. Such as a usb-disk, a removable hard disk, a magnetic or optical disk, etc. In certain jurisdictions, computer-readable media may not be an electrical carrier signal or a telecommunications signal in accordance with legislative and patent practice.
When the computer program product runs on the terminal device, the steps in the method embodiments can be implemented when the terminal device executes the computer program product.
In the above embodiments, the descriptions of the respective embodiments have respective emphasis, and reference may be made to the related descriptions of other embodiments for parts that are not described or illustrated in a certain embodiment.
Those of ordinary skill in the art will appreciate that the various illustrative elements and algorithm steps described in connection with the embodiments disclosed herein may be implemented as electronic hardware or combinations of computer software and electronic hardware. Whether such functionality is implemented as hardware or software depends upon the particular application and design constraints imposed on the implementation. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present application.
In the embodiments provided in the present application, it should be understood that the disclosed apparatus/terminal device and method may be implemented in other ways. For example, the above-described embodiments of the apparatus/terminal device are merely illustrative, and for example, a module or a unit may be divided into only one logical function, and may be implemented in other ways, for example, a plurality of 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, devices or units, and may be in an electrical, mechanical or other form.
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 network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of the embodiment.
The above embodiments are only used to illustrate the technical solutions of the present application, and not to limit the same; although the present application has been described in detail with reference to the foregoing embodiments, it should be understood by those of ordinary skill in the art that: the technical solutions described in the foregoing embodiments may still be modified, or some technical features may be equivalently replaced; such modifications and substitutions do not substantially depart from the spirit and scope of the embodiments of the present application and are intended to be included within the scope of the present application.

Claims (10)

1. A JavaScript-based component testing method is characterized by comprising the following steps:
after the to-be-tested component is installed, acquiring interface names of N to-be-tested interfaces in the to-be-tested component, wherein N is a positive integer greater than zero;
calling JavaScript files corresponding to the interface names, creating corresponding input frames on the preset HTML page, and acquiring test data input by a user in each input frame;
calling an interface function corresponding to the interface name of each interface to be tested, sending test data input by the user in an input frame of a corresponding JavaScript file to the components to be tested, and acquiring interface parameters corresponding to the interface names fed back by the components to be tested;
and detecting the similarity between the interface output participation corresponding to each interface name and the target output participation corresponding to the interface name, and if the interface output participation with the similarity lower than a preset value is detected, determining that the test result of the to-be-tested component is unqualified.
2. The component testing method according to claim 1, after obtaining the interface parameters corresponding to the interface names fed back by the components to be tested, further comprising:
creating pop-up boxes corresponding to the interface names on the preset HTML page;
and displaying the interface appearance reference corresponding to each interface name in a corresponding pop-up box.
3. The component testing method according to claim 1, wherein before obtaining the interface names of N to-be-tested interfaces in the to-be-tested component after the to-be-tested component is installed, the method further comprises:
sending a creating instruction to a to-be-tested assembly to obtain a creating result fed back by the to-be-tested assembly;
if the creation result is successful, determining that the installation of the component to be tested is completed;
after the to-be-tested component is installed, acquiring the interface names of the N to-be-tested interfaces in the to-be-tested component includes:
acquiring interface functions of N interfaces to be tested in the components to be tested;
and taking each interface function as the interface name of the corresponding interface to be tested.
4. The component testing method of claim 3, wherein said collecting interface functions of N dut interfaces of the dut comprises:
acquiring all interface functions in the component to be tested;
and taking the interface corresponding to the interface function selected by the user as the interface to be tested, and determining N interfaces to be tested and the corresponding interface functions.
5. The component testing method according to claim 3, before the calling the JavaScript script file corresponding to each interface name and creating a corresponding input box on the preset HTML page, further comprising:
acquiring a JavaScript template;
and combining the interface names with the JavaScript script template to obtain JavaScript script files corresponding to the interface names.
6. The component testing method according to claim 5, wherein the calling an interface function corresponding to an interface name of each interface to be tested and sending the test data input by the user in the input box of the corresponding JavaScript file to the component to be tested comprises:
writing the test data corresponding to each interface name into a corresponding JavaScript file to obtain a correspondingly written JavaScript file;
and calling an interface function in each written JavaScript file, and sending test data in the correspondingly written JavaScript file to the component to be tested.
7. The component testing method according to any one of claims 1 to 6, further comprising, before the acquiring the test data input by the user in each input box:
extracting the character type of the test data input in each input box;
matching the character type corresponding to each input box with the entry type, wherein if the character type is matched with the entry type, the test data accords with the entry condition, and if the character type is not matched with the entry type, the test data does not accord with the entry condition;
the acquiring the test data input by the user in each input box comprises:
if the test data input in an input box is detected to accord with the entry condition, the test data in the input box is obtained;
and if the test data input in an input box is detected not to accord with the entry condition, outputting an error prompt in the input box.
8. A JavaScript-based component testing apparatus, comprising:
the interface name acquisition module is used for acquiring interface names of N to-be-tested interfaces in the to-be-tested components after the to-be-tested components are installed, wherein N is a positive integer greater than zero;
the test data acquisition module is used for calling JavaScript files corresponding to the interface names, creating corresponding input frames on the preset HTML page and acquiring test data input by a user in each input frame;
the sending and receiving module is used for calling an interface function corresponding to the interface name of each interface to be tested, sending the test data input by the user in the input box of the corresponding JavaScript file to the components to be tested, and acquiring the interface output parameters corresponding to the interface names fed back by the components to be tested;
and the component testing module is used for detecting the similarity between the interface output participation corresponding to each interface name and the target output participation corresponding to the interface name, and if the interface output participation with the similarity lower than a preset value is detected, determining that the testing result of the component to be tested is unqualified.
9. A terminal device, characterized in that the terminal device comprises a processor, a memory and a computer program stored in the memory and executable on the processor, the processor implementing the component testing method according to any one of claims 1 to 7 when executing the computer program.
10. A computer-readable storage medium, in which a computer program is stored which, when being executed by a processor, carries out the component testing method according to any one of claims 1 to 7.
CN202210066961.7A 2022-01-20 2022-01-20 JavaScript-based component testing method and device, terminal equipment and medium Pending CN114428736A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210066961.7A CN114428736A (en) 2022-01-20 2022-01-20 JavaScript-based component testing method and device, terminal equipment and medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210066961.7A CN114428736A (en) 2022-01-20 2022-01-20 JavaScript-based component testing method and device, terminal equipment and medium

Publications (1)

Publication Number Publication Date
CN114428736A true CN114428736A (en) 2022-05-03

Family

ID=81314127

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210066961.7A Pending CN114428736A (en) 2022-01-20 2022-01-20 JavaScript-based component testing method and device, terminal equipment and medium

Country Status (1)

Country Link
CN (1) CN114428736A (en)

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104050517A (en) * 2014-06-27 2014-09-17 哈尔滨工业大学 Photovoltaic power generation forecasting method based on GRNN
CN108899048A (en) * 2018-05-10 2018-11-27 广东省智能制造研究所 A kind of voice data classification method based on signal Time-frequency Decomposition

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104050517A (en) * 2014-06-27 2014-09-17 哈尔滨工业大学 Photovoltaic power generation forecasting method based on GRNN
CN108899048A (en) * 2018-05-10 2018-11-27 广东省智能制造研究所 A kind of voice data classification method based on signal Time-frequency Decomposition

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
DOUBLELI: "在javascript中使用com组件的方法", pages 1 - 3, Retrieved from the Internet <URL:https://www.cnblogs.com/lidabo/p/3256211.html> *
廖先生: "使用javascript调用com组件", pages 1, Retrieved from the Internet <URL:https://www.cnblogs.com/liaocheng/p/4243963.html> *

Similar Documents

Publication Publication Date Title
CN109739478B (en) Front-end project automatic construction method and device, storage medium and electronic equipment
US20180011780A1 (en) Web application test script generation to test software functionality
US8621613B1 (en) Detecting malware in content items
CN107145784B (en) Vulnerability scanning method and device and computer readable medium
CN111597110B (en) Page test method and device, electronic equipment and storage medium
CN110955409B (en) Method and device for creating resources on cloud platform
CN109684008B (en) Card rendering method, device, terminal and computer readable storage medium
US20180227326A1 (en) Detecting sensitive data sent from client device to third-party
US10129278B2 (en) Detecting malware in content items
CN111324510B (en) Log processing method and device and electronic equipment
CN110908915A (en) Test coverage rate display method and device and computer system
CN109240923B (en) Interface test script generation method and computer readable storage medium
CN111209210A (en) Method and device for generating test case, electronic equipment and storage medium
CN113434400A (en) Test case execution method and device, computer equipment and storage medium
CN113535577A (en) Application testing method and device based on knowledge graph, electronic equipment and medium
CN111639028B (en) Method, device, engine and storage medium for testing account checking rule script
CN113362173A (en) Anti-duplication mechanism verification method, anti-duplication mechanism verification system, electronic equipment and storage medium
CN103186465B (en) The browser compatibility method of testing of web user interface and system
CN116756016A (en) Multi-browser testing method, device, equipment, medium and program product
CN116680291A (en) Data checking method and device, electronic equipment and storage medium
CN114428736A (en) JavaScript-based component testing method and device, terminal equipment and medium
CN116361793A (en) Code detection method, device, electronic equipment and storage medium
CN111400623B (en) Method and device for searching information
CN115203178A (en) Data quality inspection method and device, electronic equipment and storage medium
US11030087B2 (en) Systems and methods for automated invocation of accessibility validations in accessibility scripts

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