CN109634844A - JS code test method, device and electronic equipment - Google Patents

JS code test method, device and electronic equipment Download PDF

Info

Publication number
CN109634844A
CN109634844A CN201811317347.3A CN201811317347A CN109634844A CN 109634844 A CN109634844 A CN 109634844A CN 201811317347 A CN201811317347 A CN 201811317347A CN 109634844 A CN109634844 A CN 109634844A
Authority
CN
China
Prior art keywords
function
code
compatibility
tested
information
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
CN201811317347.3A
Other languages
Chinese (zh)
Other versions
CN109634844B (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.)
3600 Technology Group Co ltd
Original Assignee
Beijing Qihoo Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Qihoo Technology Co Ltd filed Critical Beijing Qihoo Technology Co Ltd
Priority to CN201811317347.3A priority Critical patent/CN109634844B/en
Publication of CN109634844A publication Critical patent/CN109634844A/en
Application granted granted Critical
Publication of CN109634844B publication Critical patent/CN109634844B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

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

Abstract

The present invention relates to Internet technical fields, in particular to a kind of JS code test method, device and electronic equipment.The JS code test method, comprising: obtain JS code to be tested, and first configuration file corresponding with the JS code to be tested;Compatibility of the JS code to be tested relative to preset browsing device set is tested simultaneously based on first configuration file, obtains the code for code compatibility test result of the JS code to be tested.When needing to test JS code to be tested, only compatibility of the JS code to be tested relative to preset browsing device set need to directly can be tested simultaneously based on the first configuration file, to obtain the code for code compatibility test result of JS code to be tested, therefore, in compared to the prior art, each browser is tested respectively by way of manual testing for the scheme of the compatibility of JS code to be tested, testing efficiency, which has, largely to be improved.

Description

