WO2018188380A1 - 一种添加控件标识的方法和装置 - Google Patents

一种添加控件标识的方法和装置 Download PDF

Info

Publication number
WO2018188380A1
WO2018188380A1 PCT/CN2017/120139 CN2017120139W WO2018188380A1 WO 2018188380 A1 WO2018188380 A1 WO 2018188380A1 CN 2017120139 W CN2017120139 W CN 2017120139W WO 2018188380 A1 WO2018188380 A1 WO 2018188380A1
Authority
WO
WIPO (PCT)
Prior art keywords
control
identifier
name
click event
preset
Prior art date
Application number
PCT/CN2017/120139
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 WO2018188380A1 publication Critical patent/WO2018188380A1/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/3684Test management for test design, e.g. generating new test cases

Definitions

  • the present invention relates to the field of Internet program development, and in particular, to a method and apparatus for adding a control identifier.
  • the control In the test of the mobile app by script, the control needs to be located by the XPath of the control to obtain the identity of each control.
  • the control identifier is duplicated or there is no control identifier, and the XPath acquires the relative path of the control, which is not easy to fix. So using XPath to position the control, the path of the control is easy to change.
  • the present invention provides a method and apparatus for adding a control identifier.
  • the present invention provides a method and apparatus for adding a control identifier in view of the drawbacks of the prior art that are time consuming, inefficient, and prone to omission.
  • An aspect of the present invention provides a method for adding a control identifier, including: S1, determining whether a control can be identified by using a preset method; S2, if the control that cannot be identified by using a preset method is obtained, The method name of the click event of the control, the method name is used as the identifier of the control; if the method name of the click event of the control cannot be obtained, the string corresponding to the control is used as the identifier of the control .
  • the identifying the control by using the preset method in the step S1 further includes: if the attribute value of the control is obtained, the attribute value is used as an identifier of the control; if the attribute value of the control cannot be obtained And according to the type of the control, the picture name or text of the control is used as the identifier of the control.
  • the type of the control includes a button type and a label type.
  • the string corresponding to the control refers to a string formed by the control type name and the parent control type name of the control.
  • the method name for obtaining the click event of the control includes: a method name for acquiring a click event of the control by a method exchange; and a method name for saving a click event of the control by adding a method in the category.
  • the method for using the method name as the identifier of the control includes: obtaining a method name of a click event of the control by adding a method in a category; and using the method name as an identifier of the control by a method exchange.
  • the method exchange includes: controlling the method exchange to be performed only once in a loading method when the class corresponding to the control is started; acquiring the original method and the method to be exchanged, and the original method and the to-be-exchanged The method is exchanged.
  • the method for adding the classification includes: creating a classification, and adding an assignment method set or a get value method get to the classification.
  • Another aspect of the present invention provides an apparatus for adding a control identifier, including: a determination module, configured to determine whether a control can be identified by using a preset method; and an identification module, configured to: a control, if the method name of the click event of the control is obtained, the method name is used as an identifier of the control; if the method name of the click event of the control cannot be obtained, the character corresponding to the control is A string is used as the identifier of the control.
  • the identifying the control by using the preset method in the identifier module further includes: if the attribute value of the control is obtained, the attribute value is used as an identifier of the control; if the attribute value of the control cannot be obtained And according to the type of the control, the picture name or text of the control is used as the identifier of the control.
  • Yet another aspect of the present invention provides an apparatus for adding a control identifier, comprising: at least one processor; and at least one memory communicatively coupled to the processor, wherein: the memory is stored for execution by the processor a program instruction, the processor invoking the program instruction to perform the method for adding a control identifier provided by the above aspect of the present invention, for example, comprising: S1, determining whether the control can be identified by using a preset method; S2, for not using the preset The method performs the identified control, if the method name of the click event of the control is obtained, the method name is used as the identifier of the control; if the method name of the click event of the control cannot be obtained, The character string corresponding to the control is used as the identifier of the control.
  • Yet another aspect of the present invention provides a non-transitory computer readable storage medium storing computer instructions that cause the computer to perform an add control identification provided by the above aspect of the present invention
  • the method includes, for example: S1, determining whether the control can be identified by using a preset method; S2, for the control that cannot be identified by using the preset method, if the method name of the click event of the control is obtained, The method name is used as the identifier of the control; if the method name of the click event of the control cannot be obtained, the character string corresponding to the control is used as the identifier of the control.
  • Yet another aspect of the present invention provides a computer program product comprising a computer program stored on a non-transitory computer readable storage medium, the computer program comprising program instructions, when the program instructions are executed by a computer
  • the method for the computer to perform the method for adding a control identifier provided by the present invention includes, for example: S1, determining whether the control can be identified by using a preset method; S2, if the control that cannot be identified by using a preset method is obtained, The method name of the click event of the control, the method name is used as the identifier of the control; if the method name of the click event of the control cannot be obtained, the character string corresponding to the control is used as the The identity of the control.
  • the method and device for adding a control identifier provided by the invention can quickly and efficiently add an identifier to a control by using a method name or a string of a click event as an identifier of the control, so as to maximize the plurality of controls in the same page.
  • the identification is not repeated, which satisfies the needs of the application when performing script testing.
  • FIG. 1 is a schematic flowchart of a method for adding a control identifier according to an embodiment of the present invention
  • FIG. 2 is a schematic structural diagram of an apparatus for adding a control identifier according to an embodiment of the present invention
  • FIG. 3 is a schematic structural diagram of an apparatus for adding a control identifier according to an embodiment of the present invention.
  • FIG. 1 is a schematic flowchart of a method for adding a control identifier according to an embodiment of the present invention.
  • the method includes: S1, determining whether a preset method can be used to identify a control; S2, for using a preset method The control that performs the identification, if the method name of the click event of the control is obtained, the method name is used as the identifier of the control; if the method name of the click event of the control cannot be obtained, The string corresponding to the control is used as the identifier of the control.
  • step S1 it can first be determined whether the control can be identified using a preset method. If possible, use the default method for identification.
  • step S2 the control may perform a corresponding method after receiving the click event. Therefore, you can intercept the system's click events and get the method name for each click event. After getting the method name of the click event, save the method name of the click event. For those controls that cannot be identified by the preset method, the method name of the click event corresponding to the control can be used as the identifier of the control.
  • the method for adding a control identifier provided by the embodiment of the present invention can quickly and efficiently add an identifier to a control by using a method name or a string of a click event as an identifier of the control, so as to maximize the plurality of controls in the same page.
  • the identification is not repeated, which satisfies the needs of the application when performing script testing.
  • the identifying the control by using the preset method in the step S1 further includes: if the attribute value of the control is obtained, the attribute value is used as an identifier of the control; if the control cannot be obtained The attribute value is used to identify the picture name or text of the control as the identifier of the control according to the type of the control.
  • control Since most of the controls are not temporary variables, the control has an attribute value in the IOS page. The value of this attribute is like the name of each control. Normally it will not change, and it is not allowed to repeat in the same page. Therefore, most of the controls can be identified by using the property values of the control.
  • the preset method first, an attempt is made to obtain an attribute value of the control, and if the attribute value of the control can be obtained, the attribute value is used as an identifier of the control.
  • this property value can be obtained through a runtime mechanism. If you can't get the property value of the control, you can use the image name or text of the control as the identifier according to the type of the control.
  • the type of the control includes a button type and a tag type. If the type of the control is a button type, that is, the UIButton type. First, you can determine whether there is a picture in the control. If there is a picture, you can use the name of the picture as the identifier of the control. Since the name of the picture is unique in the entire interface, it can avoid duplication; if the control has no picture, it further determines whether the control has text, and if there is text, the text is used as the identifier of the control. Since the type of button type is usually fixed and less reproducible on the same page, it is also better unique.
  • control type is determined to be a tag type, that is, a UILable type
  • the text of the tag in the control may be used as the identifier of the control.
  • the string corresponding to the control refers to a string of the control type name and the parent control type name of the control.
  • the control type name of the control and the type name of the parent control may be combined into a string as the identifier of the control. This ensures maximum control for each control and will not be missed.
  • the method name of obtaining the click event of the control includes: a method name for acquiring a click event of the control by a method exchange; and a method name for saving a click event of the control by adding a method in the category.
  • the method of the runtime mechanism in the IOS system can be exchanged, and the function of responding to the click time in the system is replaced by the function addTarget:action:forControlEvents, which can intercept the click time of the system, thereby obtaining each click event.
  • Objective-C provides a special way to extend the class, called Catagory, to dynamically add new behavior to existing classes. This will ensure that the class will be able to increase the required functionality with minor changes on the original basis.
  • the function has two parameters, self and string key.
  • the method as the identifier of the control, includes: obtaining a method name of a click event of the control by adding a method in a category; using the method name as the control by a method exchange Logo.
  • an acquisition value method get may be generated in the classification using the runtime mechanism of the IOS system.
  • the get value method get is a method for setting an associated object by using IOS.
  • the specific function is objc_getAssociatedObject, which has two parameters, self and the string key in the set method.
  • the method name of the click event can be obtained by the get method.
  • the function in the system can be exchanged by the method of the runtime mechanism in the IOS system, and the function in the system is exchanged into (NSString*) accessibilityIdentifier, and the function name of the click event that the function can obtain by the get method. Identify the corresponding controls.
  • the function (NSString*) accessibilityIdentifier can also be used as the identifier of the control according to the preset method or the string pair corresponding to the control.
  • the method exchange includes: controlling the method exchange to be performed only once in a loading method when the class corresponding to the control is started; acquiring the original method and the method to be exchanged, and the original method Exchange with the method to be exchanged.
  • the method exchange is performed in a loading method when a corresponding class of a control of the IOS system is started.
  • the method of controlling the class exchange can be executed only once by the function dispatch_once.
  • the function can include two parameters. The first parameter predicate is used to ensure execution once, and the second parameter is the task block to be executed once.
  • originalMethod for example, the method of event response, the method of image loading, etc.
  • customize a method to be exchanged, swizzledMethod, which needs to be exchanged can perform both the function of the system method and the self. Defined features, such as adding control markers).
  • the method exchange is performed by the IOS system function method_exchangeImplementations, and the original method originalMethod and the method to be exchanged swizzledMethod are exchanged to realize the exchange of the two functions.
  • each control creation will call this method, which ensures that each control will perform method exchange without any omission.
  • the adding method in the classification includes: creating a classification, and adding an assignment method set or an acquisition value method get to the classification.
  • the classification is an attribute of the IOS language class. You can first create a category in the class and add methods to it.
  • the assignment method set and the get value method get can be generated using the runtime mechanism of the IOS system. By setting the set method and the get method, the IOS system can not perform the assignment operation and the value acquisition operation, and the assignment operation and the value operation can be performed through the runtime mechanism.
  • the apparatus includes: a determining module 201, configured to determine whether a preset method is used to identify a control; and an identifier module 202, For the control that cannot be identified by using the preset method, if the method name of the click event of the control is obtained, the method name is used as the identifier of the control; if the click of the control cannot be obtained The method name of the event, the string corresponding to the control is used as the identifier of the control.
  • the determining module 201 can determine whether the control can be identified by using a preset method.
  • the control can perform a corresponding method after receiving the click event. Therefore, the identification module 202 can intercept the click event of the system and obtain the method name of each click event. After obtaining the method name of the click event, the identification module 202 saves the method name of the click event. For those controls that cannot be identified using the preset method, the identification module 202 can use the method name of the click event corresponding to the control as the identifier of the control.
  • the identifier module 202 can use the string corresponding to the control as the control. logo.
  • the device for adding the control identifier provided by the embodiment of the present invention can quickly and efficiently add an identifier to the control by using the method name or the string of the click event as the identifier of the control, so as to maximize the multiple controls in the same page.
  • the identification is not repeated, which satisfies the needs of the application when performing script testing.
  • the identifying the control by using the preset method in the identifier module 202 further includes: if the attribute value of the control is obtained, the attribute value is used as an identifier of the control; The attribute value of the control is based on the type of the control, and the picture name or text of the control is used as the identifier of the control.
  • control Since most of the controls are not temporary variables, the control has an attribute value in the IOS page. The value of this attribute is like the name of each control. Normally it will not change, and it is not allowed to repeat in the same page. Therefore, most of the controls can be identified by using the property values of the control.
  • the preset method first, an attempt is made to obtain an attribute value of the control, and if the attribute value of the control can be obtained, the attribute value is used as an identifier of the control.
  • this property value can be obtained through a runtime mechanism. If you can't get the property value of the control, you can use the image name or text of the control as the identifier according to the type of the control.
  • FIG. 3 is a schematic structural diagram of an apparatus for adding a control identifier according to an embodiment of the present invention.
  • the apparatus includes: at least one processor 301; and at least one memory 302 communicably connected to the processor 301, where The memory 302 stores a program instruction that can be executed by the processor 301, and the processor 301 invokes the program instruction to perform the method for adding the control identifier provided by each of the foregoing embodiments, for example, including: S1, determining Whether the control can be identified by using a preset method; S2, for the control that cannot be identified by using the preset method, if the method name of the click event of the control is obtained, the method name is used as the control If the method name of the click event of the control is not obtained, the string corresponding to the control is used as the identifier of the control.
  • the embodiment of the present invention further provides a non-transitory computer readable storage medium, where the non-transitory computer readable storage medium stores computer instructions, which cause the computer to execute the method for adding the control identifier provided by the corresponding embodiment, for example, including : S1, determining whether the control can be identified by using a preset method; S2, for the control that cannot be identified by using the preset method, if the method name of the click event of the control is obtained, the method name is taken as The identifier of the control; if the method name of the click event of the control is not obtained, the character string corresponding to the control is used as the identifier of the control.
  • the embodiment discloses a computer program product comprising a computer program stored on a non-transitory computer readable storage medium, the computer program comprising program instructions, when the program instructions are executed by a computer, the computer
  • the method for adding the control identifier provided by the foregoing method embodiments includes, for example: S1, determining whether the control can be identified by using a preset method; and S2, if the control that cannot be identified by using the preset method is obtained, The method name of the click event of the control, the method name is used as the identifier of the control; if the method name of the click event of the control cannot be obtained, the character string corresponding to the control is used as the The identity of the control.
  • the foregoing program may be stored in a computer readable storage medium, and the program is executed when executed.
  • the foregoing steps include the steps of the foregoing method embodiments; and the foregoing storage medium includes: a medium that can store program codes, such as a ROM, a RAM, a magnetic disk, or an optical disk.
  • the method and device for adding a control identifier provided by an embodiment of the present invention can perform script test on an APP by using a property name, a picture name, a text, a method name of a click event, or a character string corresponding to a control as a control identifier. Automatic, efficient, and maximum identification of controls, reducing developer workload and improving work efficiency.

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)
  • Stored Programmes (AREA)
  • Debugging And Monitoring (AREA)
  • Facsimiles In General (AREA)

