Element positioning method and apparatus, and electronic device and storage medium

By generating images of text elements that match page screenshots, it solves the positioning difficulties of traditional methods under front-end frame changes and page position changes, achieves stable and efficient element positioning, and simplifies management.

WO2024174704A1PCT designated stage expired Publication Date: 2024-08-29CHINA TELECOM CLOUD TECH CO LTD

Patent Information

Application Number
PCT/CN2023/140333
Authority / Receiving Office
WO · WO
Patent Type
Applications
Current Assignee / Owner
Priority Date
2023-02-24
Filing Date
2023-12-20
Publication Date
2024-08-29

AI Technical Summary

Technical Problem

Traditional element positioning methods cannot adapt when the front-end framework changes, rely on page position changes, and are inconvenient to manage text elements stored in unstructured data, making it difficult to locate elements in WEB automated testing.

Method used

By generating images of text elements and matching them with page screenshots, the positioning information of the text elements is obtained, ignoring front-end technical architecture and framework changes, and using structured data for positioning to avoid the impact of page position changes.

Benefits of technology

It achieves stable positioning of text elements, avoids the impact of front-end framework changes, does not rely on page position changes, simplifies the management of text elements, and improves the stability and efficiency of WEB automated testing.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN2023140333_29082024_PF_FP_ABST
    Figure CN2023140333_29082024_PF_FP_ABST
Patent Text Reader

Abstract

The embodiments of the present application relate to the technical field of computer testing. Provided are an element positioning method and apparatus, and an electronic device and a storage medium. The method comprises: loading a page under test, and acquiring a font type of said page; acquiring a text element from said page; according to the text element and the font type of said page, generating an image corresponding to the text element; and matching the image corresponding to the text element with a page screenshot of said page, so as to obtain positioning information of the text element in said page. By means of the element positioning method provided in the present embodiments, a text element can be positioned on the basis of text imaging, without being affected by a front-end framework and without depending on a position change in a page, and the element positioning method is conductive to element management.
Need to check novelty before this filing date? Find Prior Art

Description

Element positioning method, device, electronic device and storage medium

[0001] CROSS-REFERENCE TO RELATED APPLICATIONS

[0002] This application claims priority to the Chinese patent application filed with the China Patent Office on February 27, 2023, with application number 202310163234.7 and application name “Element Positioning Method, Device, Electronic Device and Storage Medium”, all contents of which are incorporated by reference into this application. Technical Field

[0003] The embodiments of the present application relate to the field of computer testing technology, and in particular to an element positioning method, device, electronic device, and storage medium. Background Art

[0004] For the field of software testing, automated testing plays a vital role, and WEB (World Wide Web) automated testing is a very important link. In WEB automated testing, the most important issue is the positioning of elements.

[0005] Currently, some traditional element location methods are unable to adapt to the continuous evolution of front-end frameworks, resulting in the inability to locate elements. Some traditional element location methods rely heavily on page stability, making it impossible to locate text elements once the page changes. Furthermore, text elements are stored as unstructured data, which makes their management inconvenient.

[0006] Therefore, for the positioning method of text elements in WEB automated testing, how to achieve it without being affected by the front-end framework, without relying on the position changes of the page, and easy to manage the elements is a technical problem that needs to be solved urgently in this application.

[0007] Overview

[0008] The embodiments of the present application provide an element positioning method, device, electronic device and storage medium, which are intended to locate text elements based on text visualization to avoid being affected by the front-end framework, not relying on the position changes of the page, and facilitating element management.

[0009] A first aspect of an embodiment of the present application provides an element positioning method, the method comprising:

[0010] Load the page to be tested and obtain the font type of the page to be tested;

[0011] Get the text element of the page to be tested;

[0012] Generate an image corresponding to the text element based on the text element and the font type of the page to be tested;

[0013] The image corresponding to the text element is matched with the screenshot of the page to be tested to obtain the positioning information of the text element in the page to be tested.

[0014] Optionally, the font type of the page to be tested includes multiple font types; generating an image corresponding to the text element according to the text element and the font type of the page to be tested includes:

[0015] According to the text elements and the multiple font types, multiple images corresponding to the text elements are generated respectively;

[0016] Match the image corresponding to the text element with the screenshot of the page to be tested to obtain the location information of the text element in the page to be tested, including:

[0017] Matching one of the multiple images with a screenshot of the page to be tested;

[0018] In response to a successful match, obtaining location information of the text element in the page to be tested;

[0019] In response to a matching failure, the remaining images in the plurality of images are matched with the page screenshot of the page to be tested in sequence until one of the remaining images successfully matches the page screenshot of the page to be tested, and the positioning information of the text element in the page to be tested is obtained.

[0020] Optionally, load the page to be tested and obtain the font type of the page to be tested, including:

[0021] Determine the default font type of the browser corresponding to the page to be tested;

[0022] Load the specific font type in the page to be tested;

[0023] Use the default font type and / or a specific font type as the font type for the page under test.

[0024] Optionally, obtain the text elements of the page to be tested, including:

[0025] In response to a user input operation, obtaining a text element of the page to be tested input by the user; and / or,

[0026] According to the page ID of the page to be tested, a pre-stored text element corresponding to the page ID is obtained from the test platform.

[0027] Optionally, based on the text element and the font type of the page to be tested, generate an image corresponding to the text element, including:

[0028] The text element is generated according to the font type of the page to be tested, and a PNG image with a transparent background centered on the text element is obtained to obtain a PNG image corresponding to the text element.