JS code test method, device and electronic equipment
Technical field
The present invention relates to Internet technical fields, set in particular to a kind of JS code test method, device and electronics It is standby.
Background technique
JS, that is, Javascript is a kind of programming language being born to adapt to the needs of dynamic web page, nowadays More and more widely applied in the production of Intemet webpage, therefore, the exploitation amount and test volume of JS code are also gradually increasing Greatly.But in the prior art, the testing efficiency of JS code is lower, for example, in test preset browsing device set to JS code to be tested Compatibility when, each preset browsing device can only be tested respectively by way of manual testing to the compatibility of JS code to be tested Property, therefore, testing efficiency is extremely low.
Summary of the invention
In view of this, the embodiment of the present invention is designed to provide a kind of JS code test method, device and electronic equipment, To be effectively improved the above problem.
The JS code test method provided in the embodiment of the present invention, comprising:
Obtain JS code to be tested, and first configuration file corresponding with the JS code to be tested;
The JS code to be tested is tested relative to the simultaneous of preset browsing device set simultaneously based on first configuration file Capacitive obtains the code for code compatibility test result of the JS code to be tested.
It further, include at least one target JS function in the JS code to be tested, in first configuration file Including at least one for characterizing the JS function function compatibility information incompatible relative to the preset browsing device set;
It is described that the JS code to be tested is tested relative to preset browsing device set simultaneously based on first configuration file Compatibility, obtain the code for code compatibility test result of the JS code to be tested, comprising:
Based on at least one function compatibility information, each target JS in the JS code to be tested is determined respectively Function compatibility test result of the function relative to the preset browsing device set;
According to the function compatibility test of all target JS functions in the JS code to be tested as a result, determine it is described to Test the code for code compatibility test result of JS code;
Wherein, if all target JS functions in the JS code to be tested are simultaneous both with respect to the preset browsing device set Hold, is then determined as being compatible with by the code for code compatibility test result of the JS code to be tested, otherwise, by the JS code to be tested Code for code compatibility test result be determined as it is incompatible.
Further, described to be based on at least one function compatibility information, the JS code to be tested is determined respectively In function compatibility test result of each target JS function relative to the preset browsing device set, comprising:
For each target JS function in the JS code to be tested, judge in first configuration file respectively whether In the presence of function compatibility information corresponding with the target JS function;
If there is function compatibility information corresponding with the target JS function in first configuration file, according to institute It states function compatibility information and determines the function compatibility test of the target JS function as a result, otherwise, by the target JS The function compatibility test result of function is determined as being compatible with.
Further, the function compatibility information includes in function label and function corresponding with the function label Hold, each corresponding JS function of the function label, the function content is for characterizing JS letter corresponding with the function label Compatibility of the number relative to the browser in the preset browsing device set;
It is described according to the function compatibility information determine the target JS function the function compatibility test as a result, Include:
It is associated with situation based on presupposed information, determines the association type of the function compatibility information, the association type packet The first association type and the second association type are included, first association type is not deposited for being characterized in first configuration file In the function compatibility information with the function compatible information function association, second association type is for being characterized in described the There is the function compatibility information with the function compatible information function association in one configuration file;
If the association type of the function compatible information is first association type, believe according to the function is compatible Breath, determines the function compatibility test result of the target JS function;
If the association type of the function compatible information is second association type, according to the function compatible information Function content and function content with the function compatibility information of the function compatible information function association, determine the mesh Mark the function compatibility test result of JS function.
Further, the function content according to the function compatible information and with the function compatible information function The function content of associated function compatibility information determines the function compatibility test of the target JS function as a result, packet It includes:
According to the function content of the function compatible information, obtain simultaneous to JS function corresponding with the function compatible information The browser of appearance, as the first browser;
By the function compatibility information with the function compatible information function association, as correlation function compatibility information, And according to the function content of the correlation function compatibility information, obtain to JS letter corresponding with the correlation function compatible information The compatible browser of number, as the second browser;
Judge whether the set of first browser and second browser is identical as the preset browsing device set;
If the set of first browser and second browser is identical as the preset browsing device set, it is determined that The function compatibility test result of the target JS function is compatibility, otherwise, it determines the letter of the target JS function Number compatibility test result is incompatible.
Further, when the function compatibility test result of the target JS function is incompatible, the basis The function compatibility information determines the function compatibility test result of the target JS function, further includes:
Based on the compatible implementations of preset browsing device, the incompatible type of the function compatibility information is determined, it is described not simultaneous Holding type includes the first incompatible type and the second incompatible type, and the first incompatible type is simultaneous for characterizing the function The incompatible situation of capacitive information is completely incompatible, and the second incompatible type is for characterizing the function compatibility information Incompatible situation be not exclusively compatible;
If the incompatible type of the function compatibility information is the described first incompatible type, by the target JS letter Several function compatibility results are determined as completely incompatible;
If the incompatible type of the function compatibility information is the described second incompatible type, the target JS function Function compatibility results be determined as incomplete compatibility.
Further, the JS code test method, further includes:
Obtain corresponding second configuration file of the JS code to be tested;
The syntax gauge of the JS code to be tested is tested based on second configuration file, obtains the JS to be tested The code syntax normalization test result of code.
It further, include at least one in second configuration file for characterizing the grammer that JS code to be tested has The syntax gauge information of Problem;
The syntax gauge that the JS code to be tested is tested based on second configuration file is obtained described to be measured Try the code syntax normalization test result of JS code, comprising:
For syntax gauge information described in every, judge to whether there is and institute's grammar rule in the JS code to be tested The corresponding grammer setting of plasticity information;
If having grammer corresponding with the syntax gauge information in the JS code to be tested to be arranged, by institute's predicate Method is provided as grammer lack of standardization;
If there are the grammers lack of standardization in the JS code, it is determined that the code syntax specification of the JS code to be tested Property test result be it is lack of standardization, otherwise, it determines the code syntax normalization test result of the JS code to be tested be specification.
Further, it is arranged if there is grammer corresponding with the syntax gauge information in the JS code to be tested, The grammer is then provided as grammer lack of standardization, comprising:
Based on default syntax gauge implementations, the type lack of standardization of the syntax gauge information is determined, it is described lack of standardization Type includes the first type lack of standardization and the second type lack of standardization, and first type lack of standardization is for characterizing the syntax gauge Property information grammer Problem be it is completely lack of standardization, second type lack of standardization is for characterizing syntax gauge letter The Problem of breath is not exclusively to standardize;
If the type lack of standardization of the syntax gauge information is the described first type lack of standardization, the grammer is arranged As complete grammer lack of standardization;
If the type lack of standardization of the syntax gauge information is the described second type lack of standardization, the grammer is arranged As complete incomplete normative grammar.
JS code tester device provided in an embodiment of the present invention, comprising:
First configuration file obtains module, for obtaining JS code to be tested, and it is corresponding with the JS code to be tested The first configuration file;
First test result obtains module, for testing the JS code to be tested simultaneously based on first configuration file Relative to the compatibility of preset browsing device set, the code for code compatibility test result of the JS code to be tested is obtained.
Further include at least one target JS function in the JS code to be tested, is wrapped in first configuration file At least one is included for characterizing the JS function function compatibility information incompatible relative to the preset browsing device set;
First test result obtains module, is specifically used for:
Based on at least one function compatibility information, each target JS in the JS code to be tested is determined respectively Function compatibility test result of the function relative to the preset browsing device set;
According to the function compatibility test of all target JS functions in the JS code to be tested as a result, determine it is described to Test the code for code compatibility test result of JS code;
Wherein, if all target JS functions in the JS code to be tested are simultaneous both with respect to the preset browsing device set Hold, is then determined as being compatible with by the code for code compatibility test result of the JS code to be tested, otherwise, by the JS code to be tested Code for code compatibility test result be determined as it is incompatible.
Further first test result obtains module, and is specifically used for:
For each target JS function in the JS code to be tested, judge in first configuration file respectively whether In the presence of function compatibility information corresponding with the target JS function;
If there is function compatibility information corresponding with the target JS function in first configuration file, according to institute It states function compatibility information and determines the function compatibility test of the target JS function as a result, otherwise, by the target JS The function compatibility test result of function is determined as being compatible with.
Further the function compatibility information includes function label and function content corresponding with the function label, Each corresponding JS function of the function label, the function content is for characterizing JS function phase corresponding with the function label For the compatibility of the browser in the preset browsing device set;
First test result obtains module, and is specifically used for:
It is associated with situation based on presupposed information, determines the association type of the function compatibility information, the association type packet The first association type and the second association type are included, first association type is not deposited for being characterized in first configuration file In the function compatibility information with the function compatible information function association, second association type is for being characterized in described the There is the function compatibility information with the function compatible information function association in one configuration file;
If the association type of the function compatible information is first association type, believe according to the function is compatible Breath, determines the function compatibility test result of the target JS function;
If the association type of the function compatible information is second association type, according to the function compatible information Function content and function content with the function compatibility information of the function compatible information function association, determine the mesh Mark the function compatibility test result of JS function.
Further first test result obtains module, and is specifically used for:
According to the function content of the function compatible information, obtain simultaneous to JS function corresponding with the function compatible information The browser of appearance, as the first browser;
By the function compatibility information with the function compatible information function association, as correlation function compatibility information, And according to the function content of the correlation function compatibility information, obtain to JS letter corresponding with the correlation function compatible information The compatible browser of number, as the second browser;
Judge whether the set of first browser and second browser is identical as the preset browsing device set;
If the set of first browser and second browser is identical as the preset browsing device set, it is determined that The function compatibility test result of the target JS function is compatibility, otherwise, it determines the letter of the target JS function Number compatibility test result is incompatible.
Further when the function compatibility test result of the target JS function is incompatible, described first is surveyed Test result obtains module, also particularly useful for:
Based on the compatible implementations of preset browsing device, the incompatible type of the function compatibility information is determined, it is described not simultaneous Holding type includes the first incompatible type and the second incompatible type, and the first incompatible type is simultaneous for characterizing the function The incompatible situation of capacitive information is completely incompatible, and the second incompatible type is for characterizing the function compatibility information Incompatible situation be not exclusively compatible;
If the incompatible type of the function compatibility information is the described first incompatible type, by the target JS letter Several function compatibility results are determined as completely incompatible;
If the incompatible type of the function compatibility information is the described second incompatible type, the target JS function Function compatibility results be determined as incomplete compatibility.
The further JS code tester device, further includes:
Second configuration file obtains module, for obtaining corresponding second configuration file of the JS code to be tested;
Second test result obtains module, for testing the JS code to be tested based on second configuration file Syntax gauge obtains the code syntax normalization test result of the JS code to be tested.
It include further at least one in second configuration file for characterizing the grammer that JS code to be tested has The syntax gauge information of Problem;
Second test result obtains module, is specifically used for:
For syntax gauge information described in every, judge to whether there is and institute's grammar rule in the JS code to be tested The corresponding grammer setting of plasticity information;
If having grammer corresponding with the syntax gauge information in the JS code to be tested to be arranged, by institute's predicate Method is provided as grammer lack of standardization;
If there are the grammers lack of standardization in the JS code, it is determined that the code syntax specification of the JS code to be tested Property test result be it is lack of standardization, otherwise, it determines the code syntax normalization test result of the JS code to be tested be specification.
Further second test result obtains module, and is specifically used for: based on default syntax gauge implementations, really The type lack of standardization of the fixed syntax gauge information, the type lack of standardization include that the first type lack of standardization and second are lack of standardization Type, the grammer Problem that first type lack of standardization is used to characterize the syntax gauge information is not advise completely Model, the Problem that second type lack of standardization is used to characterize the syntax gauge information is not exclusively to standardize;
If the type lack of standardization of the syntax gauge information is the described first type lack of standardization, the grammer is arranged As complete grammer lack of standardization;
If the type lack of standardization of the syntax gauge information is the described second type lack of standardization, the grammer is arranged As complete incomplete normative grammar.
Electronic equipment provided in an embodiment of the present invention, including processor, memory and above-mentioned JS code tester device, it is described JS code tester device includes one or more software function modules for being stored in the memory and being executed by the processor.
The embodiment of the invention also provides a kind of computer readable storage mediums, are stored thereon with computer program, described Computer program is performed, and above-mentioned JS code test method may be implemented.
JS code test method, device and electronic equipment provided in an embodiment of the present invention can obtain JS code to be tested, And first configuration file corresponding with the JS code to be tested, and tested simultaneously based on first configuration file it is described to Compatibility of the JS code relative to preset browsing device set is tested, the code for code compatibility for obtaining the JS code to be tested tests knot Fruit.In this way, need to directly can only be surveyed simultaneously based on the first configuration file when needing to test JS code to be tested Compatibility of the JS code to be tested relative to preset browsing device set is tried, so that the code for obtaining JS code to be tested is simultaneous Capacitive test result, therefore, compared to the prior art in, test each browser respectively by way of manual testing to be measured For the scheme of compatibility for trying JS code, testing efficiency, which has, largely to be improved.
The above description is only an overview of the technical scheme of the present invention, in order to better understand the technical means of the present invention, And it can be implemented in accordance with the contents of the specification, and in order to allow above and other objects of the present invention, feature and advantage can It is clearer and more comprehensible, the followings are specific embodiments of the present invention.
Detailed description of the invention
In order to illustrate the technical solution of the embodiments of the present invention more clearly, below will be to needed in the embodiment attached Figure is briefly described, it should be understood that the following drawings illustrates only some embodiments of the disclosure, therefore is not construed as pair The restriction of range for those of ordinary skill in the art without creative efforts, can also be according to this A little attached drawings obtain other relevant attached drawings.
Fig. 1 is the schematic block diagram of electronic equipment provided in an embodiment of the present invention.
Fig. 2 is a kind of flow diagram of JS code test method provided in an embodiment of the present invention.
Fig. 3 is a kind of another part flow diagram of JS code test method provided in an embodiment of the present invention.
Fig. 4 is a kind of schematic block diagram of JS code tester device provided in an embodiment of the present invention.
Fig. 5 is a kind of another part schematic block diagram of JS code tester device provided in an embodiment of the present invention.
Icon: 100- electronic equipment;110-JS code tester device;The first configuration file of 111- obtains module;112- One test result obtains module;The second configuration file of 113- obtains module;The second test result of 114- obtains module;120- processing Device;130- memory.
Specific embodiment
Following will be combined with the drawings in the embodiments of the present invention, and technical solution in the embodiment of the present invention carries out clear, complete Site preparation description, it is clear that described embodiment is only disclosure a part of the embodiment, instead of all the embodiments.Usually The component for the embodiment of the present invention being described and illustrated herein in the accompanying drawings can be arranged and be designed with a variety of different configurations.Cause This, is not intended to limit the claimed disclosure to the detailed description of the embodiment of the disclosure provided in the accompanying drawings below Range, but it is merely representative of the selected embodiment of the disclosure.Based on embodiment of the disclosure, those skilled in the art are not being done Every other embodiment obtained under the premise of creative work out belongs to the range of disclosure protection.
It should also be noted that similar label and letter indicate similar terms in following attached drawing, therefore, once a certain Xiang Yi It is defined in a attached drawing, does not then need that it is further defined and explained in subsequent attached drawing.
Referring to Fig. 1, to be provided in an embodiment of the present invention a kind of using JS code test method and the electronic equipment of device 100 schematic block diagram.Further, in the embodiment of the present invention, the electronic equipment 100 include code tester device 110, Processor 120 and memory 130.
It is directly or indirectly electrically connected between processor 120 and memory 130, to realize the transmission or interaction of data, It is electrically connected for example, these elements can be realized between each other by one or more communication bus or signal wire.JS code tester Device 110 includes that at least one can store in memory 130 or be solidificated in electricity in the form of software or firmware (Firmware) Software module in the operating system (Operating System, OS) of sub- equipment 100.Processor 120 is for executing memory The executable module stored in 130, for example, software function module and computer program included by JS code tester device 110 Deng.Processor 120 can execute computer program after receiving and executing instruction.
Wherein, processor 120 can be a kind of IC chip, have signal handling capacity.Processor 120 can also be with It is general processor, for example, it may be digital signal processor (DSP), specific integrated circuit (ASIC), discrete gate or transistor Logical device, discrete hardware components may be implemented or execute disclosed each method, step and logic in the embodiment of the present invention Block diagram.In addition, general processor can be microprocessor or any conventional processors etc..
Memory 130 may be, but not limited to, random access memory (Random Access Memory, RAM), only It reads memory (Read Only Memory, ROM), programmable read only memory (Programmable Read-Only Memory, PROM), erasable programmable read only memory (Erasable Programmable Read-Only Memory, EPROM), electrically erasable programming read-only memory Electric Erasable Programmable Read-Only Memory, EEPROM) etc..For memory 130 for storing program, processor 120 executes the program after receiving and executing instruction.
It should be appreciated that structure shown in FIG. 1 is only to illustrate, electronic equipment 100 provided in an embodiment of the present invention can also have There is component more less or more than Fig. 1, or with the configuration different from shown in Fig. 1.In addition, each component shown in FIG. 1 can be with It is realized by software, hardware or combinations thereof.
Referring to Fig. 2, Fig. 2 is the flow diagram of JS code test method provided in an embodiment of the present invention, the JS code Test method is applied to electronic equipment shown in FIG. 1, below with reference to Fig. 2 to the detailed process and step of the JS code test method Suddenly it is described in detail.It should be noted that method provided by the invention is not limitation with Fig. 2 and sequence as shown below, with The detailed process and step of JS code test method is described in detail in lower combination Fig. 2.
Step S100 obtains JS code to be tested, and first configuration file corresponding with JS code to be tested.
First configuration file is to be pre-created, for testing compatibility of the JS code to be tested relative to preset browsing device set Property.It wherein, include the browser of multiple and different types in preset browsing device set, for example, IE browser, Google's browser, fire It is multiple in the browsers such as fox browser, 360 secure browsers, sogou browser, Window on the World browser.The embodiment of the present invention In, it will be for including IE browser, Google's browser, red fox browser in preset browsing device set, to the code tester side JS The detailed process and step of method are described in detail.
Step S200 tests JS code to be tested relative to the simultaneous of preset browsing device set simultaneously based on the first configuration file Capacitive obtains the code for code compatibility test result of JS code to be tested.
It include at least one target JS function in JS code to be tested.Wherein, target JS function is or to be worked as by event-driven The reusable code block for realizing corresponding function is executed when it is called.For example, function currentStyle (), letter The JS functions such as number getComputedStyle (), function const ().
It may include at least one in the embodiment of the present invention, in the first configuration file for characterizing JS function relative to default The incompatible function compatibility information of browser collection.It should be noted that in the embodiment of the present invention, for certain JS function, There are incompatible browsers in preset browsing device set, then incompatible relative to preset browsing device set.Based on this, it is based on First configuration file tests compatibility of the JS code to be tested relative to preset browsing device set simultaneously, obtains JS code to be tested Code for code compatibility test result, may comprise steps of.
Based at least one function compatibility information, each target JS function phase in JS code to be tested is determined respectively Function compatibility test for preset browsing device set is as a result, and according to all target JS functions in JS code to be tested Function compatibility test is as a result, determine the code for code compatibility test result of JS code to be tested.Wherein, if in JS code to be tested All target JS functions it is compatible both with respect to preset browsing device set, then the code for code compatibility of JS code to be tested is tested into knot Fruit is determined as being compatible with, and otherwise, the code for code compatibility test result of JS code to be tested is determined as incompatible.
Further, in the embodiment of the present invention, it is based at least one function compatibility information, determines JS generation to be tested respectively Code in each target JS function relative to preset browsing device set function compatibility test as a result, may include following step Suddenly.
For each target JS function in JS code to be tested, judge to whether there is in the first configuration file respectively and mesh Mark the corresponding function compatibility information of JS function.Since in the embodiment of the present invention, function compatibility information is for characterizing JS letter Number is incompatible relative to preset browsing device set, therefore, if there is letter corresponding with target JS function in the first configuration file Number compatibility informations then determine the function compatibility test of target JS function as a result, otherwise, by mesh according to function compatibility information The function compatibility test result of mark JS function is determined as being compatible with.
Optionally, in the embodiment of the present invention, function compatibility information includes function label and the corresponding letter of and function label Number contents, the corresponding JS function of each function label, function content for characterize the corresponding JS function of and function label relative to The compatibility of browser in preset browsing device set.
For example, function compatibility information can be " currentStyle ": " true:IE ", wherein " currentStyle " For function label, corresponding JS function is currentStyle (), and the corresponding function of JS function currentStyle () is The non-pattern in the ranks of html page elements is obtained, " true:IE " is function content, for characterizing JS function currentStyle () is compatible relative to the IE browser in preset browsing device set, that is, clear relative to the Google in preset browsing device set Device and red fox browser-incompatible are look at, it is understood, therefore, that the function compatibility information can also write " " CurrentStyle ": " false:Chrome, Firefox " ".In the embodiment of the present invention, for guarantee code terseness, preferably It writes " " currentStyle ": " true:IE " ".For another example function compatibility information can be " GetComputedStyle ": " false:IE ", wherein " getComputedStyle " is function label, corresponding JS function For getComputedStyle (), the corresponding function of JS function getComputedStyle () is to obtain html page elements Non- pattern in the ranks, " false:IE " is function content, clear relative to presetting for characterizing JS function getComputedStyle () The IE browser look in device set is incompatible, that is, relative to Google's browser and red fox browsing in preset browsing device set Device is compatible, it is understood, therefore, that the function compatibility information can also write " getComputedStyle: " true: Chrome, Firefox ".It in the embodiment of the present invention, for the terseness for guaranteeing code, preferably writes " GetComputedStyle ": " false:IE ".In another example function compatibility information can be " setAttribute ": " False:IE ", wherein " setAttribute " is function label, and corresponding JS function is setAttribute (), JS letter The corresponding function of number setAttribute () is setting object properties, and " false:IE " is function content, for characterizing JS function SetAttribute () is incompatible relative to the IE browser in preset browsing device set, that is, relative to preset browsing device collection Google's browser and red fox browser-safe in conjunction, it is understood, therefore, that the function compatibility information can also be write Make " const ": " false:Chrome, Firefox ".It in the embodiment of the present invention, for the terseness for guaranteeing code, preferably writes " SetAttribute ": " true:Firefox ".
From the foregoing, it will be observed that it is possible that simultaneously including two different JS functions, and both JS in JS code to be tested The corresponding function of function is identical, but the situation that the browser being compatible with is different.For example, JS function currentStyle () and JS letter Number getComputedStyle () corresponding function is identical, but the compatible IE browser of JS function currentStyle (), JS function The compatible Google's browser of getComputedStyle () and red fox browser.In response to this, in the embodiment of the present invention, the One configuration file is also provided with presupposed information association situation, for determining the association type of function compatibility information, association type Including the first association type and the second association type.First association type is not present and letter for being characterized in the first configuration file The function compatibility information of number compatible information function association, for example, function compatibility information " setAttribute ": " false: IE″.There are the function of and function compatible information function association compatibilities for being characterized in the first configuration file for second association type Property information, for example, function compatibility information " currentStyle ": " true:IE " and function compatibility information " GetComputedStyle ": " false:IE ".It, can be by association type for the cleaning for guaranteeing code in actual implementation A Global Information, example are write for the function compatibility information of the second association type and the function compatibility information of its function association Such as, by function compatibility information " currentStyle ": " true:IE " and function compatibility information " GetComputedStyle ": " false:IE " writing " currentStyle ": " true:IE ";" getComputedStyle ": " True:Chrome, Firefox ".
Based on above description, in the embodiment of the present invention, determine that the function of target JS function is simultaneous according to function compatibility information Capacitive test result, may comprise steps of.
Determine the association type of function compatible information.If the association type of function compatible information is the first association type, According to function compatible information, the function compatibility test of target JS function is determined as a result, in the embodiment of the present invention, that is, determining The function compatibility test result of target JS function is incompatible.If the association type of function compatible information is the second association class Type, then according to the function content of function compatible information and the letter of the function compatibility information of and function compatible information function association Number content, determines the function compatibility test result of target JS function.
In actual implementation, it is possible, firstly, to be obtained according to the function content of function compatible information to and function compatible information The compatible browser of corresponding JS function, as the first browser.It is again that the function of and function compatible information function association is compatible Property information, as correlation function compatibility information, and according to the function content of correlation function compatibility information, obtain to be associated with The compatible browser of the corresponding JS function of function compatible information, as the second browser.Finally, judging the first browser and second Whether the set of browser is identical as preset browsing device set.If the set and preset browsing of the first browser and the second browser Device set is identical, it is determined that the function compatibility test result of target JS function is compatibility, otherwise, it determines the letter of target JS function Number compatibility test result is incompatible.
For example, when simultaneously including JS function currentStyle () and JS function in JS code to be tested It, can be according to the function compatible information " currentStyle " in the first configuration file when getComputedStyle (): " True:IE " obtains the browser namely IE browser compatible to JS function currentStyle (), as the first browser, Meanwhile by and function compatible information " currentStyle ": " true:IE " associated function compatibility information " GetComputedStyle ": " false:IE " is used as correlation function compatible information, and obtains to JS function GetComputedStyle () compatible browser namely Google's browser and red fox browser, as the second browser.The The set of one browser and the second browser is identical as preset browsing device, it is determined that the function of JS function currentStyle () Compatibility test result is compatibility.Through same judgment mode, the letter of JS function getComputedStyle () can also be determined Number compatibility test result is compatibility.
Further to judge incompatible degree of the target JS function relative to preset browsing device set, the embodiment of the present invention In, the first configuration file is also provided with the compatible implementations of preset browsing device, for determining the incompatible class of function compatibility information Type, incompatible type include the first incompatible type and the second incompatible type.First incompatible type is simultaneous for characterizing function The incompatible situation of capacitive information is completely incompatible, and the second incompatible type is for characterizing the incompatible of function compatibility information Situation is not exclusively compatible.For certain function compatibility information, if its incompatible type is the first incompatible type, table It cannot achieve corresponding function on the JS function of sign browser incompatible in preset browsing device set, if its incompatible type is Second incompatible type then may be implemented to correspond on the JS function of its characterization browser incompatible in preset browsing device set Function, but realize that effect is unable to satisfy preset requirement.
For example, there is function compatibility information " setAttribute " in the first configuration file: " false:IE " and function Compatibility information " str ": " false:IE6, IE7 ", and the corresponding function of JS function setAttribute () is in IE browser On cannot achieve, then by function compatibility information " setAttribute ": the incompatible type decision of " false:IE " be first Corresponding function may be implemented in incompatible type, the corresponding function of JS function str () on IE6 and IE7, but realizes that effect can not Meet preset requirement, then by function compatibility information " str ": the incompatible type decision of " false:IE6, IE7 " is not second not Compatible type.It can be the letter of the first incompatible type by incompatible type for the cleaning for guaranteeing code in actual implementation A program segment is written in number compatibility information, then the function compatibility information that incompatible type is the second incompatible type is written Another program segment, for example, being the function compatibility information write-in program section of the first incompatible type by incompatible type " Incompatible type is the function compatibility information write-in program section " warning " of the second incompatible type by block " { ... } {...}
Based on above description, in the embodiment of the present invention, when the function compatibility test result of target JS function is incompatible When, the function compatibility test of target JS function is determined according to function compatibility information as a result, can also include the following steps.
The incompatible type of discriminant function compatibility information, if the incompatible type of function compatibility information is first not simultaneous Hold type, then by the function compatibility results of target JS function be determined as completely it is incompatible, if function compatibility information is not simultaneous Appearance type is the second incompatible type, then the function compatibility results of target JS function are determined as incomplete compatibility.
It, can also basis after the code for code compatibility test result for obtaining JS code to be tested in the embodiment of the present invention Code for code compatibility test result generates code for code compatibility test report.It may include each function in code for code compatibility test report Compatibility test result is completely incompatible in complete incompatible objective function and corresponding preset browsing device set Browser, equally, in code for code compatibility test report can also include each function compatibility test result be not exclusively it is simultaneous Browser not exclusively compatible in the objective function of appearance and corresponding preset browsing device set.
Citing is tested into JS code to be tested relative to preset browsing device set simultaneously to based on the first configuration file below Compatibility, the overall process for obtaining the code for code compatibility test result of JS code to be tested is illustrated.
For example, the first configuration file are as follows:
The objective function that code to be tested includes be JS function cursor:hand (), JS function currentStyle (), JS function getComputedStyle (), JS function " setAttribute " () and JS function str ().
For JS function cursor:hand (), there is no right with JS function cursor:hand () in the first configuration file The function compatibility information answered, then the function compatibility test result of JS function cursor:hand () is determined as being compatible with.
It is right with JS function currentStyle () to exist for JS function currentStyle (), in the first configuration file The function compatibility information " currentStyle " answered: " true:IE ", function compatibility information " currentStyle ": " The association type of true:IE " is the second association type, and function compatibility information " currentStyle ": the pass of " true:IE " Joining function compatibility information is " getComputedStyle ": " false:IE ".Further, and to JS function CurrentStyle () compatible browser is IE browser, the browser compatible to JS function getComputedStyle () For Google's browser and red fox browser, IE browser, the set of Google's browser and red fox browser and preset browsing device collection Close it is identical, so the function compatibility test result of JS function currentStyle () is determined as being compatible with.Through the similarly side of judgement Formula, it is also compatible for obtaining the function compatibility test result of JS function getComputedStyle ().It is understood that if There are JS function currentStyle () in JS code to be tested, JS function getComputedStyle () may be not present, then The function compatibility test result of JS function currentStyle () be determined as it is incompatible, equally, if in JS code to be tested There are JS function getComputedStyle (), JS function currentStyle () may be not present, then JS function The function compatibility test result of getComputedStyle () is determined as incompatible.
For JS function " setAttribute " (), exist and JS function " setAttribute " in the first configuration file () corresponding function compatibility information " setAttribute ": " false:IE ", and the pass of JS function " setAttribute " () Connection type is the first association type, then the function compatibility test result of JS function " setAttribute " () is determined as not simultaneous Hold, further, due to function compatibility information " setAttribute ": the incompatible type of " false:IE " is first not simultaneous Hold type, then may further determine that the function compatibility test result of JS function " setAttribute " () is determined as completely It is incompatible.
For JS function str (), there is function compatibility information corresponding with JS function str () in the first configuration file " Str ": " false:IE6, IE7 ", and the association type of JS function str () is the first association type, the then letter of JS function str () Number compatibility test results be determined as it is incompatible, further, due to function compatibility information " str ": " false:IE6, IE7 " Incompatible type be the second incompatible type, then may further determine that the function compatibility test result of JS function str () It is determined as incomplete compatibility.
Hereafter, it determines that the code for code compatibility test result of JS code to be tested is incompatible, and can be generated including JS letter Number " setAttribute " incompatible IE browser completely, the not exclusively compatible IE6 browser of JS function str () and IE7 browser Code for code compatibility test report.
Optionally, in the embodiment of the present invention, JS code test method, further includes:
Step S300 obtains corresponding second configuration file of JS code to be tested.
Second configuration file is to be pre-created, for testing the syntax gauge of JS code to be tested.
Step S400 tests the syntax gauge of JS code to be tested based on the second configuration file, obtains JS generation to be tested The code syntax normalization test result of code.
It may include at least one in the embodiment of the present invention, in the second configuration file for characterizing the grammer that JS function has The syntax gauge information of Problem.Based on this, the syntax gauge of JS code to be tested is tested based on the second configuration file Property, the code syntax normalization test result of JS code to be tested is obtained, may comprise steps of.
For every syntax gauge information, judge in JS code to be tested with the presence or absence of corresponding with syntax gauge information Grammer setting.If having grammer corresponding with syntax gauge information in JS code to be tested to be arranged, grammer is arranged and is made For grammer lack of standardization.If there are grammers lack of standardization in JS code, it is determined that the code syntax normalization of JS code to be tested is tested As a result to be lack of standardization, otherwise, it determines the code syntax normalization test result of JS code to be tested is specification.
Optionally, in the embodiment of the present invention, syntax gauge information includes grammer label and corresponding with grammer label sentences Disconnected standard content, the corresponding grammer setting of each grammer label, judgment criteria content is for characterizing language corresponding with grammer label The syntax gauge of method setting is lack of standardization.
For example, syntax gauge information can be " bitwise ": true, wherein " bitwise " is grammer label, right The grammer answered be set as whether in JS code be provided with unused bit operator (such as ^), true be judgment criteria content, use If being provided with unused bit operator (such as ^, &) in characterizing in JS code to be tested, then in the code for confirming JS code to be tested The grammer is set as grammer lack of standardization, and can further confirm that the code syntax normalization test result of JS code to be tested is It is lack of standardization.For another example syntax gauge information can be " curly ": true, wherein " curly " is grammer label, is corresponded to Grammer be set as whether in the sentences such as and if while carrying out clear code block using { }, true is judgment criteria content, is used for If characterizing in JS code to be tested and carrying out clear code block using { } in the sentences such as and if while, JS code to be tested is confirmed Code in the grammer be set as grammer lack of standardization, and can further confirm that the code syntax of JS code to be tested is normative Test result is lack of standardization.In another example " noarg ": true, wherein " noarg " is grammer label, corresponding grammer setting Whether to have used arguments.caller and arguments.callee, true is judgment criteria content, if for characterizing Arguments.caller and arguments.callee have been used in JS code to be tested, then has confirmed JS code to be tested The grammer in code is set as grammer lack of standardization, and can further confirm that the code syntax normalization of JS code to be tested is surveyed Test result is lack of standardization.
In order to further judge the grammer degree lack of standardization of target JS function, in the embodiment of the present invention, the second configuration file Default syntax gauge implementations are also provided with, for determining the type lack of standardization of syntax gauge information, type lack of standardization includes First type lack of standardization and the second type lack of standardization, the grammer that the first type lack of standardization is used to characterize syntax gauge information are not advised For model problem to be completely lack of standardization, the Problem that the second type lack of standardization is used to characterize syntax gauge information is not exclusively to advise Model.For some grammer lack of standardization, if the type lack of standardization of its corresponding syntax gauge information is the first type lack of standardization, It, which is characterized in JS code, uses the grammer lack of standardization that can make JS code that can not be performed, and realizes the correspondence function of each JS function Can, if the type lack of standardization of its corresponding syntax gauge information is the second type lack of standardization, being characterized in JS code makes JS code can be allowed to be performed with the grammer lack of standardization, and realize the corresponding function of each JS function, but realize that effect can not Meet preset requirement.
For example, there is syntax gauge information " bitwise ": true and " noarg ": true in the second configuration file, by In in JS code be provided with (such as ^, the &) meeting of unused bit operator so that JS code can not be performed, and realize each JS function The type lack of standardization of " bitwise ": true is then confirmed as the first type lack of standardization by corresponding function, due to making in JS code With arguments.caller and arguments.callee, JS code can be performed, and realize the correspondence function of each JS function Can, but realize that effect is unable to satisfy preset requirement, then the type lack of standardization of " noarg ": true is confirmed as the second class lack of standardization Type.It can be the syntax gauge of the first type lack of standardization by type lack of standardization for the cleaning for guaranteeing code in actual implementation Property information be written a program segment, then by type lack of standardization be the second type lack of standardization syntax gauge information another is written Program segment, for example, being the syntax gauge information write-in program section " block " of the first type lack of standardization by type lack of standardization Type lack of standardization is the syntax gauge information write-in program section " warning " { ... } of the second type lack of standardization by { ... }
Based on above description, in the embodiment of the present invention, if existing in JS code to be tested corresponding with syntax gauge information Grammer setting, then grammer is provided as grammer lack of standardization, can specifically include following steps.
The type lack of standardization of syntax gauge information is judged, if the type lack of standardization of syntax gauge information is not advised for first Grammer is then provided as complete grammer lack of standardization by model type, if the type lack of standardization of syntax gauge information is not advised for second Grammer is then provided as complete incomplete normative grammar by model type.
It, can be with after the code syntax normalization test result for obtaining JS code to be tested in the embodiment of the present invention Code syntax normalization test report is generated according to code syntax normalization test result.Code syntax normalization test report It may include each grammer lack of standardization and corresponding type lack of standardization in announcement.
It will illustrate below to the syntax gauge for testing JS code to be tested based on the second configuration file, obtain JS to be tested The overall process of the code syntax normalization test result of code is illustrated.
For example, the second configuration file are as follows:
It is provided with unused bit operator (such as ^, &) in code to be tested, and has used arguments.caller And arguments.callee.
For first syntax gauge information " bitwise ": true confirms the code syntax specification of JS code to be tested Property test result be lack of standardization, and since the type lack of standardization of syntax gauge information " bitwise ": true is first lack of standardization Type then confirms that the unused bit operator (such as ^, &) being arranged in JS code to be tested is complete grammer lack of standardization.
For Article 7 syntax gauge information " noarg ": true confirms that the code syntax of JS code to be tested is normative Test result is lack of standardization, and since the type lack of standardization of syntax gauge information " noarg ": true is the second class lack of standardization Type then confirms that it is not exclusively to standardize that arguments.caller and arguments.callee has been used in JS code to be tested Grammer.
Based on inventive concept same as above-mentioned virtual network resource predictor method to be provided, the embodiment of the present invention is also provided A kind of JS code tester device 110.Referring to Fig. 4, JS code tester device 110 includes that the first configuration file obtains module 111 and first test result obtain module 112.
First configuration file obtains module, for obtaining JS code to be tested, and corresponding with JS code to be tested the One configuration file.
The description as described in the first configuration file obtains module 111 specifically refers to the detailed description of above-mentioned steps S100, It is executed that is, step S100 can obtain module 111 by the first configuration file, details are not described herein again.
First test result obtains module, for testing JS code to be tested relative to pre- simultaneously based on the first configuration file If the compatibility of browser collection, the code for code compatibility test result of JS code to be tested is obtained.
Include at least one target JS function in JS code to be tested, includes at least one in the first configuration file for table Levy the JS function function compatibility information incompatible relative to preset browsing device set.Based on this, optionally, the embodiment of the present invention In, the first test result obtains module, it is specifically used for:
Based at least one function compatibility information, each target JS function phase in JS code to be tested is determined respectively For the function compatibility test result of preset browsing device set;
According to the function compatibility test of all target JS functions in JS code to be tested as a result, determining JS generation to be tested The code for code compatibility test result of code;
It wherein, will if all target JS functions in JS code to be tested are compatible both with respect to preset browsing device set The code for code compatibility test result of JS code to be tested is determined as being compatible with, and otherwise, the code for code compatibility of JS code to be tested is surveyed Test result is determined as incompatible.
Optionally, in the embodiment of the present invention, the first test result obtains module, and is specifically used for:
For each target JS function in JS code to be tested, judge to whether there is in the first configuration file respectively and mesh Mark the corresponding function compatibility information of JS function;
If there is function compatibility information corresponding with target JS function in the first configuration file, according to function compatibility Information determines the function compatibility test of target JS function as a result, otherwise, by the function compatibility test result of target JS function It is determined as being compatible with.
Function compatibility information includes function label and the corresponding function content of and function label, and each function label is corresponding One JS function, function content is for characterizing the corresponding JS function of and function label relative to the browser in preset browsing device set Compatibility.Based on this, optionally, in the embodiment of the present invention, the first test result obtains module, and is specifically used for:
It is associated with situation based on presupposed information, determines that the association type of function compatibility information, association type include the first pass Join type and the second association type, there is no and function compatible informations for being characterized in the first configuration file for the first association type The function compatibility information of function association, there are the compatible letters of and function for being characterized in the first configuration file for the second association type Cease the function compatibility information of function association;
If the association type of function compatible information determines target JS according to function compatible information for the first association type The function compatibility test result of function;
If the association type of function compatible information be the second association type, according to the function content of function compatible information with And the function content of the function compatibility information of and function compatible information function association, determine the function compatibility of target JS function Test result.
Optionally, in the embodiment of the present invention, the first test result obtains module, and is specifically used for:
According to the function content of function compatible information, the compatible browsing of JS function corresponding to and function compatible information is obtained Device, as the first browser;
By the function compatibility information of and function compatible information function association, as correlation function compatibility information, and root According to the function content of correlation function compatibility information, the browsing compatible to JS function corresponding with correlation function compatible information is obtained Device, as the second browser;
Judge whether the set of the first browser and the second browser is identical as preset browsing device set;
If the set of the first browser and the second browser is identical as preset browsing device set, it is determined that target JS function Function compatibility test result is compatibility, otherwise, it determines the function compatibility test result of target JS function is incompatible.
When the function compatibility test result of target JS function is incompatible, optionally, in the embodiment of the present invention, first Test result obtains module, also particularly useful for:
Based on the compatible implementations of preset browsing device, the incompatible type of function compatibility information, incompatible type packet are determined The first incompatible type and the second incompatible type are included, the first incompatible type is for characterizing the incompatible of function compatibility information For situation to be completely incompatible, the incompatible situation that the second incompatible type is used to characterize function compatibility information is not exclusively simultaneous Hold;
If the incompatible type of function compatibility information is the first incompatible type, and the function of target JS function is compatible Property result be determined as completely it is incompatible;
If the incompatible type of function compatibility information is the second incompatible type, the function compatibility of target JS function As a result it is determined as incomplete compatibility.
The description as described in the first test result obtains module 112 specifically refers to the detailed description of above-mentioned steps S200, It is executed that is, step S200 can obtain module 112 by the first test result, details are not described herein again.
Referring to Fig. 5, optionally, in the embodiment of the present invention, JS code tester device, further includes:
Second configuration file obtains module, for obtaining corresponding second configuration file of JS code to be tested.
The description as described in the second configuration file obtains module 113 specifically refers to the detailed description of above-mentioned steps S300, It is executed that is, step S300 can obtain module 113 by the second configuration file, details are not described herein again.
Second test result obtains module, for testing the syntax gauge of JS code to be tested based on the second configuration file Property, obtain the code syntax normalization test result of JS code to be tested.
It include at least one in second configuration file for characterizing the grammer Problem that JS code to be tested has Syntax gauge information.Based on this, optionally, in the embodiment of the present invention, the second test result obtains module, is specifically used for:
For every syntax gauge information, judge in JS code to be tested with the presence or absence of corresponding with syntax gauge information Grammer setting;
If having grammer corresponding with syntax gauge information in JS code to be tested to be arranged, grammer is provided as not Normative grammar;
If there are grammers lack of standardization in JS code, it is determined that the code syntax normalization test result of JS code to be tested is It is lack of standardization, otherwise, it determines the code syntax normalization test result of JS code to be tested is specification.
Optionally, in the embodiment of the present invention, the second test result obtains module, and is specifically used for:
Based on default syntax gauge implementations, determine that the type lack of standardization of syntax gauge information, type lack of standardization include First type lack of standardization and the second type lack of standardization, the grammer that the first type lack of standardization is used to characterize syntax gauge information are not advised For model problem to be completely lack of standardization, the Problem that the second type lack of standardization is used to characterize syntax gauge information is not exclusively to advise Model;
If the type lack of standardization of syntax gauge information is the first type lack of standardization, grammer is provided as not advising completely Model grammer;
If the type lack of standardization of the syntax gauge information is the described second type lack of standardization, grammer is provided as Complete incomplete normative grammar.
The description as described in the second test result obtains module 114 specifically refers to the detailed description of above-mentioned steps S400, It is executed that is, step S400 can obtain module 114 by the second test result, details are not described herein again.
To sum up, JS code test method, device and electronic equipment provided in an embodiment of the present invention can obtain JS to be tested Code, and first configuration file corresponding with JS code to be tested, and JS to be tested is tested based on the first configuration file simultaneously Compatibility of the code relative to preset browsing device set obtains the code for code compatibility test result of JS code to be tested.In this way, When needing to test JS code to be tested, it need to directly can only be tested JS generation to be tested simultaneously based on the first configuration file Compatibility of the code relative to preset browsing device set, so that the code for code compatibility test result of JS code to be tested is obtained, therefore, In compared to the prior art, tested respectively by way of manual testing each browser to JS code to be tested compatibility For scheme, testing efficiency, which has, largely to be improved.
In several embodiments provided by the embodiment of the present invention, it should be understood that disclosed device and method, it can also To realize by another way.Device and method embodiment described above is only schematical, for example, in attached drawing Flow chart and block diagram show that the devices of multiple embodiments according to the disclosure, method and computer program product are able to achieve Architecture, function and operation.In this regard, each box in flowchart or block diagram can represent module, a program A part of section or code, a part of module, section or code include one or more for realizing defined logic function The executable instruction of energy.It should also be noted that function marked in the box can also be in some implementations as replacement Occur in a different order than that indicated in the drawings.For example, two continuous boxes can actually be basically executed in parallel, it Can also execute in the opposite order sometimes, this depends on the function involved.It is also noted that block diagram and/or process The combination of each box in figure and the box in block diagram and or flow chart, can as defined in executing function or movement Dedicated hardware based system is realized, or can be realized using a combination of dedicated hardware and computer instructions.
In addition, each functional module in each embodiment of the disclosure can integrate one independent portion of formation together Point, being also possible to modules individually includes, and an independent part can also be integrated to form with two or more modules.
If function is realized and when sold or used as an independent product in the form of software function module, can store In a computer readable storage medium.Based on this understanding, the technical solution of the disclosure is substantially in other words to existing Having the part for the part or the technical solution that technology contributes can be embodied in the form of software products, the computer Software product is stored in a storage medium, including some instructions are used so that a computer equipment (can be personal meter Calculation machine, electronic equipment or network equipment etc.) execute each embodiment method of the disclosure all or part of the steps.And it is aforementioned Storage medium include: USB flash disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory The various media that can store program code such as (RAM, RandomAccess Memory), magnetic or disk.It needs to illustrate It is, herein, the terms "include", "comprise" or any other variant thereof is intended to cover non-exclusive inclusion, to make Obtaining the process, method, article or equipment including a series of elements not only includes those elements, but also including not arranging clearly Other element out, or further include for elements inherent to such a process, method, article, or device.Not more In the case where limitation, the element that is limited by sentence " including one ... ", it is not excluded that include element process, method, It further include other identical element in article or equipment.
The above is only the alternative embodiments of the disclosure, are not limited to the disclosure, for those skilled in the art For member, the disclosure can have various modifications and variations.It is all the disclosure spirit and principle within, it is made it is any modification, Equivalent replacement, improvement etc., should be included within the protection scope of the disclosure.
A1. a kind of JS code test method characterized by comprising
Obtain JS code to be tested, and first configuration file corresponding with the JS code to be tested;
The JS code to be tested is tested relative to the simultaneous of preset browsing device set simultaneously based on first configuration file Capacitive obtains the code for code compatibility test result of the JS code to be tested.
A2. the JS code test method according to claim A1, which is characterized in that wrapped in the JS code to be tested At least one target JS function is included, includes at least one in first configuration file for characterizing JS function relative to described pre- If the incompatible function compatibility information of browser collection;
It is described that the JS code to be tested is tested relative to preset browsing device set simultaneously based on first configuration file Compatibility, obtain the code for code compatibility test result of the JS code to be tested, comprising:
Based on at least one function compatibility information, each target JS in the JS code to be tested is determined respectively Function compatibility test result of the function relative to the preset browsing device set;
According to the function compatibility test of all target JS functions in the JS code to be tested as a result, determine it is described to Test the code for code compatibility test result of JS code;
Wherein, if all target JS functions in the JS code to be tested are simultaneous both with respect to the preset browsing device set Hold, is then determined as being compatible with by the code for code compatibility test result of the JS code to be tested, otherwise, by the JS code to be tested Code for code compatibility test result be determined as it is incompatible.
A3. the JS code test method according to claim A2, which is characterized in that described to be based on described at least one Function compatibility information determines each target JS function in the JS code to be tested relative to the preset browsing respectively The function compatibility test result of device set, comprising:
For each target JS function in the JS code to be tested, judge in first configuration file respectively whether In the presence of function compatibility information corresponding with the target JS function;
If there is function compatibility information corresponding with the target JS function in first configuration file, according to institute It states function compatibility information and determines the function compatibility test of the target JS function as a result, otherwise, by the target JS The function compatibility test result of function is determined as being compatible with.
A4. the JS code test method according to claim A3, which is characterized in that the function compatibility information packet Include function label and function content corresponding with the function label, each corresponding JS function of the function label, the letter Number content is for characterizing JS function corresponding with the function label relative to the browser in the preset browsing device set Compatibility;
It is described according to the function compatibility information determine the target JS function the function compatibility test as a result, Include:
It is associated with situation based on presupposed information, determines the association type of the function compatibility information, the association type packet The first association type and the second association type are included, first association type is not deposited for being characterized in first configuration file In the function compatibility information with the function compatible information function association, second association type is for being characterized in described the There is the function compatibility information with the function compatible information function association in one configuration file;
If the association type of the function compatible information is first association type, believe according to the function is compatible Breath, determines the function compatibility test result of the target JS function;
If the association type of the function compatible information is second association type, according to the function compatible information Function content and function content with the function compatibility information of the function compatible information function association, determine the mesh Mark the function compatibility test result of JS function.
A5. the JS code test method according to claim A4, which is characterized in that described compatible according to the function The function content of information and function content with the function compatibility information of the function compatible information function association, determine institute State the function compatibility test result of target JS function, comprising:
According to the function content of the function compatible information, obtain simultaneous to JS function corresponding with the function compatible information The browser of appearance, as the first browser;
By the function compatibility information with the function compatible information function association, as correlation function compatibility information, And according to the function content of the correlation function compatibility information, obtain to JS letter corresponding with the correlation function compatible information The compatible browser of number, as the second browser;
Judge whether the set of first browser and second browser is identical as the preset browsing device set;
If the set of first browser and second browser is identical as the preset browsing device set, it is determined that The function compatibility test result of the target JS function is compatibility, otherwise, it determines the letter of the target JS function Number compatibility test result is incompatible.
A6. the JS code test method according to claim A4, which is characterized in that when the institute of the target JS function State function compatibility test result be it is incompatible when, it is described that the target JS function is determined according to the function compatibility information The function compatibility test result, further includes:
Based on the compatible implementations of preset browsing device, the incompatible type of the function compatibility information is determined, it is described not simultaneous Holding type includes the first incompatible type and the second incompatible type, and the first incompatible type is simultaneous for characterizing the function The incompatible situation of capacitive information is completely incompatible, and the second incompatible type is for characterizing the function compatibility information Incompatible situation be not exclusively compatible;
If the incompatible type of the function compatibility information is the described first incompatible type, by the target JS letter Several function compatibility results are determined as completely incompatible;
If the incompatible type of the function compatibility information is the described second incompatible type, the target JS function Function compatibility results be determined as incomplete compatibility.
A7. the JS code test method according to claim A1, which is characterized in that the JS code test method, Further include:
Obtain corresponding second configuration file of the JS code to be tested;
The syntax gauge of the JS code to be tested is tested based on second configuration file, obtains the JS to be tested The code syntax normalization test result of code.
A8. the JS code test method according to claim A7, which is characterized in that wrapped in second configuration file At least one is included for characterizing the syntax gauge information for the grammer Problem that JS code to be tested has;
The syntax gauge that the JS code to be tested is tested based on second configuration file is obtained described to be measured Try the code syntax normalization test result of JS code, comprising:
For syntax gauge information described in every, judge to whether there is and institute's grammar rule in the JS code to be tested The corresponding grammer setting of plasticity information;
If having grammer corresponding with the syntax gauge information in the JS code to be tested to be arranged, by institute's predicate Method is provided as grammer lack of standardization;
If there are the grammers lack of standardization in the JS code, it is determined that the code syntax specification of the JS code to be tested Property test result be it is lack of standardization, otherwise, it determines the code syntax normalization test result of the JS code to be tested be specification.
A9. the JS code test method according to claim A8, which is characterized in that if in the JS code to be tested It is arranged in the presence of grammer corresponding with the syntax gauge information, then the grammer is provided as grammer lack of standardization, comprising:
Based on default syntax gauge implementations, the type lack of standardization of the syntax gauge information is determined, it is described lack of standardization Type includes the first type lack of standardization and the second type lack of standardization, and first type lack of standardization is for characterizing the syntax gauge Property information grammer Problem be it is completely lack of standardization, second type lack of standardization is for characterizing syntax gauge letter The Problem of breath is not exclusively to standardize;
If the type lack of standardization of the syntax gauge information is the described first type lack of standardization, the grammer is arranged As complete grammer lack of standardization;
If the type lack of standardization of the syntax gauge information is the described second type lack of standardization, the grammer is arranged As complete incomplete normative grammar.
B10. a kind of JS code tester device characterized by comprising
First configuration file obtains module, for obtaining JS code to be tested, and it is corresponding with the JS code to be tested The first configuration file;
First test result obtains module, for testing the JS code to be tested simultaneously based on first configuration file Relative to the compatibility of preset browsing device set, the code for code compatibility test result of the JS code to be tested is obtained.
B11. the JS code tester device according to claim B10, which is characterized in that in the JS code to be tested It include at least one for characterizing JS function relative to described including at least one target JS function, in first configuration file The incompatible function compatibility information of preset browsing device set;
First test result obtains module, is specifically used for:
Based on at least one function compatibility information, each target JS in the JS code to be tested is determined respectively Function compatibility test result of the function relative to the preset browsing device set;
According to the function compatibility test of all target JS functions in the JS code to be tested as a result, determine it is described to Test the code for code compatibility test result of JS code;
Wherein, if all target JS functions in the JS code to be tested are simultaneous both with respect to the preset browsing device set Hold, is then determined as being compatible with by the code for code compatibility test result of the JS code to be tested, otherwise, by the JS code to be tested Code for code compatibility test result be determined as it is incompatible.
B12. the JS code tester device according to claim B10, which is characterized in that first test result obtains Modulus block, and be specifically used for:
For each target JS function in the JS code to be tested, judge in first configuration file respectively whether In the presence of function compatibility information corresponding with the target JS function;
If there is function compatibility information corresponding with the target JS function in first configuration file, according to institute It states function compatibility information and determines the function compatibility test of the target JS function as a result, otherwise, by the target JS The function compatibility test result of function is determined as being compatible with.
B13. the JS code tester device according to claim B12, which is characterized in that the function compatibility information Including function label and function content corresponding with the function label, each corresponding JS function of the function label is described Function content is for characterizing JS function corresponding with the function label relative to the browser in the preset browsing device set Compatibility;
First test result obtains module, and is specifically used for:
It is associated with situation based on presupposed information, determines the association type of the function compatibility information, the association type packet The first association type and the second association type are included, first association type is not deposited for being characterized in first configuration file In the function compatibility information with the function compatible information function association, second association type is for being characterized in described the There is the function compatibility information with the function compatible information function association in one configuration file;
If the association type of the function compatible information is first association type, believe according to the function is compatible Breath, determines the function compatibility test result of the target JS function;
If the association type of the function compatible information is second association type, according to the function compatible information Function content and function content with the function compatibility information of the function compatible information function association, determine the mesh Mark the function compatibility test result of JS function.
B14. the JS code tester device according to claim B13, which is characterized in that first test result obtains Modulus block, and be specifically used for:
According to the function content of the function compatible information, obtain simultaneous to JS function corresponding with the function compatible information The browser of appearance, as the first browser;
By the function compatibility information with the function compatible information function association, as correlation function compatibility information, And according to the function content of the correlation function compatibility information, obtain to JS letter corresponding with the correlation function compatible information The compatible browser of number, as the second browser;
Judge whether the set of first browser and second browser is identical as the preset browsing device set;
If the set of first browser and second browser is identical as the preset browsing device set, it is determined that The function compatibility test result of the target JS function is compatibility, otherwise, it determines the letter of the target JS function Number compatibility test result is incompatible.
B15. the JS code tester device according to claim B13, which is characterized in that when the target JS function When the function compatibility test result is incompatible, first test result obtains module, also particularly useful for:
Based on the compatible implementations of preset browsing device, the incompatible type of the function compatibility information is determined, it is described not simultaneous Holding type includes the first incompatible type and the second incompatible type, and the first incompatible type is simultaneous for characterizing the function The incompatible situation of capacitive information is completely incompatible, and the second incompatible type is for characterizing the function compatibility information Incompatible situation be not exclusively compatible;
If the incompatible type of the function compatibility information is the described first incompatible type, by the target JS letter Several function compatibility results are determined as completely incompatible;
If the incompatible type of the function compatibility information is the described second incompatible type, the target JS function Function compatibility results be determined as incomplete compatibility.
B16. the JS code tester device according to claim B10, which is characterized in that the JS code tester dress It sets, further includes:
Second configuration file obtains module, for obtaining corresponding second configuration file of the JS code to be tested;
Second test result obtains module, for testing the JS code to be tested based on second configuration file Syntax gauge obtains the code syntax normalization test result of the JS code to be tested.
B17. the JS code tester device according to claim B16, which is characterized in that in second configuration file Including at least one for characterizing the syntax gauge information for the grammer Problem that JS code to be tested has;
Second test result obtains module, is specifically used for:
For syntax gauge information described in every, judge to whether there is and institute's grammar rule in the JS code to be tested The corresponding grammer setting of plasticity information;
If having grammer corresponding with the syntax gauge information in the JS code to be tested to be arranged, by institute's predicate Method is provided as grammer lack of standardization;
If there are the grammers lack of standardization in the JS code, it is determined that the code syntax specification of the JS code to be tested Property test result be it is lack of standardization, otherwise, it determines the code syntax normalization test result of the JS code to be tested be specification.
B18. the JS code tester device according to claim B17, which is characterized in that second test result obtains Modulus block, and be specifically used for:
Based on default syntax gauge implementations, the type lack of standardization of the syntax gauge information is determined, it is described lack of standardization Type includes the first type lack of standardization and the second type lack of standardization, and first type lack of standardization is for characterizing the syntax gauge Property information grammer Problem be it is completely lack of standardization, second type lack of standardization is for characterizing syntax gauge letter The Problem of breath is not exclusively to standardize;
If the type lack of standardization of the syntax gauge information is the described first type lack of standardization, the grammer is arranged As complete grammer lack of standardization;
If the type lack of standardization of the syntax gauge information is the described second type lack of standardization, the grammer is arranged As complete incomplete normative grammar.
C19. a kind of electronic equipment, which is characterized in that including described in processor, memory and claim B10-B18 JS code tester device, the JS code tester device include that one or more is stored in the memory and by the processor The software function module of execution.
D20. a kind of computer readable storage medium, is stored thereon with computer program, which is characterized in that the computer Program is performed, and JS code test method described in any one of claim A1-A9 may be implemented.