Abstract

一种添加控件标识的方法和装置,该方法包括:S1,判断能否使用预设方法对控件进行标识(S1);S2,对于不能使用预设方法进行标识的所述控件,若获取到所述控件的点击事件的方法名,则将所述方法名作为所述控件的标识;若不能获取到所述控件的点击事件的方法名,则将所述控件对应的字符串作为所述控件的标识(S2)。通过将点击事件的方法名或字符串作为控件的标识,能够快捷、高效地为控件添加标识,能最大程度的使得在同一页面中的多个控件的标识不重复,满足了应用程序在进行脚本测试时的需求。

Description

一种添加控件标识的方法和装置
交叉引用
本申请引用于2017年04月11日提交的专利名称为“一种添加控件标识的方法和装置”的第2017102337579号中国专利申请,其通过引用被全部并入本申请。
技术领域
本发明涉及互联网程序开发领域,具体涉及一种添加控件标识的方法和装置。
背景技术
随着手机移动端的快速发展,移动端App的需求多种多样。在App功能测试中,对于一些固定的用例执行,可以使用自动化测试工具,通过编写自动化测试脚本来执行,减少人员的重复劳动,提高整个测试的效率。
在通过脚本对移动端的App进行测试中,需要通过控件的XPath获取每个控件的标识来对控件进行定位。但是在实际操作过程中,常常出现控件标识重复或者没有控件标识的问题,并且XPath获取的是控件的相对路径,不容易固定。因此使用XPath来定位控件,控件的路径很容易变化。
为了解决上述问题,现有技术中需要通过开发人员为每个控件手动添加标识,但这种方法需要耗费大量的时间。特别是已经开发了几年项目,其中控件的数量成千上万,一个个手动添加标识需要耗时耗力,浪费大量的人力资源,而且很容易造成标识遗漏,效率低下。
发明内容
针对现有技术中存在的上述缺陷,本发明提供一种添加控件标识的方法和装置。
针对现有技术中存在的耗时耗力、效率低下和易于遗漏的缺陷,本发明提供一种添加控件标识的方法和装置。
本发明的一方面提供一种添加控件标识的方法,包括:S1,判断能否使用预设方法对控件进行标识;S2,对于不能使用预设方法进行标识的所述控件,若获取到所述控件的点击事件的方法名,则将所述方法名作为所述控件的标识;若不能获取到所述控件的点击事件的方法名,则将所述控件对应的字符串作为所述控件的标识。
其中,步骤S1中所述使用预设方法对控件进行标识进一步包括:若能获取所述控件的属性值,则将所述属性值作为所述控件的标识;若不能获取所述控件的属性值,则根据所述控件的类型,将所述控件的图片名或文字作为所述控件的标识。
其中,所述控件的类型包括按钮类型和标签类型。
其中,所述控件对应的字符串是指所述控件的控件类型名和父控件类型名拼接成的字符串。
其中,所述获取到所述控件的点击事件的方法名包括:通过方法交换获取所述控件的点击事件的方法名;通过分类中添加方法保存所述控件的点击事件的方法名。
其中,所述将所述方法名作为所述控件的标识包括:通过分类中添加方法获取所述控件的点击事件的方法名;通过方法交换将所述方法名作为所述控件的标识。
其中,所述方法交换包括:在所述控件对应的类启动时的加载方法中,控制所述方法交换只执行一次;获取原方法和待交换方法,并对所述原方法和所述待交换方法进行交换。
其中,所述分类中添加方法包括:创建分类,并在所述分类中添加赋值方法set或获取值方法get。
本发明的另一方面提供一种添加控件标识的装置,包括:判断模块,用于判断能否使用预设方法对控件进行标识;标识模块,用于对于不能使用预设方法进行标识的所述控件,若获取到所述控件的点击事件的方法名,则将所述方法名作为所述控件的标识;若不能获取到所述控件的点击事件的方法名,则将所述控件对应的字符串作为所述控件的标识。
其中,标识模块中所述使用预设方法对控件进行标识进一步包括:若能获取所述控件的属性值,则将所述属性值作为所述控件的标识;若不能获取所述控件的属性值,则根据所述控件的类型,将所述控件的图片名或文字作为所述控件的标识。
本发明的又一方面提供一种添加控件标识的设备,包括:至少一个处理器;以及与所述处理器通信连接的至少一个存储器,其中:所述存储器存储有可被所述处理器执行的程序指令,所述处理器调用所述程序指令能够执行本发明上述方面提供的添加控件标识的方法,例如包括:S1,判断能否使用预设方法对控件进行标识;S2,对于不能使用预设方法进行标识的所述控件,若获取到所述控件的点击事件的方法名,则将所述方法名作为所述控件的标识;若不能获取到所述控件的点击事件的方法名,则将所述控件对应的字符串作为所述控件的标识。
本发明的又一方面提供一种非暂态计算机可读存储介质,所述非暂态计算机可读存储介质存储计算机指令,所述计算机指令使所述计算机执行本发明上述方面提供的添加控件标识的方法,例如包括:S1,判断能否使用预设方法对控件进行标识;S2,对于不能使用预设方法进行标识的所述控件,若获取到所述控件的点击事件的方法名,则将 所述方法名作为所述控件的标识;若不能获取到所述控件的点击事件的方法名,则将所述控件对应的字符串作为所述控件的标识。
本发明又一方面提供一种计算机程序产品,所述计算机程序产品包括存储在非暂态计算机可读存储介质上的计算机程序,所述计算机程序包括程序指令,当所述程序指令被计算机执行时,使所述计算机执行本发明提供的添加控件标识的方法,例如包括:S1,判断能否使用预设方法对控件进行标识;S2,对于不能使用预设方法进行标识的所述控件,若获取到所述控件的点击事件的方法名,则将所述方法名作为所述控件的标识;若不能获取到所述控件的点击事件的方法名,则将所述控件对应的字符串作为所述控件的标识。
本发明提供的添加控件标识的方法和装置,通过将点击事件的方法名或字符串作为控件的标识,能够快捷、高效地为控件添加标识,能最大程度的使得在同一页面中的多个控件的标识不重复,满足了应用程序在进行脚本测试时的需求。
附图说明
图1为本发明实施例提供的添加控件标识的方法的流程示意图;
图2为本发明实施例提供的添加控件标识的装置的结构示意图;
图3为本发明实施例提供的添加控件标识的设备的结构示意图。
具体实施方式
下面结合附图和实施例,对本发明的具体实施方式作进一步详细描述。以下实施例用于说明本发明,但不用来限制本发明的范围。
为了方便理解,本发明实施例提供的方法和装置中以IOS系统为例进行说明,但本发明实施例的保护范围不限于此。
图1为本发明实施例提供的添加控件标识的方法的流程示意图,如图1所示,该方法包括:S1,判断能否使用预设方法对控件进行标 识;S2,对于不能使用预设方法进行标识的所述控件,若获取到所述控件的点击事件的方法名,则将所述方法名作为所述控件的标识;若不能获取到所述控件的点击事件的方法名,则将所述控件对应的字符串作为所述控件的标识。
在步骤S1中,首先可以判断能否使用预设方法对控件进行标识。如果可以,则使用预设方法进行标识。
在步骤S2中,控件接收到点击事件后可以执行一个相应的方法。因此,可以拦截系统的点击事件,并获取每个点击事件的方法名。在获取点击事件的方法名之后,将点击事件的方法名保存起来。对于那些不能使用预设方法进行标识的控件,可以将该控件对应的点击事件的方法名作为该控件的标识。
由于不是所有控件都能够被点击,因此如果该控件既不能根据预设方法进行标识,也不能获取到该控件的点击事件的方法名,则可以将该控件对应的字符串作为该控件的标识。
本发明实施例提供的添加控件标识的方法,通过将点击事件的方法名或字符串作为控件的标识,能够快捷、高效地为控件添加标识,能最大程度的使得在同一页面中的多个控件的标识不重复,满足了应用程序在进行脚本测试时的需求。
基于上述实施例,步骤S1中所述使用预设方法对控件进行标识进一步包括:若能获取所述控件的属性值,则将所述属性值作为所述控件的标识;若不能获取所述控件的属性值,则根据所述控件的类型,将所述控件的图片名或文字作为所述控件的标识。
由于大部分控件不是临时变量,因此控件在IOS的页面中都有一个属性值,该属性值如同每个控件的名字,通常情况下不会变化,并且在同一页面中也不允许重复。因此,通过使用控件的属性值,能够对大部分控件进行标识。
具体地,在预设方法中,首先尝试获取控件的属性值,如果能够获取到控件的属性值,则将该属性值作为控件的标识。例如在IOS系统中,可以通过运行时机制获取这个属性值。如果不能获取控件的属性值,则可以根据控件的类型,将控件的图片名或文字作为标识。
基于上述实施例,其中,所述控件的类型包括按钮类型和标签类型。如果该控件的类型为按钮类型,即UIButton类型。则首先可以判断该控件中是否有图片,如果有图片,则可以将该图片的名字作为该控件的标识。由于图片的名字在整个界面中的唯一性较好,因此能够避免重复;如果该控件没有图片,则进一步判断该控件是否有文字,如果有文字,则将该文字作为该控件的标识。由于按钮类型的文字通常比较固定且在同一页面中的重复性较低,因此同样具有较好的唯一性。
相似地,若判断该控件类型为标签类型,即UILable类型,则可以将该控件内标签的文字作为控件的标识。通过根据控件的类型进行不同的标识操作,能够结合控件类型的特点为进行控件标识,具有较好的唯一性。
基于上述实施例,其中,所述控件对应的字符串是指所述控件的控件类型名和父控件类型名拼接成的字符串。具体地,可以将该控件的控件类型名和父控件的类型名拼接成一个字符串作为该控件的标识。从而最大程度地保证每个控件都具有标识,不会遗漏。
基于上述实施例,所述获取到所述控件的点击事件的方法名包括:通过方法交换获取所述控件的点击事件的方法名;通过分类中添加方法保存所述控件的点击事件的方法名。
具体地,可以通过IOS系统中的运行时机制的方法交换,将系统中的响应点击时间的函数替换成函数addTarget:action:forControlEvents,该函数能够拦截系统的点击时间, 从而获取每个点击事件的方法名。
而为了实现新增加的需求,Objective-C提供了一种特别的方式来扩展类,叫Catagory,可以动态的为已经存在的类添加新的行为。这样可以保证类在原来的基础上,通过较小的改动就可以增加需要的功能。
因此可以在分类里添加一个赋值set方法,在该set方法中通过使用函数objc_setAssociatedObject来保存控件的点击事件的方法名。其中,该函数具有两个参数,自己self和字符串key。
基于上述实施例,其中,所述将所述方法名作为所述控件的标识包括:通过分类中添加方法获取所述控件的点击事件的方法名;通过方法交换将所述方法名作为所述控件的标识。
具体地,为了将上述set方法保存的点击事件的方法名取出,与set方法类似,可以在分类里使用IOS系统的运行时机制生成一个获取值方法get。其中,获取值方法get是通过使用IOS设置关联对象的方法,具体的函数为objc_getAssociatedObject,其具有两个参数,自己self和上述set方法中的字符串key。通过该get方法能够获取点击事件的方法名。
在获取到点击事件的方法名后,可以通过IOS系统中的运行时机制的方法交换,将系统中的函数交换成(NSString*)accessibilityIdentifier,该函数能够将get方法获取到的点击事件的方法名对相应的控件进行标识。相似地,函数(NSString*)accessibilityIdentifier也可以根据预设方法或控件对应的字符串对作为控件的标识。
基于上述实施例,其中,所述方法交换包括:在所述控件对应的类启动时的加载方法中,控制所述方法交换只执行一次;获取原方法和待交换方法,并对所述原方法和所述待交换方法进行交换。
具体地,方法交换是在IOS系统的一个控件的对应类启动时的加载方法中进行。可以通过函数dispatch_once控制类交换的方法只执行一次,该函数可以包括两个参数,第一个参数predicate用来保证执行一次,第二个参数是要执行一次的任务block。
然后需要获取到被交换的原方法为originalMethod(例如,事件响应的方法、图片加载的方法等方法),自定义一个需要交换的待交换方法swizzledMethod(既可以执行系统方法的功能,又可以实现自定义的功能,例如添加控件标示)。
通过IOS的系统函数method_exchangeImplementations执行方法交换,交换原方法originalMethod和待交换方法swizzledMethod,以此实现两个函数的交换。
通过对IOS系统的方法进行交换,使得每个控件创建都会调用该方法,可以保证每个控件都会执行方法交换,没有任何遗漏。
基于上述实施例,其中,所述分类中添加方法包括:创建分类,并在所述分类中添加赋值方法set或获取值方法get。
具体地,分类是IOS语言类的属性。首先可以在类中创建一个分类,并在该分类中添加方法。可以使用IOS系统的运行时机制生成赋值方法set和获取值方法get。通过设置set方法和get方法让IOS系统中原本不能执行赋值操作和获取值操作变成了可以通过运行时机制执行赋值操作和获取值操作。
图2为本发明实施例提供的添加控件标识的装置的结构示意图,如图2所示,该装置包括:判断模块201,用于判断能否使用预设方法对控件进行标识;标识模块202,用于对于不能使用预设方法进行标识的所述控件,若获取到所述控件的点击事件的方法名,则将所述方法名作为所述控件的标识;若不能获取到所述控件的点击事件的方法名,则将所述控件对应的字符串作为所述控件的标识。
具体地,判断模块201可以判断能否使用预设方法对控件进行标识。控件接收到点击事件后可以执行一个相应的方法。因此,标识模块202可以拦截系统的点击事件,并获取每个点击事件的方法名。在获取点击事件的方法名之后,标识模块202将点击事件的方法名保存起来。对于那些不能使用预设方法进行标识的控件,标识模块202可以将该控件对应的点击事件的方法名作为该控件的标识。
由于不是所有控件都能够被点击,因此如果该控件既不能根据预设方法进行标识,也不能获取到该控件的点击事件的方法名,则标识模块202可以将该控件对应的字符串作为该控件的标识。
本发明实施例提供的添加控件标识的装置,通过将点击事件的方法名或字符串作为控件的标识,能够快捷、高效地为控件添加标识,能最大程度的使得在同一页面中的多个控件的标识不重复,满足了应用程序在进行脚本测试时的需求。
基于上述实施例,其中,标识模块202中所述使用预设方法对控件进行标识进一步包括:若能获取所述控件的属性值,则将所述属性值作为所述控件的标识;若不能获取所述控件的属性值,则根据所述控件的类型,将所述控件的图片名或文字作为所述控件的标识。
由于大部分控件不是临时变量,因此控件在IOS的页面中都有一个属性值,该属性值如同每个控件的名字,通常情况下不会变化,并且在同一页面中也不允许重复。因此,通过使用控件的属性值,能够对大部分控件进行标识。
具体地,在预设方法中,首先尝试获取控件的属性值,如果能够获取到控件的属性值,则将该属性值作为控件的标识。例如在IOS系统中,可以通过运行时机制获取这个属性值。如果不能获取控件的属性值,则可以根据控件的类型,将控件的图片名或文字作为标识。
图3为本发明实施例提供的添加控件标识的设备的结构示意图, 如图3所示,该设备包括:至少一个处理器301;以及与所述处理器301通信连接的至少一个存储器302,其中:所述存储器302存储有可被所述处理器301执行的程序指令,所述处理器301调用所述程序指令能够执行上述各实施例所提供的添加控件标识的方法,例如包括:S1,判断能否使用预设方法对控件进行标识;S2,对于不能使用预设方法进行标识的所述控件,若获取到所述控件的点击事件的方法名,则将所述方法名作为所述控件的标识;若不能获取到所述控件的点击事件的方法名,则将所述控件对应的字符串作为所述控件的标识。
本发明实施例还提供一种非暂态计算机可读存储介质,该非暂态计算机可读存储介质存储计算机指令,该计算机指令使计算机执行对应实施例所提供的添加控件标识的方法,例如包括:S1,判断能否使用预设方法对控件进行标识;S2,对于不能使用预设方法进行标识的所述控件,若获取到所述控件的点击事件的方法名,则将所述方法名作为所述控件的标识;若不能获取到所述控件的点击事件的方法名,则将所述控件对应的字符串作为所述控件的标识。
本实施例公开一种计算机程序产品,所述计算机程序产品包括存储在非暂态计算机可读存储介质上的计算机程序,所述计算机程序包括程序指令,当所述程序指令被计算机执行时,计算机能够执行上述各方法实施例所提供的添加控件标识的方法,例如包括:S1,判断能否使用预设方法对控件进行标识;S2,对于不能使用预设方法进行标识的所述控件,若获取到所述控件的点击事件的方法名,则将所述方法名作为所述控件的标识;若不能获取到所述控件的点击事件的方法名,则将所述控件对应的字符串作为所述控件的标识。
本领域普通技术人员可以理解:实现上述方法实施例的全部或部分步骤可以通过程序指令相关的硬件来完成,前述的程序可以存储于一计算机可读取存储介质中,该程序在执行时,执行包括上述方法实施例的步骤;而前述的存储介质包括:ROM、RAM、磁碟或者光盘等 各种可以存储程序代码的介质。
以上所描述的添加控件标识的设备等实施例仅仅是示意性的,其中所述作为分离部件说明的单元可以是或者也可以不是物理上分开的,作为单元显示的部件可以是或者也可以不是物理单元,即可以位于一个地方,或者也可以分布到多个网络单元上。可以根据实际的需要选择其中的部分或者全部模块来实现本实施例方案的目的。本领域普通技术人员在不付出创造性的劳动的情况下,即可以理解并实施。
通过以上的实施方式的描述,本领域的技术人员可以清楚地了解到各实施方式可借助软件加必需的通用硬件平台的方式来实现,当然也可以通过硬件。基于这样的理解,上述技术方案本质上或者说对现有技术做出贡献的部分可以以软件产品的形式体现出来,该计算机软件产品可以存储在计算机可读存储介质中,如ROM/RAM、磁碟、光盘等,包括若干指令用以使得一台计算机设备(可以是个人计算机,服务器,或者网络设备等)执行各个实施例或者实施例的某些部分所述的方法。
本发明实施例提供的添加控件标识的方法和装置,能够通过使用控件的属性名、图片名、文字、点击事件的方法名或控件对应的字符串作为控件的标识,能在对APP进行脚本测试时,自动、高效、最大程度地为控件添加标识,降低了开发人员的工作量,提高了工作效率。
最后,本申请的方法仅为较佳的实施方案,并非用于限定本发明的保护范围。凡在本发明的精神和原则之内,所作的任何修改、等同替换、改进等,均应包含在本发明的保护范围之内。