[0029] Optionally, matching the image corresponding to the text element with a screenshot of the page to be tested to obtain location information of the text element in the page to be tested includes:

[0030] The model processes the images corresponding to the text elements and the screenshots of the page to be tested to obtain the coordinate information output by the model;

[0031] The coordinate information output by the model is used as the positioning information of the text element in the page to be tested.

[0032] Optionally, matching the image corresponding to the text element with a screenshot of the page to be tested to obtain location information of the text element in the page to be tested includes:

[0033] The target detection model is used to process the PNG image corresponding to the text element and the screenshot of the page to be tested to obtain the coordinate information of the PNG image corresponding to the text element in the page to be tested;

[0034] Determine the coordinate information of the center point of the PNG image corresponding to the text element according to the coordinate information of the PNG image corresponding to the text element in the page to be tested;

[0035] The coordinate information of the center point is used as the positioning information of the text element in the page to be tested.

[0036] A second aspect of an embodiment of the present application provides an element positioning device, the device comprising:

[0037] The font acquisition module is used to load the page to be tested and obtain the font type of the page to be tested;

[0038] Text acquisition module, used to obtain text elements of the page to be tested;

[0039] An image generation module is used to generate an image corresponding to a text element according to the text element and the font type of the page to be tested;

[0040] The matching module is used to match the image corresponding to the text element with the page screenshot of the page to be tested to obtain the positioning information of the text element in the page to be tested.

[0041] Optionally, the font type of the page to be tested includes multiple font types; the image generation module includes:

[0042] A first image generation submodule is configured to generate a plurality of images corresponding to the text elements according to the text elements and the plurality of font types;

[0043] Matching modules, including:

[0044] A matching submodule, used to match one of the multiple images with a screenshot of the page to be tested;

[0045] A first acquisition submodule is configured to acquire location information of the text element in the page to be tested in response to a successful match;

[0046] The second acquisition submodule is used to match the remaining images in the multiple images with the page screenshot of the page to be tested in sequence in response to the matching failure until one of the remaining images successfully matches the page screenshot of the page to be tested, and obtain the positioning information of the text element in the page to be tested.

[0047] Optional font acquisition module, including:

[0048] The first determination submodule is used to determine the default font type of the browser corresponding to the page to be tested;

[0049] The second determination submodule is used to load a specific font type in the page to be tested;

[0050] The font acquisition submodule is used to use the default font type and / or the specific font type as the font type of the page to be tested.

[0051] Optional text acquisition module, including:

[0052] A first text acquisition submodule is configured to acquire text elements of the page to be tested input by the user in response to an input operation of the user;

[0053] The second text acquisition submodule is used to acquire, according to the page ID of the page to be tested, a pre-stored text element corresponding to the page ID from the test platform.

[0054] Optional, image generation module, including:

[0055] The second image generation submodule is used to generate a PNG image with a transparent background centered on the text element according to the font type of the page to be tested, so as to obtain a PNG image corresponding to the text element.

[0056] Optional, matching modules, including:

[0057] The coordinate information acquisition submodule is used to process the images corresponding to the text elements and the screenshots of the page to be tested through the model to obtain the coordinate information output by the model;

[0058] The positioning information acquisition submodule is used to use the coordinate information output by the model as the positioning information of the text element in the page to be tested.

[0059] Optional, matching modules, including:

[0060] The third determination submodule is used to process the PNG image corresponding to the text element and the page screenshot of the page to be tested through the target detection model to obtain the coordinate information of the PNG image corresponding to the text element in the page to be tested;

[0061] A fourth determining submodule is configured to determine the coordinate information of the center point of the PNG image corresponding to the text element according to the coordinate information of the PNG image corresponding to the text element in the page to be tested;

[0062] The fifth determining submodule is configured to use the coordinate information of the center point as the positioning information of the text element in the page to be tested.

[0063] A third aspect of an embodiment of the present application provides an electronic device, which includes: a memory, a processor, and a computer program stored in the memory and runnable on the processor. When the computer program is executed by the processor, it implements the element positioning method of the first aspect of the embodiment of the present application.

[0064] A fourth aspect of an embodiment of the present application provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the element positioning method of the first aspect of the embodiment of the present application is implemented.

[0065] The element positioning method provided by the embodiment of the present application is as follows: first, the page to be tested is loaded and the font type of the page to be tested is obtained; secondly, the text element of the page to be tested is obtained; then, an image corresponding to the text element is generated according to the text element and the font type of the page to be tested; finally, the image corresponding to the text element is matched with the page screenshot of the page to be tested to obtain the positioning information of the text element in the page to be tested, thereby realizing the positioning of the text element. In this embodiment, the image corresponding to the text element is generated by the text element and the font type derived from the page to be tested itself, and then the image corresponding to the text element is matched with the page screenshot of the page to be tested to find the position of the text element in the page to be tested for positioning. In this way, the identification of text elements after the text is imaged can ignore the influence of the front-end technical architecture and framework. No matter how confused it is, the text element can be found without relying on the position change of the page. Moreover, since the image is generated based on structured text data for positioning, that is, the text image is generated when the method is executed, only the storage of the text needs to be managed, and there will be no management problems caused by unstructured storage, thereby making it more convenient to manage text elements in a structured manner. BRIEF DESCRIPTION OF THE DRAWINGS

[0066] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the following briefly introduces the drawings required for use in the description of the embodiments of the present application. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.

[0067] FIG1 is a flow chart of an element positioning method according to an embodiment of the present application;

[0068] FIG2 is a schematic diagram of text visualization according to an embodiment of the present application;