Claims (10)

1. a kind of JS code test method characterized by comprising
Obtain JS code to be tested, and first configuration file corresponding with the JS code to be tested;
Compatibility of the JS code to be tested relative to preset browsing device set is tested simultaneously based on first configuration file, Obtain the code for code compatibility test result of the JS code to be tested.
2. JS code test method according to claim 1, which is characterized in that include at least in the JS code to be tested One target JS function includes at least one in first configuration file for characterizing JS function relative to the preset browsing The incompatible function compatibility information of device set;
It is described that the JS code to be tested is tested relative to the simultaneous of preset browsing device set simultaneously based on first configuration file Capacitive obtains the code for code compatibility test result of the JS code to be tested, comprising:
Based on at least one function compatibility information, each target JS function in the JS code to be tested is determined respectively Function compatibility test result relative to the preset browsing device set;
According to the function compatibility test of all target JS functions in the JS code to be tested as a result, determination is described to be tested The code for code compatibility test result of JS code;
Wherein, if all target JS functions in the JS code to be tested are compatible both with respect to the preset browsing device set, Then the code for code compatibility test result of the JS code to be tested is determined as being compatible with, otherwise, by the JS code to be tested Code for code compatibility test result is determined as incompatible.
3. JS code test method according to claim 2, which is characterized in that described to be based at least one function simultaneous Capacitive information determines each target JS function in the JS code to be tested relative to the preset browsing device set respectively Function compatibility test result, comprising:
For each target JS function in the JS code to be tested, judge to whether there is in first configuration file respectively Function compatibility information corresponding with the target JS function;
If there is function compatibility information corresponding with the target JS function in first configuration file, according to the letter Number compatibility informations determine the function compatibility test of the target JS function as a result, otherwise, by the target JS function Function compatibility test result be determined as being compatible with.
4. JS code test method according to claim 3, which is characterized in that the function compatibility information includes function Label and function content corresponding with the function label, each corresponding JS function of the function label, the function content For characterizing compatibility of the JS function corresponding with the function label relative to the browser in the preset browsing device set;
It is described to determine the function compatibility test of the target JS function as a result, packet according to the function compatibility information It includes:
It is associated with situation based on presupposed information, determines the association type of the function compatibility information, the association type includes the One association type and the second association type, first association type for be characterized in first configuration file there is no with The function compatibility information of the function compatible information function association, second association type are matched for being characterized in described first Set the function compatibility information existed in file with the function compatible information function association;
If the association type of the function compatible information is first association type, according to the function compatible information, really The function compatibility test result of the fixed target JS function;
If the association type of the function compatible information is second association type, according to the letter of the function compatible information Number content and the function content with the function compatibility information of the function compatible information function association, determine the target JS The function compatibility test result of function.
5. JS code test method according to claim 4, which is characterized in that described according to the function compatible information Function content and function content with the function compatibility information of the function compatible information function association, determine the target The function compatibility test result of JS function, comprising:
According to the function content of the function compatible information, obtain compatible to JS function corresponding with the function compatible information Browser, as the first browser;
By the function compatibility information with the function compatible information function association, as correlation function compatibility information, and root According to the function content of the correlation function compatibility information, obtain simultaneous to JS function corresponding with the correlation function compatible information The browser of appearance, as the second browser;
Judge whether the set of first browser and second browser is identical as the preset browsing device set;
If the set of first browser and second browser is identical as the preset browsing device set, it is determined that described The function compatibility test result of target JS function is compatibility, otherwise, it determines the function of the target JS function is simultaneous Capacitive test result is incompatible.
6. JS code test method according to claim 4, which is characterized in that when the function of the target JS function When compatibility test result is incompatible, the letter that the target JS function is determined according to the function compatibility information Number compatibility test result, further includes:
Based on the compatible implementations of preset browsing device, the incompatible type of the function compatibility information, the incompatible class are determined Type includes the first incompatible type and the second incompatible type, and the first incompatible type is for characterizing the function compatibility The incompatible situation of information is completely incompatible, and the second incompatible type is for characterizing the function compatibility information not Compatible context is not exclusively compatible;
If the incompatible type of the function compatibility information is the described first incompatible type, by the target JS function Function compatibility results are determined as completely incompatible;
If the incompatible type of the function compatibility information is the described second incompatible type, the letter of the target JS function Number compatibility results are determined as incomplete compatibility.
7. JS code test method according to claim 1, which is characterized in that the JS code test method, further includes:
Obtain corresponding second configuration file of the JS code to be tested;
The syntax gauge of the JS code to be tested is tested based on second configuration file, obtains the JS code to be tested Code syntax normalization test result.
8. a kind of JS code tester device characterized by comprising
First configuration file obtains module, for obtaining JS code to be tested, and corresponding with the JS code to be tested the One configuration file;
First test result obtains module, opposite for testing the JS code to be tested simultaneously based on first configuration file In the compatibility of preset browsing device set, the code for code compatibility test result of the JS code to be tested is obtained.
9. a kind of electronic equipment, which is characterized in that filled including processor, memory and JS code tester according to any one of claims 8 It sets, the JS code tester device includes one or more software function for being stored in the memory and being executed by the processor It can module.
10. a kind of computer readable storage medium, is stored thereon with computer program, which is characterized in that the computer program It is performed, JS code test method described in any one of claim 1-7 may be implemented.
CN201811317347.3A 2018-11-06 2018-11-06 JS code testing method and device and electronic equipment Active CN109634844B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201811317347.3A CN109634844B (en) 2018-11-06 2018-11-06 JS code testing method and device and electronic equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201811317347.3A CN109634844B (en) 2018-11-06 2018-11-06 JS code testing method and device and electronic equipment