Claims (13)

  1. 一种添加控件标识的方法,其特征在于,包括:
    S1,判断能否使用预设方法对控件进行标识;
    S2,对于不能使用预设方法进行标识的所述控件,若获取到所述控件的点击事件的方法名,则将所述方法名作为所述控件的标识;若不能获取到所述控件的点击事件的方法名,则将所述控件对应的字符串作为所述控件的标识。
  2. 根据权利要求1所述的方法,其特征在于,步骤S1中所述使用预设方法对控件进行标识进一步包括:
    若能获取所述控件的属性值,则将所述属性值作为所述控件的标识;
    若不能获取所述控件的属性值,则根据所述控件的类型,将所述控件的图片名或文字作为所述控件的标识。
  3. 根据权利要求2所述的方法,其特征在于,所述控件的类型包括按钮类型和标签类型。
  4. 根据权利要求1所述的方法,其特征在于,所述控件对应的字符串是指所述控件的控件类型名和父控件类型名拼接成的字符串。
  5. 根据权利要求1所述的方法,其特征在于,所述获取到所述控件的点击事件的方法名包括:
    通过方法交换获取所述控件的点击事件的方法名;
    通过分类中添加方法保存所述控件的点击事件的方法名。
  6. 根据权利要求1所述的方法,其特征在于,所述将所述方法名作为所述控件的标识包括:
    通过分类中添加方法获取所述控件的点击事件的方法名;
    通过方法交换将所述方法名作为所述控件的标识。
  7. 根据权利要求5或6所述的方法,其特征在于,所述方法交换包括:
    在所述控件对应的类启动时的加载方法中,控制所述方法交换只执行一次;
    获取原方法和待交换方法,并对所述原方法和所述待交换方法进行交换。
  8. 根据权利要求5或6所述的方法,其特征在于,所述分类中添加方法包括:
    创建分类,并在所述分类中添加赋值方法set或获取值方法get。
  9. 一种添加控件标识的装置,其特征在于,包括:
    判断模块,用于判断能否使用预设方法对控件进行标识;
    标识模块,用于对于不能使用预设方法进行标识的所述控件,若获取到所述控件的点击事件的方法名,则将所述方法名作为所述控件的标识;若不能获取到所述控件的点击事件的方法名,则将所述控件对应的字符串作为所述控件的标识。
  10. 根据权利要求9所述的装置,其特征在于,标识模块中所述使用预设方法对控件进行标识进一步包括:
    若能获取所述控件的属性值,则将所述属性值作为所述控件的标识;
    若不能获取所述控件的属性值,则根据所述控件的类型,将所述控件的图片名或文字作为所述控件的标识。
  11. 一种添加控件标识的设备,其特征在于,包括:
    至少一个处理器;
    以及与所述处理器通信连接的至少一个存储器,其中:所述存储器存储有可被所述处理器执行的程序指令,所述处理器调用所述程序指令能够执行如权利要求1至8任一所述的方法。
  12. 一种非暂态计算机可读存储介质,其特征在于,所述非暂态计算机可读存储介质存储计算机指令,所述计算机指令使所述计算机执行如权利要求1至8任一所述的方法。
  13. 一种计算机程序产品,其特征在于,所述计算机程序产品包括存储在非暂态计算机可读存储介质上的计算机程序,所述计算机程序包括程序指令,当所述程序指令被计算机执行时,使所述计算机执行如权利要求1至8任一所述的方法。