[0069] FIG3 is a flow chart of a method for locating elements in a WEB automated test based on text visualization according to an embodiment of the present application;

[0070] FIG4 is a structural block diagram of an element positioning device provided by an embodiment of the present application;

[0071] FIG5 is a schematic diagram of an electronic device according to an embodiment of the present application.

[0072] Detailed description

[0073] The following will be combined with the drawings in the embodiments of this application to clearly and completely describe the technical solutions in the embodiments of this application. Obviously, the embodiments described are part of the embodiments of this application, not all of them. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.

[0074] As mentioned above, element location is a crucial step in web automation testing. Traditional element location methods, impacted by new front-end frameworks and technologies, no longer work well. Some traditional element location methods rely on HTML analysis using methods like IDs and XPATH (XML Path Language). However, with the continuous advancement of front-end frameworks and the widespread obfuscation of HTML for security reasons, these traditional methods may not be able to find all elements. More advanced element location methods rely on element images. These methods take screenshots of the elements to be found, store them, and then search for the captured elements across the entire page. However, this method has two drawbacks: first, it relies heavily on page stability. Once the page changes, such as with a new style, background, or font, the location of the text element becomes unreliable. Second, managing the elements on the page requires managing saved element screenshots, which are unstructured binary images and inconvenient to manage.

[0075] Therefore, in order to at least partially solve one or more of the above-mentioned problems and other potential problems, an embodiment of the present application proposes an element positioning method, by visualizing the text elements according to the font type of the page to be tested itself, and then locating the text elements on the page to be tested based on the generated text image. In this way, the influence of the front-end technical architecture and framework can be ignored, and the text elements can be found no matter how confused they are, without relying on the position changes of the page, and there will be no management problems caused by unstructured storage.

[0076] Referring to Figure 1, Figure 1 is a flow chart of an element positioning method according to an embodiment of the present application. As shown in Figure 1, the element positioning method of this embodiment may include the following steps:

[0077] Step S11: Load the page to be tested and obtain the font type of the page to be tested.

[0078] In this embodiment, when locating text elements for WEB automated testing, the page to be tested can be loaded, and during the loading process of the page to be tested, all font types included in the page to be tested can be obtained. The page to be tested in this embodiment can be a WEB page that requires WEB automated testing.

[0079] Step S12: Acquire text elements of the page to be tested.

[0080] In this embodiment, for the positioning of text elements in the page to be tested, the text elements in the page to be tested that need to be positioned can be determined. Among them, when developing for the page to be tested, the text elements to be displayed in the page to be tested can be developed and determined, such as text elements such as "OK", "Search", "Home", etc. Based on this, when the text elements of the page to be tested need to be positioned based on WEB automated testing, the text elements of the page to be tested need to be obtained. The text elements of the page to be tested in this embodiment can be one or more text elements that need to be positioned in the page to be tested.

[0081] Step S13: Generate an image corresponding to the text element according to the text element and the font type of the page to be tested.

[0082] In this embodiment, after obtaining the text elements of the page to be tested and the font type of the page to be tested, the text elements of the page to be tested can be converted into an image corresponding to the text elements according to the font type of the page to be tested. Among them, the image corresponding to the text elements of the present embodiment is: an image containing text elements with the font type of the page to be tested as the text font. It can be understood that this step is to convert the text elements of the page to be tested into a text image of the corresponding font type (i.e., the font type of the page to be tested) according to the font type of the page to be tested.

[0083] Step S14: Match the image corresponding to the text element with the screenshot of the page to be tested to obtain the location information of the text element in the page to be tested.

[0084] In this embodiment, after the text element of the page to be tested is converted into a text image of the font type of the page to be tested, that is, after the image corresponding to the text element is generated, the image corresponding to the text element can be matched with the page screenshot of the page to be tested. For example, a target comparison is performed between the image corresponding to the text element and the page screenshot of the page to be tested. It can be understood that the image corresponding to the text element is the "target", and the position of the image corresponding to the text element in the page to be tested is found, thereby determining the positioning information of the text element in the page to be tested, and realizing the positioning of the text element.

[0085] The screenshot of the page to be tested can be obtained by taking a screenshot of the page to be tested. In this embodiment, the timing for obtaining the screenshot of the page to be tested can be after loading the page to be tested; before, after, or simultaneously with obtaining the text elements of the page to be tested; or before, after, or simultaneously with generating the images corresponding to the text elements. This embodiment does not impose any restrictions on this.

[0086] In this embodiment, a method of identifying text after it is converted into an image is used. The meta-attributes of the text element being tested (the text it contains) are used as a basis, and the actual font of the tested page is used to generate a text image of the corresponding font. This allows the position of the text image within the entire tested page to be accurately identified in real time, thereby locating the text element. This avoids the effects of positional offset and reconstruction of front-end web page elements, and does not rely on positional changes of elements within the page. Furthermore, since positioning is based on converting structured data (text) into images, rather than directly using screenshots of unstructured data, there are no management issues associated with unstructured storage.

[0087] In conjunction with the above embodiments, in one implementation, the present application also provides an element positioning method. In this method, the font type of the page to be tested includes multiple font types; the above step S13 may specifically include step S21, and the above step S14 may specifically include steps S22 to S24:

[0088] Step S21: generating a plurality of images corresponding to the text elements according to the text elements and the plurality of font types.

[0089] In this embodiment, the font type of the page to be tested may include multiple font types. For example, the page to be tested may include multiple font types such as font type A, font type B, and font type C. Based on this, after obtaining the text element and the font type of the page to be tested, multiple images corresponding to the text element can be generated based on the text element and the multiple font types. The multiple images corresponding to the text element correspond one-to-one to the multiple font types.