Publications (2)

Publication Number Publication Date
CN109634844A true CN109634844A (en) 2019-04-16
CN109634844B CN109634844B (en) 2023-12-22

Family

ID=66067321

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201811317347.3A Active CN109634844B (en) 2018-11-06 2018-11-06 JS code testing method and device and electronic equipment

Country Status (1)

Country Link
CN (1) CN109634844B (en)

Citations (11)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20010013043A1 (en) * 1998-03-12 2001-08-09 Richard J. Wagner System and method for determining browser package and version compatibility of a web document
CN102054100A (en) * 2010-12-17 2011-05-11 中国科学院计算技术研究所 Static analysis-based method and system for detecting RTL (Resistor Transistor Logic) design errors
US20110173589A1 (en) * 2010-01-13 2011-07-14 Microsoft Corporation Cross-Browser Interactivity Testing
US20120210236A1 (en) * 2011-02-14 2012-08-16 Fujitsu Limited Web Service for Automated Cross-Browser Compatibility Checking of Web Applications
CN103164213A (en) * 2011-12-19 2013-06-19 中国移动通信集团四川有限公司 Method, device and system of testing compatibility of Web browser
US20140201625A1 (en) * 2012-04-24 2014-07-17 Concepts in Data Management, SRL System and method for generating a browser compatible document
CN103942137A (en) * 2013-01-23 2014-07-23 腾讯科技(深圳)有限公司 Browser compatibility testing method and device
CN104156307A (en) * 2014-07-03 2014-11-19 安徽景行信息科技有限公司 Browser compatibility detecting method and system
CN107103237A (en) * 2016-02-23 2017-08-29 阿里巴巴集团控股有限公司 A kind of detection method and device of malicious file
CN107133165A (en) * 2017-03-22 2017-09-05 腾讯科技(深圳)有限公司 Browser compatibility detection method and device
CN107729249A (en) * 2017-10-18 2018-02-23 北京奇虎科技有限公司 Browser compatibility method of testing, device, system and electronic equipment

