WO2019169761A1 - 自动化测试方法、装置及存储介质 - Google Patents

自动化测试方法、装置及存储介质 Download PDF

Info

Publication number
WO2019169761A1
WO2019169761A1 PCT/CN2018/089320 CN2018089320W WO2019169761A1 WO 2019169761 A1 WO2019169761 A1 WO 2019169761A1 CN 2018089320 W CN2018089320 W CN 2018089320W WO 2019169761 A1 WO2019169761 A1 WO 2019169761A1
Authority
WO
WIPO (PCT)
Prior art keywords
screenshot
error information
test
file
test case
Prior art date
Application number
PCT/CN2018/089320
Other languages
English (en)
French (fr)
Inventor
唐可
Original Assignee
平安科技(深圳)有限公司
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 平安科技(深圳)有限公司 filed Critical 平安科技(深圳)有限公司
Publication of WO2019169761A1 publication Critical patent/WO2019169761A1/zh

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3668Software testing
    • G06F11/3672Test management
    • G06F11/3688Test management for test execution, e.g. scheduling of test suites
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3668Software testing
    • G06F11/3672Test management
    • G06F11/3692Test management for test results analysis

Definitions

  • JAVA-based UI automation tests generally use the TestNG framework and use TestNG-based assertion methods to determine page elements and expected results.
  • the UI automated test if the verification of a checkpoint of the test case fails, the subsequent execution step interruption cannot be performed, the entire test case returns failure, and the integrity of the test cannot be guaranteed; and the test cannot be displayed intuitively and comprehensively.
  • the specific information when an error occurs in the process is not conducive to the tester to analyze the cause of the error.
  • the present application provides an automated test method, an electronic device, and a computer readable storage medium, the main purpose of which is to solve the problem that the error information in the test process cannot be accurately located due to the incomplete test process.
  • the present application provides an automated testing method, the method comprising:
  • S1 Receive an instruction to execute a test, and retrieve a test case from a class file, where the test case includes multiple steps, and adding one or more checkpoints after the multiple steps;
  • the error information is sequentially extracted from the string buffer to determine whether the error information is empty, and if it is empty, the error information is filtered out, and Extract the next error message, if it is not empty, the test case tag fails to execute;
  • the present application further provides an electronic device, the device comprising a memory, a processor, and an automatic test program program executable on the processor, the program being processed by the processor Any step of the automated test method as described above is implemented while the device is executing.
  • the present application further provides a computer readable storage medium having an automated test program stored thereon, which is executed by a processor to implement any of the automated test methods described above. step.
  • the automatic test method, the electronic device and the computer readable storage medium proposed by the present application 1.
  • the exception processing branch even if the checkpoint verification fails during the automatic test process, the execution of the subsequent steps is not affected.
  • the checkpoint verification fails, intercept the current page information, and display the corresponding screenshot in the corresponding error message of the test report, which helps the tester to quickly and accurately locate the error message during the test. And the cause of the error, improving the efficiency of the test.
  • FIG. 1 is a schematic diagram of a preferred embodiment of an electronic device of the present application.
  • FIG. 2 is a schematic diagram of a program module of the automated test program of FIG. 1;
  • FIG. 3 is a flow chart of a preferred embodiment of an automated test method of the present application.
  • the present application provides an automated test method applied to an electronic device 1.
  • FIG. 1 it is a schematic diagram of a preferred embodiment of the electronic device 1 of the present application.
  • the electronic device 1 may be a terminal device with a data processing function, such as a server, a smart phone, a tablet computer, a portable computer, a desktop computer, etc.
  • the server may be a rack server, a blade server, or a tower. Server or rack server.
  • the memory 11 can be used not only for storing application software and various types of data installed in the electronic device 1, such as an automated test program 10, a predetermined test case, an assertion method and a screenshot method pre-packaged in a base class, and a screenshot file.
  • a method or the like can also be used to temporarily store data that has been output or is about to be output.
  • the processor 12 may be a Central Processing Unit (CPU), controller, microcontroller, microprocessor or other data processing chip for running program code or processing stored in the memory 11. Data, such as automated test program 10, etc.
  • CPU Central Processing Unit
  • controller microcontroller
  • microprocessor or other data processing chip for running program code or processing stored in the memory 11.
  • Data such as automated test program 10, etc.
  • Communication bus 13 is used to implement connection communication between these components.
  • the network interface 14 can optionally include a standard wired interface, a wireless interface (such as a WI-FI interface), and is generally used to establish a communication connection between the electronic device 1 and other electronic devices.
  • a standard wired interface such as a WI-FI interface
  • Figure 1 shows only the electronic device 1 with components 11-14, but it should be understood that not all illustrated components may be implemented, and more or fewer components may be implemented instead.
  • the electronic device 1 may further include a user interface
  • the user interface may include a display, an input unit such as a keyboard, and the optional user interface may further include a standard wired interface and a wireless interface.
  • the display may be an LED display, a liquid crystal display, a touch liquid crystal display, and an Organic Light-Emitting Diode (OLED) touch device.
  • the display may also be referred to as a display screen or display unit for displaying information processed in the electronic device 1 and a user interface for displaying visualizations.
  • an automated test program 10 is stored in the memory 11.
  • the processor 12 implements the following steps when executing the automated test program 10 stored in the memory 11:
  • A1 Receive an instruction to execute a test, and retrieve a test case from a class file, where the test case includes multiple steps, and adding one or more checkpoints after the multiple steps;
  • A2 executing a step of the test case and obtaining an execution result, and after the step, there is a checkpoint, and the call assertion method verifies the execution result corresponding to the step, and obtains a verification result corresponding to the execution result;
  • the verification result is verification failure
  • the error information in the verification result is captured, and the error information is added to the string buffer area, and the screenshot method is called to take a screenshot of the current page according to the preset rule. Save the screenshot file and continue with the steps after the checkpoint;
  • the error information is sequentially extracted from the string buffer to determine whether the error information is empty, and if it is empty, the error information is filtered out, and Extract the next error message, if it is not empty, the test case tag fails to execute;
  • A5. Generate a test report based on the test results and screenshot files obtained by executing the test case.
  • the test is performed in accordance with the contents of the file configuration configured in advance using TestNG.xml.
  • multiple test cases can be pre-configured to be executed one by one in sequence, or multiple test cases can be pre-configured to execute concurrently. Selecting multiple test cases concurrently can speed up the automated test.
  • the time for executing the test can be preset to avoid the test operation during working hours. As an implementation manner, a preset time point (for example, 10:00 pm) is set in advance, and each time a preset time point is reached, the automatic test is started according to the pre-configured content, and the corresponding steps are performed.
  • the code of each test case directly reflects the multiple steps, the order of execution steps, the checkpoints added after the steps, and the assertion method called by each checkpoint.
  • the test case corresponding to the scenario includes multiple steps: account entry, verification code verification, login, etc., and different checkpoints may be added after different steps of the test case, for example, verifying the verification code. Is it correct, verify that the login is successful, etc.
  • each execution of the test case will result in an execution result.
  • a checkpoint is added after the step, the assertion corresponding to the checkpoint is called from the assertion method encapsulated in the base class.
  • the method verifies the execution result of the above steps, and obtains the verification result of the checkpoint according to whether the actual execution result is consistent with the expected execution result.
  • the login step is performed with a set of account matching verification data, the expected execution result of the checkpoint set after the step is successful, and if the actual execution result is inconsistent with the expected execution result, the check is performed.
  • the verification result of the point is that the verification fails. Otherwise, the verification result is that the verification is successful, that is, the verification is passed. It can be understood that when the verification result is that the verification is successful, the above steps are repeated, and the subsequent steps of the test case are continued, and the execution result of the subsequent steps is obtained and verified.
  • a plurality of sets of verification data are set for the above login step, including data matching the account and data of the account error.
  • the login operation is performed with a plurality of sets of verification data, and the execution results of the login operation are verified for the plurality of sets of verification data respectively.
  • assertTrue determine whether it is True
  • assertFalse determine whether it is false
  • assertSame determine whether the reference address is the same
  • assertNotSame determine whether the reference address is not the same
  • assertNull determine whether it is null
  • assertNotNull Determine whether it is not null
  • assertEquals determine whether it is equal, Object of type Object needs to implement the methodCode and equals method
  • assertNotEquals determine whether it is not equal
  • assertEqualsNoOrder determine whether to ignore the order and so on.
  • the process includes the following steps: first access the Baidu homepage, then input "xx" in the search box, click search, wait for 2s, print the latest title of the browser, and close the browser. Executing the above steps will get the actual execution result "Baidu, you will know”. A checkpoint is added after the step of "waiting for the latest title of the browser after waiting for 2 seconds", and the expected execution result of the checkpoint is "Baidu”.
  • the execution result is verified, and the actual execution result is inconsistent with the expected execution result, that is, the verification fails, and the verification result is: java.lang.assertionError:excepted[ Baidu] but found [Baidu, you will know].
  • the assertion method invoked by the checkpoint is assertEquals, which determines whether the actual verification result is consistent with the expected verification result. If it is inconsistent, the verification fails. Testers can choose different assertion methods for different checkpoints according to actual conditions, and flexibly use various assertion methods to make test cases more robust.
  • the error information of the checkpoint is captured from the verification result, and the error information is added to the string buffer area for subsequent extraction of the error information.
  • the string buffer may contain multiple error information, and the multiple error information is sequentially added to the chronological order in which the verification fails.
  • the process enters the exception handling branch, and the screenshot method is called from the base class to take a screenshot of the page at the moment when the verification fails.
  • the screenshot method is used to intercept the screen image by using the browser driver, and the screenshot file is generated.
  • the screenshot file directory is allocated to the screenshot file.
  • the screenshot file directory is composed by a global variable root directory (for example, uiSupport) + a call execution class file name (for example, baseAPI.API) + a call method name (for example, waitElement), for example, uiSupport.baseAPI.API.waitElement Copying the screenshot file to the directory by means of file copying, determining the save address of the screenshot file; and then obtaining the time point at which the screenshot action occurs, including year, month, day, hour, minute, second, and Format the output as the name of the screenshot file, for example, 20171107_1848.
  • the hook method is also added to the screenshot method. If the screenshot fails, the error message is caught and thrown, and the execution of the subsequent steps is not hindered. For example, the browser driver cannot intercept the screen image, directly grabs and throws the error message, and continues to perform subsequent operations. At this point, all the error information in the verification result has been added to the string buffer.
  • the flag failure method extracts the error information from the character buffer area
  • the error information with the earlier time is preferentially extracted, and it is determined whether the error information is empty. If it is not empty, the corresponding check point may be found according to the error information. If the verification fails, the test fails to execute the test. If it is empty, the error message is filtered out and the next error message is taken.
  • the tag failure method extracts an error message from the string buffer, and the error message extracted in the string buffer is deleted until there is no error message in the string buffer. At this point, the test is over.
  • test report is generated.
  • a listener is added in the class file in advance, and the listener is referenced to monitor the verification result in the automatic test process.
  • a report listener is added in the TestNG.xml file to extract the listener added in the class file, and obtain The information it listens to and restores in the report and displays an error message that the verification failed.
  • the number of successful verifications and verification failures is counted separately.
  • the error information of each checkpoint and the corresponding specific content are respectively listed, including: global variable, class file name, calling method, etc., and corresponding to the specific content of each error information, determine corresponding The screenshot file directory, and the corresponding screenshot file is extracted from the screenshot file directory and displayed in the test report.
  • the electronic device 1 of the above embodiment by adding an exception processing branch, causes the checkpoint to intercept the current page information after the verification fails, and displays the screenshot in the corresponding position of the test report, which helps the tester to quickly and accurately locate the test process.
  • the error message and the cause of the error at the same time, even if the verification fails, the execution of the subsequent steps is not affected, and the test efficiency is improved.
  • the automated test program 10 may also be divided into one or more modules, one or more modules being stored in the memory 11 and being processed by one or more processors (this embodiment) Executed for processor 12) to accomplish the present application, a module referred to herein refers to a series of computer program instructions that are capable of performing a particular function.
  • FIG. 2 it is a schematic diagram of a program module of the automated test program 10 in FIG. 1.
  • the automated test program 10 can be divided into a receiving module 110, a verification module 120, a capture module 130, and a marking module 140.
  • the generating module 150, the functions or operating steps implemented by the modules 110-150 are similar to the above, and are not described in detail herein, for example, where:
  • the verification module 120 is configured to execute a step of the test case and obtain an execution result.
  • the checkpoint method is used to verify the execution result corresponding to the step, and the verification result corresponding to the execution result is obtained. ;
  • the capture module 130 is configured to: when the verification result is a verification failure, grab the error information in the verification result, add the error information to the string buffer, and invoke the screenshot method to take a screenshot of the current page. , save the screenshot file according to the preset rule, and continue to perform the steps after the checkpoint;
  • the marking module 140 when all the steps of the test case have been executed, sequentially extract the error information from the string buffer to determine whether the error information is empty, and if it is empty, filter the error information. And extracting the next error message, if not empty, the execution of the test case tag fails;
  • the generating module 150 is configured to generate a test report according to the test result and the screenshot file obtained by executing the test case.
  • the present application also provides an automated test method.
  • FIG 3 there is shown a flow chart of a preferred embodiment of the automated test method of the present application.
  • the method can be performed by a device that can be implemented by software and/or hardware.
  • the automated test method includes steps S1-S5:
  • S1 Receive an instruction to execute a test, and retrieve a test case from a class file, where the test case includes multiple steps, and adding one or more checkpoints after the multiple steps;
  • the error information is sequentially extracted from the string buffer to determine whether the error information is empty, and if it is empty, the error information is filtered out, and Extract the next error message, if it is not empty, the test case tag fails to execute;
  • the test is performed in accordance with the contents of the file configuration configured in advance using TestNG.xml.
  • a plurality of test cases can be pre-configured to be executed one by one in sequence, or multiple test cases can be pre-configured to execute concurrently. Selecting multiple test cases concurrently can speed up the automated test.
  • the time for executing the test can be preset to avoid the test operation during working hours. As an implementation manner, a preset time point (for example, 10:00 pm) is set in advance, and each time a preset time point is reached, the automatic test is started according to the pre-configured content, and the corresponding steps are performed.
  • the code of each test case directly reflects the multiple steps, the order of execution steps, the checkpoints added after the steps, and the assertion method called by each checkpoint.
  • the test case corresponding to the scenario includes multiple steps: account entry, verification code verification, login, etc., and different checkpoints may be added after different steps of the test case, for example, verifying the verification code. Is it correct, verify that the login is successful, etc.
  • each execution of the test case will result in an execution result.
  • a checkpoint is added after the step, the assertion corresponding to the checkpoint is called from the assertion method encapsulated in the base class.
  • the method verifies the execution result of the above steps, and obtains the verification result of the checkpoint according to whether the actual execution result is consistent with the expected execution result.
  • the login step is performed with a set of account matching verification data, the expected execution result of the checkpoint set after the step is successful, and if the actual execution result is inconsistent with the expected execution result, the check is performed.
  • the verification result of the point is that the verification fails. Otherwise, the verification result is that the verification is successful, that is, the verification is passed. It can be understood that when the verification result is that the verification is successful, the above steps are repeated, and the subsequent steps of the test case are continued, and the execution result of the subsequent steps is obtained and verified.
  • a plurality of sets of verification data are set for the above login step, including data matching the account and data of the account error.
  • the login operation is performed with a plurality of sets of verification data, and the execution results of the login operation are verified for the plurality of sets of verification data respectively.
  • assertTrue determine whether it is True
  • assertFalse determine whether it is false
  • assertSame determine whether the reference address is the same
  • assertNotSame determine whether the reference address is not the same
  • assertNull determine whether it is null
  • assertNotNull Determine whether it is not null
  • assertEquals determine whether it is equal, Object of type Object needs to implement the methodCode and equals method
  • assertNotEquals determine whether it is not equal
  • assertEqualsNoOrder determine whether to ignore the order and so on.
  • the execution result is verified, and the actual execution result is inconsistent with the expected execution result, that is, the verification fails, and the verification result is: java.lang.assertionError:excepted[ Baidu] but found [Baidu, you will know].
  • the assertion method invoked by the checkpoint is assertEquals, which determines whether the actual verification result is consistent with the expected verification result. If it is inconsistent, the verification fails. Testers can choose different assertion methods for different checkpoints according to actual conditions, and flexibly use various assertion methods to make test cases more robust.
  • the error information of the checkpoint is captured from the verification result, and the error information is added to the string buffer area for subsequent extraction of the error information.
  • the string buffer may contain multiple error information, and the multiple error information is sequentially added to the chronological order in which the verification fails.
  • the process enters the exception handling branch, and the screenshot method is called from the base class to take a screenshot of the page at the moment when the verification fails.
  • the screenshot method is used to intercept the screen image by using the browser driver, and the screenshot file is generated.
  • the screenshot file directory is allocated to the screenshot file.
  • the screenshot file directory is composed by a global variable root directory (for example, uiSupport) + a call execution class file name (for example, baseAPI.API) + a call method name (for example, waitElement), for example, uiSupport.baseAPI.API.waitElement Copying the screenshot file to the directory by means of file copying, determining the save address of the screenshot file; and then obtaining the time point at which the screenshot action occurs, including year, month, day, hour, minute, second, and Format the output as the name of the screenshot file, for example, 20171107_1848.
  • the hook method is also added to the screenshot method. If the screenshot fails, the error message is caught and thrown, and the execution of the subsequent steps is not hindered. For example, the browser driver cannot intercept the screen image, directly grabs and throws the error message, and continues to perform subsequent operations. At this point, all the error information in the verification result has been added to the string buffer.
  • the flag failure method extracts the error information from the character buffer area
  • the error information with the earlier time is preferentially extracted, and it is determined whether the error information is empty. If it is not empty, the corresponding check point may be found according to the error information. If the verification fails, the test fails to execute the test. If it is empty, the error message is filtered out and the next error message is taken.
  • the tag failure method extracts an error message from the string buffer, and the error message extracted in the string buffer is deleted until there is no error message in the string buffer. At this point, the test is over.
  • test report is generated.
  • a listener is added in the class file in advance, and the listener is referenced to monitor the verification result in the automatic test process.
  • a report listener is added in the TestNG.xml file to extract the listener added in the class file, and obtain The information it listens to and restores in the report and displays an error message that the verification failed.
  • the number of successful verifications and verification failures is counted separately.
  • the error information of each checkpoint and the corresponding specific content are respectively listed, including: global variable, class file name, calling method, etc., and corresponding to the specific content of each error information, determine corresponding The screenshot file directory, and the corresponding screenshot file is extracted from the screenshot file directory and displayed in the test report.
  • the automated test method proposed by the above embodiment adds the exception processing branch, so that the checkpoint intercepts the current page information after the verification fails, and displays the screenshot in the corresponding position of the test report, which helps the tester to quickly and accurately locate the test process.
  • the error message and the cause of the error at the same time, even if the verification fails, the execution of the subsequent steps is not affected, and the test efficiency is improved.
  • the embodiment of the present application further provides a computer readable storage medium, where the computer readable storage medium stores an automated test program 10, and when the program is executed by the processor, the following operations are implemented:
  • A1 Receive an instruction to execute a test, and retrieve a test case from a class file, where the test case includes multiple steps, and adding one or more checkpoints after the multiple steps;
  • A2 executing a step of the test case and obtaining an execution result, and after the step, there is a checkpoint, and the call assertion method verifies the execution result corresponding to the step, and obtains a verification result corresponding to the execution result;
  • the verification result is verification failure
  • the error information in the verification result is captured, and the error information is added to the string buffer area, and the screenshot method is called to take a screenshot of the current page according to the preset rule. Save the screenshot file and continue with the steps after the checkpoint;
  • the error information is sequentially extracted from the string buffer to determine whether the error information is empty, and if it is empty, the error information is filtered out, and Extract the next error message, if it is not empty, the test case tag fails to execute;
  • A5. Generate a test report based on the test results and screenshot files obtained by executing the test case.
  • the technical solution of the present application which is essential or contributes to the prior art, may be embodied in the form of a software product stored in a storage medium (such as ROM/RAM as described above). , a disk, an optical disk, including a number of instructions for causing a terminal device (which may be a mobile phone, a computer, a server, or a network device, etc.) to perform the methods described in the various embodiments of the present application.
  • a terminal device which may be a mobile phone, a computer, a server, or a network device, etc.