[0090] For example, multiple font types include font type A, font type B, and font type C. Then, the multiple images corresponding to the text elements generated based on the text elements and the multiple font types include: an image of font type A corresponding to the text element, an image of font type B corresponding to the text element, and an image of font type C corresponding to the text element.

[0091] Step S22: matching one of the multiple images with the screenshot of the page to be tested.

[0092] In this embodiment, after obtaining multiple images with diverse text elements, any one of the multiple images can be matched with a page screenshot of the page to be tested, that is, a target comparison is performed between any one of the multiple images and the page screenshot of the page to be tested to determine whether any one of the multiple images successfully matches the page screenshot of the page to be tested.

[0093] Step S23: In response to a successful match, the location information of the text element in the page to be tested is obtained.

[0094] In this embodiment, when it is determined that one of the multiple images to be matched is in the page screenshot of the page to be tested, that is, it is determined that one of the multiple images to be matched is successfully matched with the page screenshot of the page to be tested, in response to the successful match, the position of the image corresponding to the text element (that is, one of the multiple images to be matched) in the page to be tested can be found, thereby determining the positioning information of the text element in the page to be tested, and realizing the positioning of the text element.

[0095] Step S24: In response to a matching failure, the remaining images in the plurality of images are matched with the screenshot of the page to be tested in sequence until one of the remaining images successfully matches the screenshot of the page to be tested, thereby obtaining the positioning information of the text element in the page to be tested.

[0096] In this embodiment, if it is determined that one of the multiple images being matched is not in the screenshot of the page to be tested, that is, if it is determined that one of the multiple images being matched fails to match the screenshot of the page to be tested, in response to the match failure, the remaining images in the multiple images are matched with the screenshot of the page to be tested in sequence to determine whether the match is successful. If the match is successful, the positioning information of the text element in the page to be tested can be obtained. If the match fails, one of the remaining images that has not yet been matched is matched with the screenshot of the page to be tested until one of the remaining images successfully matches the screenshot of the page to be tested, at which point the positioning information of the text element in the page to be tested can be obtained. The remaining images in this embodiment are the images in the multiple images other than the image that was matched the first time.

[0097] For example, the multiple images corresponding to the text element Q include image 1, image 2, image 3 and image 4. Then, any one of the multiple images (such as image 2) is first matched with the page screenshot of the page to be tested to determine whether the match is successful. If the match is successful, the positioning information of the text element Q in the page to be tested can be obtained based on the position information of image 2 in the page screenshot of the page to be tested; if the match fails, the remaining images are matched with the page screenshot of the page to be tested in turn. For example, image 1 among the remaining images can be matched with the page screenshot of the page to be tested first to determine whether the match is successful. If the match is successful, the positioning information of the text element Q in the page to be tested can be obtained based on the position information of image 1 in the page screenshot of the page to be tested; if the match fails, image 3 among the remaining images is matched with the page screenshot of the page to be tested to determine whether the match is successful, ..., until one of the remaining images is successfully matched with the page screenshot of the page to be tested, the positioning information of the text element Q in the page to be tested can be obtained based on the position information of the successfully matched image in the page screenshot of the page to be tested.

[0098] It can be understood that the text elements of this embodiment may include one or more text elements. When positioning the text elements, for each text element, multiple images corresponding to the text element of corresponding multiple font types can be generated respectively, and then the above steps S21-S24 are executed in sequence for the text element, so as to achieve the positioning of each text element.

[0099] In addition, in one embodiment, the text element may first generate an image corresponding to the text element for one of the multiple font types, and then match the image corresponding to the text element with the screenshot of the page to be tested to determine whether the match is successful. If the match is successful, the positioning information of the text element in the page to be tested can be obtained based on the position information of the image in the screenshot of the page to be tested; if the match fails, the text element may generate another image corresponding to the text element for another font type among the multiple font types, and then match the another image corresponding to the text element with the screenshot of the page to be tested to determine whether the match is successful, ... until the image corresponding to the text element generated by the text element according to one of the multiple font types can be successfully matched with the screenshot of the page to be tested, and the positioning information of the text element in the page to be tested is obtained.

[0100] In this embodiment, when the font type of the page to be tested includes multiple font types, multiple images corresponding to the text element can be matched with the page screenshot of the page to be tested in sequence until one of the multiple images successfully matches the page screenshot of the page to be tested, thereby achieving the positioning of the text element.

[0101] In combination with the above embodiments, in one embodiment, the present application also provides an element positioning method. In this method, the above step S11 may specifically include steps S31 to S33:

[0102] Step S31: Determine the default font type of the browser corresponding to the page to be tested.

[0103] Generally speaking, a browser is set with a default font type. Therefore, in the present embodiment, the default font type of the browser corresponding to the page to be tested can be determined during the process of loading the page to be tested.

[0104] Step S32: Loading a specific font type in the page to be tested.

[0105] In this embodiment, the specific font type existing in the page to be tested can also be loaded during the process of loading the page to be tested, thereby obtaining the specific font type in the page to be tested. For example, the specific font type can be a font determined by the web page style of the page to be tested.

[0106] Step S33: Using the default font type and / or the specific font type as the font type of the page to be tested.

[0107] In this embodiment, after obtaining the default font type and / or specific font type of the page to be tested, the default font type and / or specific font type can be used as the font type of the page to be tested, thereby obtaining all font types derived from the page to be tested itself.