Patent Citations (11)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20010013043A1 (en) * 1998-03-12 2001-08-09 Richard J. Wagner System and method for determining browser package and version compatibility of a web document
US20110173589A1 (en) * 2010-01-13 2011-07-14 Microsoft Corporation Cross-Browser Interactivity Testing
CN102054100A (en) * 2010-12-17 2011-05-11 中国科学院计算技术研究所 Static analysis-based method and system for detecting RTL (Resistor Transistor Logic) design errors
US20120210236A1 (en) * 2011-02-14 2012-08-16 Fujitsu Limited Web Service for Automated Cross-Browser Compatibility Checking of Web Applications
CN103164213A (en) * 2011-12-19 2013-06-19 中国移动通信集团四川有限公司 Method, device and system of testing compatibility of Web browser
US20140201625A1 (en) * 2012-04-24 2014-07-17 Concepts in Data Management, SRL System and method for generating a browser compatible document
CN103942137A (en) * 2013-01-23 2014-07-23 腾讯科技(深圳)有限公司 Browser compatibility testing method and device
CN104156307A (en) * 2014-07-03 2014-11-19 安徽景行信息科技有限公司 Browser compatibility detecting method and system
CN107103237A (en) * 2016-02-23 2017-08-29 阿里巴巴集团控股有限公司 A kind of detection method and device of malicious file
CN107133165A (en) * 2017-03-22 2017-09-05 腾讯科技(深圳)有限公司 Browser compatibility detection method and device
CN107729249A (en) * 2017-10-18 2018-02-23 北京奇虎科技有限公司 Browser compatibility method of testing, device, system and electronic equipment