Landscapes

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

Abstract

一种自动化测试方法,包括:接收执行测试的指令并调取测试用例;执行所述测试用例的步骤,当所述步骤之后存在检查点,对执行结果进行验证;当验证失败时,抓取验证结果中的错误信息,添加至字符串缓存区中,对当前页面进行截图,并执行所述检查点之后的步骤;当所述测试用例的步骤已全部被执行时,依次从字符串缓存区中摘取所述错误信息,判断所述错误信息是否为空,若为空则过滤掉该条错误信息,并摘取下一条错误信息,若不为空则对所述测试用例标记执行失败;生成测试报告。还提出一种电子装置及存储介质。该方法保证了测试的完整性,有助于测试人员快速定位错误信息及错误原因,提高了测试效率。

Description

自动化测试方法、装置及存储介质
本申请基于巴黎公约申明享有2018年3月6日递交的申请号为CN201810184610.X、名称为“自动化测试方法、装置及存储介质”的中国专利申请的优先权,该中国专利申请的整体内容以参考的方式结合在本申请中。
技术领域
本申请涉及计算机技术领域,尤其涉及一种自动化测试方法、电子装置及计算机可读存储介质。
背景技术
目前基于JAVA的UI自动化测试普遍使用的是TestNG框架,并且使用基于TestNG的断言方法,用于判断页面元素和预期结果。然而在UI自动化测试时,如果测试用例的某个检查点验证失败,会导致后续执行步骤中断无法执行,整个测试用例返回失败,无法保证测试的完整性;并且不能直观地、全面地展示出测试过程中发生错误时的具体信息,不利于测试人员分析错误原因。
发明内容
本申请提供一种自动化测试方法、电子装置及计算机可读存储介质,其主要目的在于解决因测试过程不完整造成的无法准确定位测试过程中的错误信息的问题。
为实现上述目的,本申请提供一种自动化测试方法,该方法包括:
S1、接收执行测试的指令,从类文件中调取测试用例,所述测试用例包含多个步骤,在所述多个步骤之后添加一个或多个检查点;
S2、执行所述测试用例的一个步骤并得到执行结果,当所述步骤之后存在检查点,调用断言方法对所述步骤对应的执行结果进行验证,得到该执行结果对应的验证结果;
S3、当所述验证结果为验证失败时,抓取所述验证结果中的错误信息,并将所述错误信息添加至字符串缓存区中,调用截图方法对当前页面进行截图,按照预设规则保存截图文件,并继续执行所述检查点之后的步骤;
S4、当所述测试用例的步骤已全部被执行时,依次从字符串缓存区中摘取所述错误信息,判断所述错误信息是否为空,若为空则过滤掉该条错误信息,并摘取下一条错误信息,若不为空则对所述测试用例标记执行失败;及
S5、根据执行测试用例得到的测试结果及截图文件,生成测试报告。
此外,为实现上述目的,本申请还提供一种电子装置,该装置包括存储器、处理器,所述存储器上存储有可在所述处理器上运行的自动化测试程序程序,该程序被所述处理器执行时实现如上所述的自动化测试方法的任意步骤。
此外,为实现上述目的,本申请还提供一种计算机可读存储介质,所述计算机可读存储介质上存储有自动化测试程序,该程序被处理器执行时实现如上所述的自动化测试方法的任意步骤。
相较于现有技术,本申请提出的自动化测试方法、电子装置及计算机可读存储介质,1.通过加入异常处理分支,即使在自动化测试过程中检查点验证失败,也不影响后续步骤的执行,保证了测试的完整性;2.检查点验证失败时,截取当前页面信息,并在测试报告的相应的错误信息处展示对应的截图,有助于测试人员快速精准定位测试过程中的错误信息及错误原因,提高了测试效率。
附图说明
图1为本申请电子装置较佳实施例的示意图;
图2为图1中自动化测试程序的程序模块示意图;
图3为本申请自动化测试方法较佳实施例的流程图。
本申请目的的实现、功能特点及优点将结合实施例,参照附图做进一步说明。
具体实施方式
应当理解,此处所描述的具体实施例仅仅用以解释本申请,并不用于限 定本申请。
本申请提供一种自动化测试方法,该方法应用于一种电子装置1。参照图1所示,为本申请电子装置1较佳实施例的示意图。
在本实施例中,电子装置1可以是服务器、智能手机、平板电脑、便携计算机、桌上型计算机等具有数据处理功能的终端设备,所述服务器可以是机架式服务器、刀片式服务器、塔式服务器或机柜式服务器。
该电子装置1包括存储器11、处理器12,通信总线13,以及网络接口14。
其中,存储器11至少包括一种类型的可读存储介质,所述可读存储介质包括闪存、硬盘、多媒体卡、卡型存储器(例如,SD或DX存储器等)、磁性存储器、磁盘、光盘等。存储器11在一些实施例中可以是所述电子装置1的内部存储单元,例如该电子装置1的硬盘。存储器11在另一些实施例中也可以是所述电子装置1的外部存储设备,例如该电子装置1上配备的插接式硬盘,智能存储卡(Smart Media Card,SMC),安全数字(Secure Digital,SD)卡,闪存卡(Flash Card)等。进一步地,存储器11还可以既包括该电子装置1的内部存储单元也包括外部存储设备。存储器11不仅可以用于存储安装于该电子装置1的应用软件及各类数据,例如自动化测试程序10、预先确定的测试用例、预先封装在基础类中的断言方法及截图方法、保存截图文件的方法等,还可以用于暂时地存储已经输出或者将要输出的数据。
处理器12在一些实施例中可以是一中央处理器(Central Processing Unit,CPU)、控制器、微控制器、微处理器或其他数据处理芯片,用于运行存储器11中存储的程序代码或处理数据,例如自动化测试程序10等。
通信总线13用于实现这些组件之间的连接通信。
网络接口14可选的可以包括标准的有线接口、无线接口(如WI-FI接口),通常用于在该电子装置1与其他电子设备之间建立通信连接。
图1仅示出了具有组件11-14的电子装置1,但是应理解的是,并不要求实施所有示出的组件,可以替代的实施更多或者更少的组件。
可选地,该电子装置1还可以包括用户接口,用户接口可以包括显示器(Display)、输入单元比如键盘(Keyboard),可选的用户接口还可以包括标准的有线接口、无线接口。
可选地,在一些实施例中,显示器可以是LED显示器、液晶显示器、触控式液晶显示器以及有机发光二极管(Organic Light-Emitting Diode,OLED)触摸器等。其中,显示器也可以称为显示屏或显示单元,用于显示在电子装置1中处理的信息以及用于显示可视化的用户界面。
在图1所示的装置实施例中,存储器11中存储有自动化测试程序10。处理器12执行存储器11中存储的自动化测试程序10时实现如下步骤:
A1、接收执行测试的指令,从类文件中调取测试用例,所述测试用例包含多个步骤,在所述多个步骤之后添加一个或多个检查点;
A2、执行所述测试用例的一个步骤并得到执行结果,当所述步骤之后存在检查点,调用断言方法对所述步骤对应的执行结果进行验证,得到该执行结果对应的验证结果;
A3、当所述验证结果为验证失败时,抓取所述验证结果中的错误信息,并将所述错误信息添加至字符串缓存区中,调用截图方法对当前页面进行截图,按照预设规则保存截图文件,并继续执行所述检查点之后的步骤;
A4、当所述测试用例的步骤已全部被执行时,依次从字符串缓存区中摘取所述错误信息,判断所述错误信息是否为空,若为空则过滤掉该条错误信息,并摘取下一条错误信息,若不为空则对所述测试用例标记执行失败;及
A5、根据执行测试用例得到的测试结果及截图文件,生成测试报告。
本实施例中,针对某个对象进行自动化测试之前,首先需要确定具体的测试目的,并根据测试目的及对应的场景确定测试用例的范围及具体内容,例如,执行测试用例中的每一个操作步骤。然后,根据测试的需求或者测试重点,在执行某一操作步骤之后添加检查点(或者,断言点),对执行结果进行验证。同时,在测试用例各检查点之后增加异常处理分支,将测试用例的文件写入类文件中。同时,通过TestNG.xml执行文件,配置执行本次测试需要执行的类文件、测试用例、执行的方法及调用的监听器等。
当电子装置1接收到开始执行测试的指令时,按照预先利用TestNG.xml执行文件配置的内容进行测试。首先,从类文件中调用需要执行的测试用例,然后按照配置的执行顺序及执行方式选择测试用例,并执行测试用例中操作步骤。可以理解的是,可以预先配置多个测试用例按照先后顺序被一一执行, 也可以预先配置多个测试用例并发执行,选择多个测试用例并发执行可以加快自动化测试速度。在其他实施例中,为了节省时间及资源,可以预设执行测试的时间,避免在工作时间进行测试操作。作为一种实施方式,预先设置一个预设时间点(例如,下午10:00),每到预设时间点,开始按照预先配置的内容进行自动化测试,并执行相应的步骤。
具体的,每个测试用例的代码直接反应了多个步骤、执行步骤的先后顺序、步骤之后添加的检查点及每个检查点调用的断言方法。例如,以登录场景为例,该场景对应的测试用例包括多个步骤:账密输入、验证码验证、登录等,可在该测试用例的不同步骤之后加入不同的检查点,例如,验证验证码是否正确,验证登录是否成功等。
当执行该测试用例时,每执行完该测试用例的一个步骤,会得到一个执行结果,若该步骤之后添加了检查点,则从封装在基础类中的断言方法中调用该检查点对应的断言方法对上述步骤的执行结果进行验证,并根据实际执行结果与预期执行结果是否一致得到该检查点的验证结果。以上述登录步骤为例,若以一组账密相符的验证数据执行该登录步骤,该步骤之后设置的检查点的预期执行结果为成功,若实际执行结果与预期执行结果不一致,则说明该检查点的验证结果为验证失败,否则,验证结果为验证成功,也就是验证通过。可以理解的是,当验证结果为验证成功,重复上述步骤,继续执行该测试用例的后续步骤,得到执行后续步骤的执行结果,并对其进行验证。
进一步地,在测试过程中,若只采用一组验证数据执行该测试用例的某步骤,对得到的执行结果进行验证,可能出现验证结果不严谨的问题。在其他实施例中,为了避免因数据覆盖面不够广可能造成的问题,为关键步骤设置多组验证数据,并依次采用所述多组验证数据执行该关键步骤,并对执行结果进行验证,使验证结果更严谨、真实。针对上述登录步骤设置多组验证数据,其中,包括账密相符的数据及账密错误的数据等。以多组验证数据执行该登录操作,并分别对上述多组验证数据执行该登录操作的执行结果进行验证。
具体地,TestNG中常用的断言方法有:assertTrue:判断是否为True;assertFalse:判断是否为false;assertSame:判断引用地址是否相同; assertNotSame:判断引用地址是否不相同;assertNull:判断是否为null;assertNotNull:判断是否不为null;assertEquals:判断是否相等,Object类型的对象需要实现haseCode及equals方法;assertNotEquals:判断是否不相等;assertEqualsNoOrder:判断忽略顺序是否相等等方法。将上述断言方法封装在基础类中,供后续对执行各个检查点时调用。
以打开浏览器的流程为例,该流程包括以下步骤:首先访问百度首页,然后在搜索框输入“xx”,点击搜索,等待2s后打印浏览器最新的标题,关闭浏览器。执行上述步骤会得到实际的执行结果“百度一下,你就知道”。在“等待2s后打印浏览器最新的标题”的步骤之后添加检查点,该检查点预期的执行结果为“百度”。在执行完“等待2s后打印浏览器最新的标题”的步骤后,对执行结果进行验证,发现实际执行结果与预期执行结果不一致,即验证失败,验证结果为:java.lang.assertionError:excepted[百度]but found[百度一下,你就知道]。该检查点调用的断言方法为assertEquals,判断实际验证结果是否与预期验证结果一致,若不一致,则验证失败。测试人员可根据实际情况为不同的检查点选择不同的断言方法,灵活使用各种断言方法,才能使测试用例更加健壮。
当上述检查点的验证结果为验证失败时,从验证结果中抓取该检查点的错误信息,将错误信息添加至字符串缓存区中,以供后续摘取错误信息。需要说明的是,执行测试用例时可能出现多处检查点验证失败的情况,因此字符串缓存区中可能包含多个错误信息,所述多个错误信息按照发生验证失败的时间先后顺序依次添加至字符串缓存区。然后,流程进入异常处理分支,从基础类中调用截图方法,对出现验证失败这一时刻的页面进行截图。
具体地,调用截图方法使用浏览器驱动进行截取屏幕影像的操作,生成截图文件,根据截图文件中包含的该检查点及该检查点对应步骤的实际内容,对该截图文件进行截图文件目录分配,所述截图文件目录通过全局变量根目录(例如,uiSupport)+调用执行类文件名(例如,baseAPI.API)+调用方法名(例如,waitElement)组合而成,例如,uiSupport.baseAPI.API.waitElement,通过文件复制的方法将所述截图文件复制到该目录中,确定该截图文件的保存地址;然后获取截图动作发生的时间点,包括年、月、日、时、分、秒, 并以预设格式输出,作为截图文件的名称,如,20171107_1848。
需要说明的是,在自动化测试过程中,可能出现在同一秒发生多次截图操作的情况,若按照上述命名步骤对截图文件进行命名,会出现不同截图文件重名的情况。在其他实施例中,为了防止在同一时刻截图生成的截图文件重名,在上述精确到秒的时间点后加入一个递增变量,并为截图文件生成唯一的文件名,例如,在某一秒同时有5次截图,获取这5次截图动作发生的时间信息(精确到毫秒),根据5次截图动作的先后顺序分别为该5个截图文件名称后加一个1-5的递增变量,最终使截图文件分别归属至相应的截图文件目录中,并以时间点+递增变量+.jpg的形式进行命名,如,20171107_1848_4。
通过在检查点的验证步骤后加入截图的异常处理分支,使检查点验证失败时立即进行屏幕截图,有助于还原并展示发生错误时的页面信息。
当截图动作完成并成功保存截图文件后,若还有未被执行的步骤,继续执行未被执行的步骤,并重复上述步骤,直到所有测试用例的所有步骤均执行完毕,例如,上述“打开浏览器的流程”的例子中的“关闭浏览器”的步骤。在其他实施例中,所述截图方法中也加入了异常分支,如果截图失败,则抓住并抛出错误信息,不阻碍后续步骤的执行。例如,浏览器驱动无法进行截取屏幕影像的操作,直接抓取并抛出该错误信息,并继续执行后续操作。至此,已将验证结果中的所有错误信息添加至字符串缓存区中。
当标记失败方法从字符缓存区中摘取错误信息时,优先摘取时间较早的错误信息,并判断所述错误信息是否为空,若不为空,则可根据错误信息找到相应的检查点并标记验证失败,对该测试用例标记执行测试失败;若为空,则过滤掉该错误信息,继续摘取下一条错误信息。另外,标记失败方法每从字符串缓存区中摘取出一条错误信息,字符串缓存区中被摘取的该条错误信息会被删除,直到所述字符串缓存区中没有错误信息为止。至此,测试结束。
当测试结束后,提取类文件中监听器监听到的测试结果,生成测试报告。具体地,预先在类文件中添加监听器,引用该监听器监听自动化测试过程中的验证结果,同时,在TestNG.xml文件中加入报告监听器,用于提取类文件中添加的监听器,获取其监听到的信息,并在报告中还原并展示验证失败的 错误信息。在生成测试报告的过程中,分别统计验证成功及验证失败的次数。对于验证失败的检查点,分别列出每个检查点的错误信息及对应的具体内容,包括:全局变量、类文件名、调用方法等,并根据每条错误信息的具体内容,确定与之对应的截图文件目录,并从该截图文件目录中摘取出相应的截图文件,展示在测试报告中。使测试人员更直观的了解测试过程中发生错误的具体原因。
上述实施例提出的电子装置1,通过加入异常处理分支,使检查点在验证失败后截取当前页面信息,并在测试报告的相应位置展示该截图,有助于测试人员快速精准定位测试过程中的错误信息及错误原因;同时,即使验证失败也不影响后续步骤的执行,提高了测试效率。
可选地,在其他的实施例中,自动化测试程序10还可以被分割为一个或者多个模块,一个或者多个模块被存储于存储器11中,并由一个或多个处理器(本实施例为处理器12)所执行,以完成本申请,本申请所称的模块是指能够完成特定功能的一系列计算机程序指令段。例如,参照图2所示,为图1中自动化测试程序10的程序模块示意图,该实施例中,自动化测试程序10可以被分割为接收模块110、验证模块120、抓取模块130、标记模块140及生成模块150,所述模块110-150所实现的功能或操作步骤均与上文类似,此处不再详述,示例性地,例如其中:
接收模块110,用于接收执行测试的指令,从类文件中调取测试用例,所述测试用例包含多个步骤,在所述多个步骤之后添加一个或多个检查点;
验证模块120,用于执行所述测试用例的一个步骤并得到执行结果,当所述步骤之后存在检查点,调用断言方法对所述步骤对应的执行结果进行验证,得到该执行结果对应的验证结果;
抓取模块130,用于当所述验证结果为验证失败时,抓取所述验证结果中的错误信息,并将所述错误信息添加至字符串缓存区中,调用截图方法对当前页面进行截图,按照预设规则保存截图文件,并继续执行所述检查点之后的步骤;
标记模块140,当所述测试用例的步骤已全部被执行时,依次从字符串缓存区中摘取所述错误信息,判断所述错误信息是否为空,若为空则过滤掉该 条错误信息,并摘取下一条错误信息,若不为空则对所述测试用例标记执行失败;及
生成模块150,用于根据执行测试用例得到的测试结果及截图文件,生成测试报告。
此外,本申请还提供一种自动化测试方法。参照图3所示,为本申请自动化测试方法较佳实施例的流程图。该方法可以由一个装置执行,该装置可以由软件和/或硬件实现。
在本实施例中,自动化测试方法包括步骤S1-S5:
S1、接收执行测试的指令,从类文件中调取测试用例,所述测试用例包含多个步骤,在所述多个步骤之后添加一个或多个检查点;
S2、执行所述测试用例的一个步骤并得到执行结果,当所述步骤之后存在检查点,调用断言方法对所述步骤对应的执行结果进行验证,得到该执行结果对应的验证结果;
S3、当所述验证结果为验证失败时,抓取所述验证结果中的错误信息,并将所述错误信息添加至字符串缓存区中,调用截图方法对当前页面进行截图,按照预设规则保存截图文件,并继续执行所述检查点之后的步骤;
S4、当所述测试用例的步骤已全部被执行时,依次从字符串缓存区中摘取所述错误信息,判断所述错误信息是否为空,若为空则过滤掉该条错误信息,并摘取下一条错误信息,若不为空则对所述测试用例标记执行失败;及
S5、根据执行测试用例得到的测试结果及截图文件,生成测试报告。
本实施例中,针对某个对象进行自动化测试之前,首先需要确定具体的测试目的,并根据测试目的及对应的场景确定测试用例的范围及具体内容,例如,执行测试用例中的每一个操作步骤。然后,根据测试的需求或者测试重点,在执行某一操作步骤之后添加检查点(或者,断言点),对执行结果进行验证。同时,在测试用例各检查点之后增加异常处理分支,将测试用例的文件写入类文件中。同时,通过TestNG.xml执行文件,配置执行本次测试需要执行的类文件、测试用例、执行的方法及调用的监听器等。
当电子装置接收到开始执行测试的指令时,按照预先利用TestNG.xml执行文件配置的内容进行测试。首先,从类文件中调用需要执行的测试用例, 然后按照配置的执行顺序及执行方式选择测试用例,并执行测试用例中操作步骤。可以理解的是,可以预先配置多个测试用例按照先后顺序被一一执行,也可以预先配置多个测试用例并发执行,选择多个测试用例并发执行可以加快自动化测试速度。在其他实施例中,为了节省时间及资源,可以预设执行测试的时间,避免在工作时间进行测试操作。作为一种实施方式,预先设置一个预设时间点(例如,下午10:00),每到预设时间点,开始按照预先配置的内容进行自动化测试,并执行相应的步骤。
具体的,每个测试用例的代码直接反应了多个步骤、执行步骤的先后顺序、步骤之后添加的检查点及每个检查点调用的断言方法。例如,以登录场景为例,该场景对应的测试用例包括多个步骤:账密输入、验证码验证、登录等,可在该测试用例的不同步骤之后加入不同的检查点,例如,验证验证码是否正确,验证登录是否成功等。
当执行该测试用例时,每执行完该测试用例的一个步骤,会得到一个执行结果,若该步骤之后添加了检查点,则从封装在基础类中的断言方法中调用该检查点对应的断言方法对上述步骤的执行结果进行验证,并根据实际执行结果与预期执行结果是否一致得到该检查点的验证结果。以上述登录步骤为例,若以一组账密相符的验证数据执行该登录步骤,该步骤之后设置的检查点的预期执行结果为成功,若实际执行结果与预期执行结果不一致,则说明该检查点的验证结果为验证失败,否则,验证结果为验证成功,也就是验证通过。可以理解的是,当验证结果为验证成功,重复上述步骤,继续执行该测试用例的后续步骤,得到执行后续步骤的执行结果,并对其进行验证。
进一步地,在测试过程中,若只采用一组验证数据执行该测试用例的某步骤,对得到的执行结果进行验证,可能出现验证结果不严谨的问题。在其他实施例中,为了避免因数据覆盖面不够广可能造成的问题,为关键步骤设置多组验证数据,并依次采用所述多组验证数据执行该关键步骤,并对执行结果进行验证,使验证结果更严谨、真实。针对上述登录步骤设置多组验证数据,其中,包括账密相符的数据及账密错误的数据等。以多组验证数据执行该登录操作,并分别对上述多组验证数据执行该登录操作的执行结果进行验证。
具体地,TestNG中常用的断言方法有:assertTrue:判断是否为True;assertFalse:判断是否为false;assertSame:判断引用地址是否相同;assertNotSame:判断引用地址是否不相同;assertNull:判断是否为null;assertNotNull:判断是否不为null;assertEquals:判断是否相等,Object类型的对象需要实现haseCode及equals方法;assertNotEquals:判断是否不相等;assertEqualsNoOrder:判断忽略顺序是否相等等方法。将上述断言方法封装在基础类中,供后续对执行各个检查点时调用。
以打开浏览器的流程为例,该流程包括以下步骤:首先访问百度首页,然后在搜索框输入“xx”,点击搜索,等待2s后打印浏览器最新的标题,关闭浏览器。执行上述步骤会得到实际的执行结果“百度一下,你就知道”。在“等待2s后打印浏览器最新的标题”的步骤之后添加检查点,该检查点预期的执行结果为“百度”。在执行完“等待2s后打印浏览器最新的标题”的步骤后,对执行结果进行验证,发现实际执行结果与预期执行结果不一致,即验证失败,验证结果为:java.lang.assertionError:excepted[百度]but found[百度一下,你就知道]。该检查点调用的断言方法为assertEquals,判断实际验证结果是否与预期验证结果一致,若不一致,则验证失败。测试人员可根据实际情况为不同的检查点选择不同的断言方法,灵活使用各种断言方法,才能使测试用例更加健壮。
当上述检查点的验证结果为验证失败时,从验证结果中抓取该检查点的错误信息,将错误信息添加至字符串缓存区中,以供后续摘取错误信息。需要说明的是,执行测试用例时可能出现多处检查点验证失败的情况,因此字符串缓存区中可能包含多个错误信息,所述多个错误信息按照发生验证失败的时间先后顺序依次添加至字符串缓存区。然后,流程进入异常处理分支,从基础类中调用截图方法,对出现验证失败这一时刻的页面进行截图。
具体地,调用截图方法使用浏览器驱动进行截取屏幕影像的操作,生成截图文件,根据截图文件中包含的该检查点及该检查点对应步骤的实际内容,对该截图文件进行截图文件目录分配,所述截图文件目录通过全局变量根目录(例如,uiSupport)+调用执行类文件名(例如,baseAPI.API)+调用方法名(例如,waitElement)组合而成,例如,uiSupport.baseAPI.API.waitElement, 通过文件复制的方法将所述截图文件复制到该目录中,确定该截图文件的保存地址;然后获取截图动作发生的时间点,包括年、月、日、时、分、秒,并以预设格式输出,作为截图文件的名称,如,20171107_1848。
需要说明的是,在自动化测试过程中,可能出现在同一秒发生多次截图操作的情况,若按照上述命名步骤对截图文件进行命名,会出现不同截图文件重名的情况。在其他实施例中,为了防止在同一时刻截图生成的截图文件重名,在上述精确到秒的时间点后加入一个递增变量,并为截图文件生成唯一的文件名,例如,在某一秒同时有5次截图,获取这5次截图动作发生的时间信息(精确到毫秒),根据5次截图动作的先后顺序分别为该5个截图文件名称后加一个1-5的递增变量,最终使截图文件分别归属至相应的截图文件目录中,并以时间点+递增变量+.jpg的形式进行命名,如,20171107_1848_4。
通过在检查点的验证步骤后加入截图的异常处理分支,使检查点验证失败时立即进行屏幕截图,有助于还原并展示发生错误时的页面信息。
当截图动作完成并成功保存截图文件后,若还有未被执行的步骤,继续执行未被执行的步骤,并重复上述步骤,直到所有测试用例的所有步骤均执行完毕,例如,上述“打开浏览器的流程”的例子中的“关闭浏览器”的步骤。在其他实施例中,所述截图方法中也加入了异常分支,如果截图失败,则抓住并抛出错误信息,不阻碍后续步骤的执行。例如,浏览器驱动无法进行截取屏幕影像的操作,直接抓取并抛出该错误信息,并继续执行后续操作。至此,已将验证结果中的所有错误信息添加至字符串缓存区中。
当标记失败方法从字符缓存区中摘取错误信息时,优先摘取时间较早的错误信息,并判断所述错误信息是否为空,若不为空,则可根据错误信息找到相应的检查点并标记验证失败,对该测试用例标记执行测试失败;若为空,则过滤掉该错误信息,继续摘取下一条错误信息。另外,标记失败方法每从字符串缓存区中摘取出一条错误信息,字符串缓存区中被摘取的该条错误信息会被删除,直到所述字符串缓存区中没有错误信息为止。至此,测试结束。
当测试结束后,提取类文件中监听器监听到的测试结果,生成测试报告。具体地,预先在类文件中添加监听器,引用该监听器监听自动化测试过程中 的验证结果,同时,在TestNG.xml文件中加入报告监听器,用于提取类文件中添加的监听器,获取其监听到的信息,并在报告中还原并展示验证失败的错误信息。在生成测试报告的过程中,分别统计验证成功及验证失败的次数。对于验证失败的检查点,分别列出每个检查点的错误信息及对应的具体内容,包括:全局变量、类文件名、调用方法等,并根据每条错误信息的具体内容,确定与之对应的截图文件目录,并从该截图文件目录中摘取出相应的截图文件,展示在测试报告中。使测试人员更直观的了解测试过程中发生错误的具体原因。
上述实施例提出的自动化测试方法,通过加入异常处理分支,使检查点在验证失败后截取当前页面信息,并在测试报告的相应位置展示该截图,有助于测试人员快速精准定位测试过程中的错误信息及错误原因;同时,即使验证失败也不影响后续步骤的执行,提高了测试效率。
此外,本申请实施例还提出一种计算机可读存储介质,所述计算机可读存储介质上存储有自动化测试程序10,该程序被处理器执行时实现如下操作:
A1、接收执行测试的指令,从类文件中调取测试用例,所述测试用例包含多个步骤,在所述多个步骤之后添加一个或多个检查点;
A2、执行所述测试用例的一个步骤并得到执行结果,当所述步骤之后存在检查点,调用断言方法对所述步骤对应的执行结果进行验证,得到该执行结果对应的验证结果;
A3、当所述验证结果为验证失败时,抓取所述验证结果中的错误信息,并将所述错误信息添加至字符串缓存区中,调用截图方法对当前页面进行截图,按照预设规则保存截图文件,并继续执行所述检查点之后的步骤;
A4、当所述测试用例的步骤已全部被执行时,依次从字符串缓存区中摘取所述错误信息,判断所述错误信息是否为空,若为空则过滤掉该条错误信息,并摘取下一条错误信息,若不为空则对所述测试用例标记执行失败;及
A5、根据执行测试用例得到的测试结果及截图文件,生成测试报告。
本申请计算机可读存储介质具体实施方式与上述自动化测试方法和电子装置1的具体实施方式基本相同,在此不作累述。
需要说明的是,上述本申请实施例序号仅仅为了描述,不代表实施例的优劣。并且本文中的术语“包括”、“包含”或者其任何其他变体意在涵盖非排他性的包含,从而使得包括一系列要素的过程、装置、物品或者方法不仅包括那些要素,而且还包括没有明确列出的其他要素,或者是还包括为这种过程、装置、物品或者方法所固有的要素。在没有更多限制的情况下,由语句“包括一个……”限定的要素,并不排除在包括该要素的过程、装置、物品或者方法中还存在另外的相同要素。
通过以上的实施方式的描述,本领域的技术人员可以清楚地了解到上述实施例方法可借助软件加必需的通用硬件平台的方式来实现,当然也可以通过硬件,但很多情况下前者是更佳的实施方式。基于这样的理解,本申请的技术方案本质上或者说对现有技术做出贡献的部分可以以软件产品的形式体现出来,该计算机软件产品存储在如上所述的一个存储介质(如ROM/RAM、磁碟、光盘)中,包括若干指令用以使得一台终端设备(可以是手机,计算机,服务器,或者网络设备等)执行本申请各个实施例所述的方法。
以上仅为本申请的优选实施例,并非因此限制本申请的专利范围,凡是利用本申请说明书及附图内容所作的等效结构或等效流程变换,或直接或间接运用在其他相关的技术领域,均同理包括在本申请的专利保护范围内。