[0108] In this embodiment, the font type of the page to be tested is obtained from the default font of the browser of the page to be tested or the font determined by the style of the page to be tested, all of which are derived from the page to be tested itself. Therefore, the text elements are converted into images according to the font type and then matched, thereby avoiding the influence of position offset and reconstruction of the front-end WEB page elements, and can well realize the positioning of text elements.

[0109] In combination with the above embodiments, in one implementation, the present application also provides an element positioning method. In this method, the above step S12 may specifically include step S41 and / or step S42:

[0110] Step S41: in response to the user's input operation, obtaining the text element of the page to be tested input by the user.

[0111] In this embodiment, when locating text elements for WEB automated testing, the user can manually input the text element to be located, that is, input the text element name (text), such as inputting: "OK", "Search", etc., so that in response to the user's input operation, the text element of the page to be tested input by the user is read according to the input operation, thereby obtaining the text element of the page to be tested input by the user.

[0112] Step S42: According to the page ID of the page to be tested, obtain the pre-stored text element corresponding to the page ID from the test platform.

[0113] In this embodiment, loading the page to be tested can also obtain the page ID of the page to be tested. After obtaining the page ID of the page to be tested, a text data request carrying the page ID can be sent to the test platform (such as an automated test platform) based on the page ID of the page to be tested, and the pre-stored text elements corresponding to the page ID can be pulled from the test platform, thereby obtaining the text elements of the page to be tested.

[0114] Among them, this embodiment can be to input the text information of each developed page to be tested into the automated testing platform in advance for storage and management. For example, the automated testing platform associates these structured text information with the page ID of the corresponding page to be tested and saves it in the database of the automated testing platform, so that the automated testing platform can easily perform relevant management of the stored text (structured data).

[0115] In this embodiment, pre-stored structured text information can be directly pulled from the test platform, or text information can be manually input, or a combination of the two methods: that is, pre-stored text elements can be pulled from the outside, and text elements to be located can be manually added in real time, thereby achieving diversity in text element acquisition.

[0116] In combination with the above embodiments, in one implementation, the present application also provides an element positioning method. In this method, the above step S14 may specifically include steps S51 and S52:

[0117] Step S51: Processing the image corresponding to the text element and the screenshot of the page to be tested by the model to obtain coordinate information output by the model.

[0118] In this embodiment, the image corresponding to the text element can be matched with the screenshot of the page to be tested in a model manner to obtain a matching result, thereby obtaining the positioning information of the text element in the page to be tested.

[0119] Specifically, a model capable of image target matching may be pre-trained, such that the input of the trained model is: the image corresponding to the text element and the screenshot of the page to be tested; and the output of the trained model is: the coordinate information of the center point of the image corresponding to the text element in the screenshot of the page to be tested. It is understandable that if the model determines through processing that the image corresponding to the text element is not in the screenshot of the page to be tested, that is, the model determines that the image corresponding to the text element and the screenshot of the page to be tested are not successfully matched, then the model cannot output the coordinate information and may output a prompt message indicating the failed match, such as "no match" or "unable to find location".

[0120] Among them, the coordinate information of this embodiment is pixel coordinate information. This embodiment establishes a pixel coordinate system based on the size of the page screenshot of the page to be tested obtained when taking a screenshot of the page to be tested. Based on this pixel coordinate system, the model outputs the coordinate information of the center point of the image corresponding to the text element in the page screenshot of the page to be tested.

[0121] Step S52: using the coordinate information output by the model as the positioning information of the text element in the page to be tested.

[0122] In this embodiment, after obtaining the coordinate information of the center point of the image corresponding to the text element output by the model in the page screenshot of the page to be tested, the coordinate information output by the model can be determined as the positioning information of the text element in the page to be tested, thereby realizing the positioning of the text element.

[0123] Combined with the above embodiments, in one implementation, the embodiments of the present application further provide an element positioning method. In this method, step S13 above may specifically include step S61:

[0124] Step S61: Generate a PNG image with a transparent background centered on the text element according to the font type of the page to be tested for the text element, and obtain the PNG image corresponding to the text element.

[0125] In this embodiment, after obtaining the text element of the page to be tested and the font type of the page to be tested, the text element can be used to generate a PNG image with a transparent background centered on the text element according to the font type of the page to be tested, so as to obtain the PNG image corresponding to the text element. As shown in Figure 2, Figure 2 is a schematic diagram of text image conversion shown in an embodiment of the present application.

[0126] For example, if the font type of the page to be tested includes "KaiTi" and the text element is "OK", then the text element "OK" is used to generate a PNG image with a transparent background corresponding to the font according to the font type "KaiTi", and the two characters "OK" in the "KaiTi" font are at the center of the PNG image. In an optional implementation, the size of the PNG image generated by the text according to the font type can be a preset fixed size, and the specific value of the fixed size can be freely selected according to requirements.

[0127] In this embodiment, generating a PNG image with a transparent background for the text element according to the font type of the page to be tested can make full use of the characteristics of the PNG file type to remove the interference of the background, and further improve the matching accuracy between the image corresponding to the text element and the page screenshot of the page to be tested through text image conversion.

[0128] Combined with the above embodiments, in one implementation, the embodiments of the present application further provide an element positioning method. In this method, step S14 above may specifically include steps S71 to S73:

[0129] Step S71: Process the PNG image corresponding to the text element and the page screenshot of the page to be tested through a target detection model, and obtain the coordinate information of the PNG image corresponding to the text element in the page to be tested.