PCT/CN2017/120139 2017-04-11 2017-12-29 一种添加控件标识的方法和装置 WO2018188380A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201710233757.9A CN107085554B (zh) 2017-04-11 2017-04-11 一种添加控件标识的方法和装置
CN201710233757.9 2017-04-11

Publications (1)

Publication Number Publication Date
WO2018188380A1 true WO2018188380A1 (zh) 2018-10-18

Family

ID=59612843

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2017/120139 WO2018188380A1 (zh) 2017-04-11 2017-12-29 一种添加控件标识的方法和装置

Country Status (2)

Country Link
CN (1) CN107085554B (zh)
WO (1) WO2018188380A1 (zh)

Families Citing this family (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107085554B (zh) * 2017-04-11 2019-09-20 武汉斗鱼网络科技有限公司 一种添加控件标识的方法和装置
CN107832403B (zh) * 2017-11-02 2020-05-12 武汉斗鱼网络科技有限公司 目录文件管理方法、装置、电子终端及可读存储介质
CN110704327B (zh) * 2019-10-11 2023-03-31 江苏赛诺格兰医疗科技有限公司 一种pet-ct系统控制软件自动化测试的辅助方法
CN111045941B (zh) * 2019-12-09 2023-08-18 广州品唯软件有限公司 用户界面控件的定位方法、装置及存储介质
CN111176770B (zh) * 2019-12-19 2023-04-18 深圳赛安特技术服务有限公司 防止控件重复点击方法、装置及计算机可读存储介质
CN114416603B (zh) * 2022-03-31 2022-07-12 北京搜狐新动力信息技术有限公司 Ui元素测试方法、装置、存储介质和设备

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103064782A (zh) * 2011-10-21 2013-04-24 腾讯科技(深圳)有限公司 一种获取控件的方法及装置
CN103455414A (zh) * 2012-06-04 2013-12-18 腾讯科技(深圳)有限公司 获取控件的逻辑位置的方法及装置
CN103780448A (zh) * 2012-10-23 2014-05-07 百度在线网络技术(北京)有限公司 一种控件层代码的生成方法及装置
CN104156218A (zh) * 2014-08-18 2014-11-19 浪潮电子信息产业股份有限公司 一种自动识别动态控件的方法
CN105743736A (zh) * 2016-01-27 2016-07-06 武汉联影医疗科技有限公司 自动化测试方法及系统
CN107085554A (zh) * 2017-04-11 2017-08-22 武汉斗鱼网络科技有限公司 一种添加控件标识的方法和装置

Family Cites Families (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US9715483B2 (en) * 2010-09-16 2017-07-25 International Business Machines Corporation User interface for testing and asserting UI elements with natural language instructions
CN103309797B (zh) * 2012-03-09 2016-05-04 阿里巴巴集团控股有限公司 用户界面自动化测试方法及装置
CN104391797B (zh) * 2014-12-09 2017-11-10 北京奇虎科技有限公司 Gui控件的识别方法和装置
CN105095088A (zh) * 2015-09-02 2015-11-25 厦门美图移动科技有限公司 基于uiautomator测试框架的计算器自动化测试方法和测试系统
CN105511873B (zh) * 2015-12-02 2020-05-12 网易(杭州)网络有限公司 用户界面控件展示方法及装置
CN106484407A (zh) * 2016-09-28 2017-03-08 上海银天下科技有限公司 控件显示方法及装置

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103064782A (zh) * 2011-10-21 2013-04-24 腾讯科技(深圳)有限公司 一种获取控件的方法及装置
CN103455414A (zh) * 2012-06-04 2013-12-18 腾讯科技(深圳)有限公司 获取控件的逻辑位置的方法及装置
CN103780448A (zh) * 2012-10-23 2014-05-07 百度在线网络技术(北京)有限公司 一种控件层代码的生成方法及装置
CN104156218A (zh) * 2014-08-18 2014-11-19 浪潮电子信息产业股份有限公司 一种自动识别动态控件的方法
CN105743736A (zh) * 2016-01-27 2016-07-06 武汉联影医疗科技有限公司 自动化测试方法及系统
CN107085554A (zh) * 2017-04-11 2017-08-22 武汉斗鱼网络科技有限公司 一种添加控件标识的方法和装置

Also Published As

Publication number Publication date
CN107085554A (zh) 2017-08-22
CN107085554B (zh) 2019-09-20

Similar Documents

Publication Publication Date Title
WO2018188380A1 (zh) 一种添加控件标识的方法和装置
US11507256B2 (en) Updating data records by adding editing functions to non-editable display elements
US11113475B2 (en) Chatbot generator platform
CN109582301B (zh) 基于任务调度系统的业务处理方法、装置、设备及介质
US10838838B2 (en) Method and apparatus for dealing with abnormality of application program and storage medium
WO2020186809A1 (zh) 基于大数据平台的hive任务调度方法、装置、设备及存储介质
WO2018036342A1 (zh) 基于csar的模型文件的可视化设计方法及装置
WO2019227708A1 (zh) 测试案例的在线调试装置、方法及计算机可读存储介质
US20150310209A1 (en) Executing third-party application
WO2018120965A1 (zh) 自动化测试方法、计算机可读存储介质及装置
US11704139B2 (en) Service processing method and apparatus, electronic device, and storage medium
US10949218B2 (en) Generating an execution script for configuration of a system
US9329979B2 (en) Derivation of generalized test cases
US10684826B2 (en) Method and device for page rendering and validation
US20210232755A1 (en) Machine first approach for identifying accessibility, non-compliances, remediation techniques and fixing at run-time
CN113448862B (zh) 软件版本测试方法、装置及计算机设备
JP2016099857A (ja) 不正プログラム対策システムおよび不正プログラム対策方法
CN107038117B (zh) 一种基于事件处理函数间定义-引用的web自动化测试方法
CN106919374B (zh) 一种脚本生成方法和装置
CN109446077A (zh) 一种数据库测试方法及装置
CN107590062B (zh) 一种多客户端交互的测试方法和装置
JP6516343B2 (ja) アプリケーションユーザーインターフェース自動テスト方法、電子装置、システム及び記憶媒体
TWI756867B (zh) 在作業系統標記物件標籤及產生安全政策的方法及系統
US11740995B2 (en) Source quality check service
CN110221952B (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: 17905184

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 17905184

Country of ref document: EP

Kind code of ref document: A1