Claims (20)

  1. 一种自动化测试方法,应用于电子装置,其特征在于,该方法包括:
    S1、接收执行测试的指令,从类文件中调取测试用例,所述测试用例包含多个步骤,在所述多个步骤之后添加一个或多个检查点;
    S2、执行所述测试用例的一个步骤并得到执行结果,当所述步骤之后存在检查点,调用断言方法对所述步骤对应的执行结果进行验证,得到该执行结果对应的验证结果;
    S3、当所述验证结果为验证失败时,抓取所述验证结果中的错误信息,并将所述错误信息添加至字符串缓存区中,调用截图方法对当前页面进行截图,按照预设规则保存截图文件,并继续执行所述检查点之后的步骤;
    S4、当所述测试用例的步骤已全部被执行时,依次从字符串缓存区中摘取所述错误信息,判断所述错误信息是否为空,若为空则过滤掉该条错误信息,并摘取下一条错误信息,若不为空则对所述测试用例标记执行失败;及
    S5、根据执行测试用例得到的测试结果及截图文件,生成测试报告。
  2. 如权利要求1所述的自动化测试方法,其特征在于,所述步骤S3还包括:
    当存在多条错误信息时,将所述多条错误信息按照时间先后顺序依次添加到字符串缓存区中。
  3. 如权利要求1所述的自动化测试方法,其特征在于,所述步骤S3中“调用截图方法对当前页面进行截图,按照预设规则保存截图文件”的步骤包括:
    调用所述截图方法对发生验证失败时的页面进行截图生成截图文件,并将该截图文件分配至相应的文件目录中,其中,所述文件目录的名称由全局变量根目录、调用执行类名及调用方法名组合生成;及
    获取截图的时间信息,按照预设格式生成截图文件的名称,并以该名称保存所述截图文件。
  4. 如权利要求3所述的自动化测试方法,其特征在于,所述步骤S3还包括:
    在所述截图方法中加入异常处理分支,当截图失败时,抓取并抛出导致截图失败的错误信息,继续执行所述测试用例中该检查点之后的步骤,并对其执行结果进行验证。
  5. 如权利要求4所述的自动化测试方法,其特征在于,所述步骤S5中的“标记失败方法依次从字符缓存区摘取错误信息”的步骤包括:
    标记失败方法每从字符串缓存区中摘取出一条错误信息后,将字符串缓存区中被摘取的错误信息删除,直到所述字符串缓冲区中没有错误信息为止。
  6. 一种电子装置,其特征在于,该装置包括:存储器、处理器,所述存储器上存储有可在所述处理器上运行的自动化测试程序,该程序被所述处理器执行时实现如下步骤:
    A1、接收执行测试的指令,从类文件中调取测试用例,所述测试用例包含多个步骤,在所述多个步骤之后添加一个或多个检查点;
    A2、执行所述测试用例的一个步骤并得到执行结果,当所述步骤之后存在检查点,调用断言方法对所述步骤对应的执行结果进行验证,得到该执行结果对应的验证结果;
    A3、当所述验证结果为验证失败时,抓取所述验证结果中的错误信息,并将所述错误信息添加至字符串缓存区中,调用截图方法对当前页面进行截图,按照预设规则保存截图文件,并继续执行所述检查点之后的步骤;
    A4、当所述测试用例的步骤已全部被执行时,依次从字符串缓存区中摘取所述错误信息,判断所述错误信息是否为空,若为空则过滤掉该条错误信息,并摘取下一条错误信息,若不为空则对所述测试用例标记执行失败;及
    A5、根据执行测试用例得到的测试结果及截图文件,生成测试报告。
  7. 如权利要求6所述的电子装置,其特征在于,所述步骤A3还包括:
    当存在多条错误信息时,将所述多条错误信息按照时间先后顺序依次添加到字符串缓存区中。
  8. 如权利要求6所述的电子装置,其特征在于,所述步骤A3中“调用截图方法对当前页面进行截图,按照预设规则保存截图文件”的步骤包括:
    调用所述截图方法对发生验证失败时的页面进行截图生成截图文件,并将该截图文件分配至相应的文件目录中,其中,所述文件目录的名称由全局变量根目录、调用执行类名及调用方法名组合生成;及
    获取截图的时间信息,按照预设格式生成截图文件的名称,并以该名称保存所述截图文件。
  9. 如权利要求8所述的电子装置,其特征在于,所述步骤A3还包括:
    在所述截图方法中加入异常处理分支,当截图失败时,抓取并抛出导致截图失败的错误信息,继续执行所述测试用例中该检查点之后的步骤,并对其执行结果进行验证。
  10. 如权利要求9所述的电子装置,其特征在于,所述步骤A5中的“标记失败方法依次从字符缓存区摘取错误信息”的步骤包括:
    标记失败方法每从字符串缓存区中摘取出一条错误信息后,将字符串缓存区中被摘取的错误信息删除,直到所述字符串缓冲区中没有错误信息为止。
  11. 一种计算机可读存储介质,其特征在于,所述计算机可读存储介质上存储有自动化测试程序,该程序被所述处理器执行时实现如下步骤:
    A1、接收执行测试的指令,从类文件中调取测试用例,所述测试用例包含多个步骤,在所述多个步骤之后添加一个或多个检查点;
    A2、执行所述测试用例的一个步骤并得到执行结果,当所述步骤之后存在检查点,调用断言方法对所述步骤对应的执行结果进行验证,得到该执行结果对应的验证结果;
    A3、当所述验证结果为验证失败时,抓取所述验证结果中的错误信息,并将所述错误信息添加至字符串缓存区中,调用截图方法对当前页面进行截图,按照预设规则保存截图文件,并继续执行所述检查点之后的步骤;
    A4、当所述测试用例的步骤已全部被执行时,依次从字符串缓存区中摘取所述错误信息,判断所述错误信息是否为空,若为空则过滤掉该条错误信息,并摘取下一条错误信息,若不为空则对所述测试用例标记执行失败;及
    A5、根据执行测试用例得到的测试结果及截图文件,生成测试报告。
  12. 如权利要求11所述的计算机可读存储介质,其特征在于,所述步骤A3还包括:
    当存在多条错误信息时,将所述多条错误信息按照时间先后顺序依次添加到字符串缓存区中。
  13. 如权利要求11所述的计算机可读存储介质,其特征在于,所述步骤A3中“调用截图方法对当前页面进行截图,按照预设规则保存截图文件”的步骤包括:
    调用所述截图方法对发生验证失败时的页面进行截图生成截图文件,并将该截图文件分配至相应的文件目录中,其中,所述文件目录的名称由全局 变量根目录、调用执行类名及调用方法名组合生成;及
    获取截图的时间信息,按照预设格式生成截图文件的名称,并以该名称保存所述截图文件。
  14. 如权利要求13所述的计算机可读存储介质,其特征在于,所述步骤A3还包括:
    在所述截图方法中加入异常处理分支,当截图失败时,抓取并抛出导致截图失败的错误信息,继续执行所述测试用例中该检查点之后的步骤,并对其执行结果进行验证。
  15. 如权利要求14所述的计算机可读存储介质,其特征在于,所述步骤A5中的“标记失败方法依次从字符缓存区摘取错误信息”的步骤包括:
    标记失败方法每从字符串缓存区中摘取出一条错误信息后,将字符串缓存区中被摘取的错误信息删除,直到所述字符串缓冲区中没有错误信息为止。
  16. 一种自动化测试程序,其特征在于,该程序包括:
    接收模块,用于接收执行测试的指令,从类文件中调取测试用例,所述测试用例包含多个步骤,在所述多个步骤之后添加一个或多个检查点;
    验证模块,用于执行所述测试用例的一个步骤并得到执行结果,当所述步骤之后存在检查点,调用断言方法对所述步骤对应的执行结果进行验证,得到该执行结果对应的验证结果;
    抓取模块,用于当所述验证结果为验证失败时,抓取所述验证结果中的错误信息,并将所述错误信息添加至字符串缓存区中,调用截图方法对当前页面进行截图,按照预设规则保存截图文件,并继续执行所述检查点之后的步骤;
    标记模块,用于当所述测试用例的步骤已全部被执行时,依次从字符串缓存区中摘取所述错误信息,判断所述错误信息是否为空,若为空则过滤掉该条错误信息,并摘取下一条错误信息,若不为空则对所述测试用例标记执行失败;及
    生成模块,用于根据执行测试用例得到的测试结果及截图文件,生成测试报告。
  17. 如权利要求16所述的自动化测试程序,其特征在于,所述“抓取所述验证结果中的错误信息,并将所述错误信息添加至字符串缓存区中”的步骤 还包括:
    当存在多条错误信息时,将所述多条错误信息按照时间先后顺序依次添加到字符串缓存区中。
  18. 如权利要求16所述的自动化测试程序,其特征在于,所述“调用截图方法对当前页面进行截图,按照预设规则保存截图文件”的步骤包括:
    调用所述截图方法对发生验证失败时的页面进行截图生成截图文件,并将该截图文件分配至相应的文件目录中,其中,所述文件目录的名称由全局变量根目录、调用执行类名及调用方法名组合生成;及
    获取截图的时间信息,按照预设格式生成截图文件的名称,并以该名称保存所述截图文件。
  19. 如权利要求18所述的自动化测试程序,其特征在于,所述“当所述验证结果为验证失败时,抓取所述验证结果中的错误信息,并将所述错误信息添加至字符串缓存区中,调用截图方法对当前页面进行截图,按照预设规则保存截图文件”的步骤还包括:
    在所述截图方法中加入异常处理分支,当截图失败时,抓取并抛出导致截图失败的错误信息,继续执行所述测试用例中该检查点之后的步骤,并对其执行结果进行验证。
  20. 如权利要求19所述的自动化测试程序,其特征在于,所述“标记失败方法依次从字符缓存区摘取错误信息”的步骤包括:
    标记失败方法每从字符串缓存区中摘取出一条错误信息后,将字符串缓存区中被摘取的错误信息删除,直到所述字符串缓冲区中没有错误信息为止。