Non-Patent Citations (4)

* Cited by examiner, † Cited by third party
Title
CYNTRICA EATON: "Chapter 5 - A Framework for Detecting and Diagnosing Configuration Faults in Web Applications", ADVANCES IN COMPUTERS, vol. 85, pages 137 - 181 *
RUIFENG CHEN等: "A Selenium based approach to automatic test script generation for refactoring JavaScript code", 2013 IEEE/ACIS 12TH INTERNATIONAL CONFERENCE ON COMPUTER AND INFORMATION SCIENCE (ICIS), pages 341 - 346 *
王安娜: "基于MVC设计模式的源代码检测平台的设计与实现", 中国优秀硕士学位论文全文数据库 信息科技辑, no. 10, pages 138 - 29 *
程勇 等: "针对JavaScript浏览器兼容性的变异测试方法", 计算机应用, vol. 37, no. 4, pages 1143 - 1148 *

Also Published As

Publication number Publication date
CN109634844B (en) 2023-12-22

Similar Documents

Publication Publication Date Title
CN109976761B (en) Software development kit generation method and device and terminal equipment
CN105589805B (en) Method and device for generating code coverage rate report
CN107766040A (en) A kind of method, apparatus and computer-readable recording medium for generating interface document
CN105183592B (en) Method and apparatus for supporting performance evaluation
CN106294372A (en) Application program page quick access method and apply its mobile terminal
CN107678937A (en) Page compatibility detection method, device, server and medium
CN107729452B (en) Webpage loading method and device, electronic equipment and computer readable storage medium
EP3242214B1 (en) Method and device for protecting information of mcu chip
CN104915297B (en) A kind of automated testing method of the APP power consumption of android equipment
CN107729071B (en) A kind of method and device initializing network interface card
CN109240665A (en) Log recording method, device and electronic equipment
CN114153779B (en) I2C communication method, system, equipment and storage medium
US10387124B2 (en) System and method for creating domain specific language
CN108305053A (en) Implementation method, device, electronic equipment and the storage medium of approval process
CN109857387A (en) A kind of method and electronic equipment generating JAVA class object
CN108984328B (en) Stack backtracking method and device
CN110231907A (en) Display methods, electronic equipment, computer equipment and the medium of electronic reading
CN108023905A (en) Internet of things application system and method
CN109634844A (en) JS code test method, device and electronic equipment
CN104461603B (en) A kind of information processing method and electronic equipment
CN105739717B (en) Data inputting method and device
CN109271323A (en) Processing method, device, test equipment and the storage medium of page elements
CN109344083A (en) A kind of program debugging method, device, equipment and readable storage medium storing program for executing
CN108345791A (en) Processor security detection method, system and detection device
CN112506871B (en) Automated task management and log management method, system, electronic device and medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
TA01 Transfer of patent application right

Effective date of registration: 20231128

Address after: Room 03, 2nd Floor, Building A, No. 20 Haitai Avenue, Huayuan Industrial Zone (Huanwai), Binhai New Area, Tianjin, 300450

Applicant after: 3600 Technology Group Co.,Ltd.

Address before: 100088 room 112, block D, 28 new street, new street, Xicheng District, Beijing (Desheng Park)

Applicant before: BEIJING QIHOO TECHNOLOGY Co.,Ltd.

TA01 Transfer of patent application right
GR01 Patent grant
GR01 Patent grant