[0130] In this embodiment, a target detection model can be trained in advance. This target detection model can perform target matching on the PNG image corresponding to the text element and the page screenshot of the page to be tested to obtain a matching result. The input of this target detection model can be: the PNG image corresponding to the text element and the page screenshot of the page to be tested; the output of this target detection model can be: the coordinate information of the PNG image corresponding to the text element in the page to be tested.

[0131] In an optional embodiment, the coordinate information of the PNG image corresponding to the text element in the page to be tested refers to the BOX coordinate information of the PNG image corresponding to the text element in the page to be tested, where the BOX coordinates refer to the area coordinates, which in this embodiment can be understood as the coordinate information of the four vertices of the PNG image corresponding to the text element in the page to be tested.

[0132] It can be understood that if the target detection model determines that the PNG image corresponding to the text element is not in the page screenshot of the page to be tested, that is, the target detection model determines that the PNG image corresponding to the text element is not successfully matched with the page screenshot of the page to be tested, then the target detection model cannot output the coordinate information, but can output prompt information such as "no match" and "unable to find location" to indicate the matching failure.

[0133] Among them, the coordinate information of this embodiment is pixel coordinate information, which is a pixel coordinate system established based on the size of the page screenshot of the page to be tested obtained when taking a screenshot of the page to be tested. Based on this pixel coordinate system, the target detection model outputs the coordinate information of the PNG image corresponding to the text element in the page to be tested.

[0134] Step S72: Determine the coordinate information of the center point of the PNG image corresponding to the text element according to the coordinate information of the PNG image corresponding to the text element in the page to be tested.

[0135] Since the text element is at the center of the PNG image when generating the PNG image corresponding to the text element, this embodiment can determine the coordinate information of the center point of the PNG image corresponding to the text element based on the coordinate information of the PNG image corresponding to the text element in the page to be tested, so as to accurately locate the text element based on the position of the center point of the PNG image.

[0136] Step S73: Using the coordinate information of the center point as the positioning information of the text element in the page to be tested.

[0137] In this embodiment, after obtaining the coordinate information of the center point of the PNG image corresponding to the text element, the coordinate information of the center point of the PNG image corresponding to the text element can be determined as the positioning information of the text element in the page to be tested, thereby realizing the positioning of the text element.

[0138] In another embodiment, as shown in FIG3 , FIG3 is a flow chart of a method for locating elements in a WEB automated test based on text visualization according to an embodiment of the present application.

[0139] In Figure 3, when positioning text elements in a WEB automated test, the page under test is first loaded; secondly, the input element text is obtained, which is the text element that needs to be located in the page under test; then a screenshot of the loaded page is taken as a whole to obtain a screenshot of the page under test; then the page font is queried, that is, the font loading of the page under test is detected, and all fonts are obtained, where all fonts may include the default font of the browser corresponding to the page under test and / or the font determined by the WEB page style; then the obtained text element is converted into a text image according to one of the obtained fonts, for example, the text generates a transparent background PNG image of the corresponding font according to a font, and then in the page screenshot To find the text image, for example, the text image and the page screenshot can be compared by a detection model to determine whether the position of the text image can be found in the page screenshot, that is, whether the match is successful; if the position of the text image cannot be found in the page screenshot, that is, it is determined that the match has failed. At this time, the text can be converted into a text image according to another font, and then the target matching of the text image and the page screenshot can be continued until it is determined that the position of the text image can be found in the page screenshot, that is, it is determined that the match is successful, thereby obtaining the output element position information, such as the coordinate information of the center point of the output text image in the page screenshot, and using the coordinate information of the center point as the coordinate information of the text element, thereby accurately realizing the positioning of the text element.

[0140] Through the method of using text image recognition in this embodiment, the meta-attribute of the target element to be tested, that is, the text contained therein, is used as input, and the actual font of the page to be tested is used to generate a text image of the corresponding font. The position of the generated transparent background text image in the overall page is identified, thereby obtaining its position coordinates. This application combines and utilizes the transparent background characteristics of PNG images to remove background interference, uses structured stored text to be converted into images for recognition, and avoids the impact caused by the position offset and reconstruction of front-end WEB page elements.

[0141] That is, the advantages of this embodiment include at least:

[0142] 1. Text recognition after image conversion can ignore the influence of front-end technical architecture and framework, and can find elements regardless of obfuscation;

[0143] 2. Since elements are text images generated during execution, only the storage of text needs to be managed, making it easier to manage all elements in a structured manner;

[0144] 3. Use the method of text image recognition to find the location of the text in the page for positioning. It does not rely on the position changes of elements in the page, nor does it cause management problems due to unstructured storage. It has a good effect on the problem of element positioning.

[0145] It should be noted that for the method embodiments, for the sake of simplicity, they are all expressed as a series of action combinations, but those skilled in the art should be aware that the embodiments of the present application are not limited by the order of the actions described, because according to the embodiments of the present application, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions involved are not necessarily required by the embodiments of the present application.

[0146] Based on the same inventive concept, an embodiment of the present application provides an element positioning device 400. Referring to FIG4 , FIG4 is a structural block diagram of the element positioning device provided by an embodiment of the present application. As shown in FIG4 , the device 400 includes:

[0147] The font acquisition module 401 is used to load the page to be tested and obtain the font type of the page to be tested;

[0148] The text acquisition module 402 is used to acquire text elements of the page to be tested;

[0149] The image generation module 403 is used to generate an image corresponding to the text element according to the text element and the font type of the page to be tested;

[0150] The matching module 404 is used to match the image corresponding to the text element with the screenshot of the page to be tested to obtain the location information of the text element in the page to be tested.