PCT/CN2018/089320 2018-03-06 2018-05-31 自动化测试方法、装置及存储介质 WO2019169761A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201810184610.XA CN108491322A (zh) 2018-03-06 2018-03-06 自动化测试方法、装置及存储介质
CN201810184610.X 2018-03-06

Publications (1)

Publication Number Publication Date
WO2019169761A1 true WO2019169761A1 (zh) 2019-09-12

Family

ID=63341722

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2018/089320 WO2019169761A1 (zh) 2018-03-06 2018-05-31 自动化测试方法、装置及存储介质

Country Status (2)

Country Link
CN (1) CN108491322A (zh)
WO (1) WO2019169761A1 (zh)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112559330A (zh) * 2020-12-07 2021-03-26 深圳开源互联网安全技术有限公司 一种开源软件组分检测结果正确性的分析方法

Families Citing this family (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109324969A (zh) * 2018-09-27 2019-02-12 平安普惠企业管理有限公司 测试报告的生成方法、装置、计算机设备及存储介质
CN111104267B (zh) * 2018-10-26 2022-05-13 长鑫存储技术有限公司 存储器的调试处理方法及其调试处理系统
CN109359053A (zh) * 2018-12-18 2019-02-19 上海科梁信息工程股份有限公司 测试报告的生成方法和相关装置、测试系统及存储介质
CN109614342A (zh) * 2019-01-23 2019-04-12 四川虹美智能科技有限公司 一种应用程序自动化测试的方法及测试用例管理平台
CN109960651A (zh) * 2019-02-13 2019-07-02 北京达佳互联信息技术有限公司 埋点测试方法、系统、装置和计算机可读存储介质
CN111124919A (zh) * 2019-12-24 2020-05-08 浙江诺诺网络科技有限公司 一种用户界面的测试方法、装置、设备及存储介质
CN111538659B (zh) * 2020-04-21 2024-03-01 上海携程商务有限公司 业务场景的接口测试方法、系统、电子设备和存储介质
CN111581093B (zh) * 2020-05-08 2023-09-19 中国银行股份有限公司 一种测试记录单的生成方法、装置、设备及介质
CN112015665B (zh) * 2020-09-30 2023-04-11 北京百度网讯科技有限公司 测试验证的回溯方法、装置、电子设备及存储介质
CN116401175A (zh) * 2023-05-29 2023-07-07 云筑信息科技(成都)有限公司 一种基于json文件追加写入图片的处理方法

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20100146488A1 (en) * 2008-12-08 2010-06-10 Microsoft Corporation Automatic test tool for webpage design with micro-browsers on mobile platforms
CN102053906A (zh) * 2009-10-30 2011-05-11 国际商业机器公司 用于收集程序运行时信息的系统和方法
CN102981958A (zh) * 2012-12-19 2013-03-20 青岛海信传媒网络技术有限公司 软件测试方法和测试装置
CN106502895A (zh) * 2016-10-21 2017-03-15 郑州云海信息技术有限公司 一种自动化测试信息生成装置及方法

Family Cites Families (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US9213625B1 (en) * 2010-07-27 2015-12-15 Intuit Inc. Method and apparatus for performing automated user-interface layout testing
CN103544101B (zh) * 2012-07-16 2020-06-26 深圳市世纪光速信息技术有限公司 一种无线平台开发自动测试系统及方法
TWI510915B (zh) * 2014-05-28 2015-12-01 Univ Nat Central Computer automated test system and test methods, recording media and program products
CN106161134A (zh) * 2015-04-21 2016-11-23 腾讯科技(深圳)有限公司 移动终端自动化测试方法、装置及移动终端
CN104978270A (zh) * 2015-07-03 2015-10-14 上海触乐信息科技有限公司 一种自动化地软件测试方法和装置

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20100146488A1 (en) * 2008-12-08 2010-06-10 Microsoft Corporation Automatic test tool for webpage design with micro-browsers on mobile platforms
CN102053906A (zh) * 2009-10-30 2011-05-11 国际商业机器公司 用于收集程序运行时信息的系统和方法
CN102981958A (zh) * 2012-12-19 2013-03-20 青岛海信传媒网络技术有限公司 软件测试方法和测试装置
CN106502895A (zh) * 2016-10-21 2017-03-15 郑州云海信息技术有限公司 一种自动化测试信息生成装置及方法

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112559330A (zh) * 2020-12-07 2021-03-26 深圳开源互联网安全技术有限公司 一种开源软件组分检测结果正确性的分析方法

Also Published As

Publication number Publication date
CN108491322A (zh) 2018-09-04

Similar Documents

Publication Publication Date Title
WO2019169761A1 (zh) 自动化测试方法、装置及存储介质
US10613971B1 (en) Autonomous testing of web-based applications
CN108108297B (zh) 自动化测试的方法和装置
US10409711B2 (en) Automatically running tests against WEB APIs based on specifications
US10169206B2 (en) Simultaneous multi-platform testing
KR102268355B1 (ko) 클라우드 배치 기반구조 검증 엔진
US9846634B2 (en) Visual graphical user interface verification
US9223684B2 (en) Online application testing across browser environments
US9342237B2 (en) Automated testing of gesture-based applications
JP6648306B2 (ja) 異常スタック情報取得方法、装置及びコンピュータ読み取り可能な記憶媒体
CN107171825B (zh) 一种终端的重复日志过滤方法
US8839201B2 (en) Capturing test data associated with error conditions in software item testing
US9760475B2 (en) Automatic updating of graphical user interface element locators based on image comparison
US9946637B2 (en) Automatic updating of graphical user interface element locators based on dimension comparison
US8839202B2 (en) Test environment managed within tests
US9684587B2 (en) Test creation with execution
US8438418B2 (en) Simplifying automated software maintenance of data centers
US8949794B2 (en) Binding a software item to a plain english control name
CN110825619A (zh) 接口测试用例自动生成方法、装置及存储介质
CN111104315A (zh) 一种测试脚本生成方法及装置、计算机可读存储介质
CN105302722B (zh) Cts自动测试方法及装置
US20090204945A1 (en) Utilizing intelligent automated scripts to test software applications
CN111400125A (zh) Java进程的内存溢出监控方法、装置、设备及存储介质
WO2017164856A1 (en) Comparable user interface object identifications
CN113760763A (zh) 软件测试方法、设备、服务器和系统

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 18908945

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

32PN Ep: public notification in the ep bulletin as address of the adressee cannot be established

Free format text: NOTING OF LOSS OF RIGHTS PURSUANT TO RULE 112(1) EPC (EPO FORM 1205A DATED 09.12.2020)

122 Ep: pct application non-entry in european phase

Ref document number: 18908945

Country of ref document: EP

Kind code of ref document: A1