[0151] Optionally, the font type of the page to be tested includes multiple font types; the image generation module 403 includes:

[0152] A first image generation submodule is configured to generate a plurality of images corresponding to the text elements according to the text elements and the plurality of font types;

[0153] Matching modules, including:

[0154] A matching submodule, used to match one of the multiple images with a screenshot of the page to be tested;

[0155] A first acquisition submodule is configured to acquire location information of the text element in the page to be tested in response to a successful match;

[0156] The second acquisition submodule is used to match the remaining images in the multiple images with the page screenshot of the page to be tested in sequence in response to the matching failure until one of the remaining images successfully matches the page screenshot of the page to be tested, and obtain the positioning information of the text element in the page to be tested.

[0157] Optionally, the font acquisition module 401 includes:

[0158] The first determination submodule is used to determine the default font type of the browser corresponding to the page to be tested;

[0159] The second determination submodule is used to load a specific font type in the page to be tested;

[0160] The font acquisition submodule is used to use the default font type and / or the specific font type as the font type of the page to be tested.

[0161] Optionally, the text acquisition module 402 includes:

[0162] A first text acquisition submodule is configured to acquire text elements of the page to be tested input by the user in response to an input operation of the user;

[0163] The second text acquisition submodule is used to acquire, according to the page ID of the page to be tested, a pre-stored text element corresponding to the page ID from the test platform.

[0164] Optionally, the image generation module 403 includes:

[0165] The second image generation submodule is used to generate a PNG image with a transparent background centered on the text element according to the font type of the page to be tested, so as to obtain a PNG image corresponding to the text element.

[0166] Optionally, the matching module 404 includes:

[0167] The coordinate information acquisition submodule is used to process the images corresponding to the text elements and the screenshots of the page to be tested through the model to obtain the coordinate information output by the model;

[0168] The positioning information acquisition submodule is used to use the coordinate information output by the model as the positioning information of the text element in the page to be tested.

[0169] Optionally, the matching module 404 includes:

[0170] The third determination submodule is used to process the PNG image corresponding to the text element and the page screenshot of the page to be tested through the target detection model to obtain the coordinate information of the PNG image corresponding to the text element in the page to be tested;

[0171] A fourth determining submodule is configured to determine the coordinate information of the center point of the PNG image corresponding to the text element according to the coordinate information of the PNG image corresponding to the text element in the page to be tested;

[0172] The fifth determining submodule is configured to use the coordinate information of the center point as the positioning information of the text element in the page to be tested.

[0173] Based on the same inventive concept, another embodiment of the present application provides a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, it implements the steps in the element positioning method of any of the above embodiments of the present application.

[0174] Based on the same inventive concept, another embodiment of the present application provides an electronic device 500, as shown in Figure 5. Figure 5 is a schematic diagram of an electronic device according to one embodiment of the present application. The electronic device includes a memory 502, a processor 501, and a computer program stored in the memory and executable on the processor. When executed by the processor, the computer program implements the steps of the element location method according to any of the above embodiments of the present application.

[0175] As for the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.

[0176] The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referenced to each other.

[0177] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, devices, or computer program products. Therefore, the embodiments of the present application may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Furthermore, the embodiments of the present application may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0178] The present application embodiment is described with reference to the flow chart and / or block diagram of the method, terminal device (system), and computer program product according to the embodiment of the present application. It should be understood that each process and / or box in the flow chart and / or block diagram and the combination of the process and / or box in the flow chart and / or block diagram can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor or other programmable data processing terminal device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing terminal device produce a device for realizing the function specified in one process or multiple processes and / or one box or multiple boxes of the flow chart.

[0179] These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing terminal device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce a manufactured product including an instruction device that implements the functions specified in one or more processes in the flowchart and / or one or more boxes in the block diagram.

[0180] These computer program instructions can also be loaded onto a computer or other programmable data processing terminal device so that a series of operating steps are executed on the computer or other programmable terminal device to produce computer-implemented processing, so that the instructions executed on the computer or other programmable terminal device provide steps for implementing the functions specified in one or more processes in the flowchart and / or one or more boxes in the block diagram.

[0181] Although preferred embodiments of the present invention have been described, those skilled in the art may make additional changes and modifications to these embodiments once they become aware of the basic inventive concepts. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the embodiments of the present invention.

[0182] Finally, it should be noted that, in this document, relational terms such as first and second, etc., are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations. Moreover, the terms "comprises," "comprising," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or terminal device that includes a series of elements includes not only those elements, but also other elements not explicitly listed, or elements inherent to such process, method, article, or terminal device. In the absence of further limitations, an element defined by the phrase "comprising a ..." does not exclude the presence of additional identical elements in the process, method, article, or terminal device that includes the element.

[0183] The above is a detailed introduction to the element positioning method, device, electronic device and storage medium provided by the present application. Specific examples are used in this article to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method of the present application and its core idea; at the same time, for general technical personnel in this field, based on the ideas of the present application, there will be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.

Claims

1. A method for locating an element, It is characterized in that The method comprises: Loading a page to be tested, and obtaining the font type of the page to be tested; Obtaining text elements of the page to be tested; Generate an image corresponding to the text element according to the text element and the font type of the page to be tested; The image corresponding to the text element is matched with the page screenshot of the page to be tested to obtain the location information of the text element in the page to be tested.

2. The element positioning method according to claim 1, It is characterized in that The font type of the page to be tested includes a plurality of font types; and generating an image corresponding to the text element according to the text element and the font type of the page to be tested includes: Generating a plurality of images corresponding to the text elements respectively according to the text elements and the plurality of font types; The step of matching the image corresponding to the text element with the screenshot of the page to be tested to obtain the location information of the text element in the page to be tested includes: Matching one of the multiple images with the page screenshot of the page to be tested; In response to a successful match, obtaining location information of the text element in the page to be tested; In response to a matching failure, the remaining images in the multiple images are matched with the page screenshot of the page to be tested in sequence until one of the remaining images successfully matches the page screenshot of the page to be tested, and the positioning information of the text element in the page to be tested is obtained.

3. The element positioning method according to claim 1, It is characterized in that The step of loading a page to be tested and obtaining a font type of the page to be tested includes: Determine the default font type of the browser corresponding to the page to be tested; Loading a specific font type in the page to be tested; The default font type and / or the specific font type is used as the font type of the page to be tested.

4. The element positioning method according to claim 1, It is characterized in that The step of obtaining the text element of the page to be tested includes: In response to a user's input operation, obtaining a text element of the page to be tested input by the user; and / or, According to the page ID of the page to be tested, a pre-stored text element corresponding to the page ID is obtained from the test platform.

5. The element positioning method according to claim 1, It is characterized in that The step of generating an image corresponding to the text element according to the text element and the font type of the page to be tested includes: The text element is generated according to the font type of the page to be tested, and a PNG image with a transparent background centered on the text element is obtained to obtain a PNG image corresponding to the text element.

6. The element positioning method according to claim 1, It is characterized in that The step of matching the image corresponding to the text element with the screenshot of the page to be tested to obtain the location information of the text element in the page to be tested includes: Processing the image corresponding to the text element and the screenshot of the page to be tested through the model to obtain coordinate information output by the model; The coordinate information output by the model is used as the positioning information of the text element in the page to be tested.

7. The element positioning method according to claim 5, It is characterized in that The step of matching the image corresponding to the text element with the screenshot of the page to be tested to obtain the location information of the text element in the page to be tested includes: Processing the PNG image corresponding to the text element and the page screenshot of the page to be tested by the target detection model to obtain coordinate information of the PNG image corresponding to the text element in the page to be tested; Determine the coordinate information of the center point of the PNG image corresponding to the text element according to the coordinate information of the PNG image corresponding to the text element in the page to be tested; The coordinate information of the center point is used as the positioning information of the text element in the page to be tested.

8. An element positioning device, It is characterized in that The device comprises: A font acquisition module is used to load a page to be tested and acquire the font type of the page to be tested; A text acquisition module, used to acquire text elements of the page to be tested; An image generation module is used to generate an image based on the font type of the text element and the page to be tested. Type, generating an image corresponding to the text element; The matching module is used to match the image corresponding to the text element with the page screenshot of the page to be tested to obtain the positioning information of the text element in the page to be tested.

9. The element positioning device according to claim 8, It is characterized in that The font type of the page to be tested includes multiple font types; the image generation module includes: A first image generation submodule, configured to generate a plurality of images corresponding to the text elements according to the text elements and the plurality of font types; The matching module comprises: A matching submodule, used for matching one of the multiple images with the page screenshot of the page to be tested; A first acquisition submodule, configured to acquire location information of the text element in the page to be tested in response to a successful match; The second acquisition submodule is used to match the remaining images of the multiple images with the page screenshot of the page to be tested in sequence in response to a matching failure, until one of the remaining images successfully matches the page screenshot of the page to be tested, and obtain the positioning information of the text element in the page to be tested.

10. The element positioning device according to claim 8, It is characterized in that The font acquisition module includes: A first determination submodule is used to determine the default font type of the browser corresponding to the page to be tested; A second determination submodule is used to load a specific font type in the page to be tested; The font acquisition submodule is used to use the default font type and / or the specific font type as the font type of the page to be tested.

11. The element positioning device according to claim 8, It is characterized in that The text acquisition module comprises: A first text acquisition submodule, configured to acquire, in response to an input operation of a user, a text element of the page to be tested input by the user; The second text acquisition submodule is used to acquire, according to the page ID of the page to be tested, a pre-stored text element corresponding to the page ID from the test platform.

12. The element positioning device according to claim 8, It is characterized in that The image generation module comprises: The second image generation submodule is used to generate the text element according to the image of the page to be tested. The font type generates a PNG image with a transparent background centered on the text element, and obtains the PNG image corresponding to the text element.

13. The element positioning device according to claim 8, It is characterized in that The matching module comprises: A coordinate information acquisition submodule, used to process the image corresponding to the text element and the page screenshot of the page to be tested through a model to obtain the coordinate information output by the model; The positioning information acquisition submodule is used to use the coordinate information output by the model as the positioning information of the text element in the page to be tested.

14. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, It is characterized in that When the computer program is executed by the processor, the element positioning method according to any one of claims 1 to 7 is implemented.

15. A computer-readable storage medium having a computer program stored thereon, It is characterized in that When the computer program is executed by a processor, the element positioning method according to any one of claims 1 to 7 is implemented.

Citation Information

Patent Citations

  • Page element positioning method, page testing method and related devices

    CN111309618A

  • Page testing method and device, storage medium and electronic equipment

    CN113094286A

  • Page test method and device, electronic equipment and medium

    CN114924959A

  • Element positioning method and device, electronic equipment and storage medium

    CN115830602A

  • Automated non-native table representation annotation for machine-learning models

    US20210319356A1

Cited By

  • Visual semantic fusion page element positioning method based on large model

    CN120257213A