In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >
Share
Shulou(Shulou.com)06/01 Report--
Mobile APP testing is in the process of continuous exploration and evolution, and mobile banking is the main position of financial technology war of major banks at present. How to test mobile banking better and faster is a hot topic, and it is also a topic worthy of in-depth study. Taking a mobile banking test as an example, this paper describes the SoloPi case execution recording converted into Appium script integrated into jenkins, and completes the real machine concurrent execution practice process after automated deployment, and provides solutions to some problems existing in the use of Appium 1.15.1 and Android 10, hoping to provide more reference for mobile APP testing. 1. Automatic construction and testing of SoloPi and use cases SoloPi is a mobile APP testing tool developed by Ant Financial Services. It provides script recording, editing, playback, result display and multi-control on one machine, that is, one mobile phone can control multiple mobile phones to execute scripts through socket communication between devices. The recording and execution of test cases are completed in the SoloPi APP on the mobile phone side. SoloPi use cases can be converted into Appium scripts through officially provided conversion tools, which provide conditions for automated deployment of use cases and jenkins execution of builds. As shown in the figure below, this process can be summarized into the following four steps: 1. SoloPi records the test transaction and exports the test case to JSON file after playback; 2. For example, use the conversion tool provided by SoloPi official to convert the JSON file into Appium script; 3. Modify the desired_caps{} and webdriver.Remote() parameters in the script, and improve the script steps to achieve concurrency; 4. Use jenkins to manage Appium script execution. 2. 1. Install android studio, set environment variable Path, C:\Users\XXX\AppData\Local\Android\Sdk\platform-tools\ C: \Users\XXX\AppData\Local\Android\Sdk\build-tools\29.0.3\ 2. Install python3 and Appium-python-Client v0.5. 3. Install Appium Desktop v1.15.1. 4. Install Jenkins 2.190.3. 2.1 SoloPi use case recording and JSON file export Start SoloPi, need to connect to the computer to open adb authorization, here to a certain line of mobile banking APP financial secretary to perform login as an example to break down the steps. First, slide down to the financial secretary on the APP homepage, click the secretary, and complete the login operation. The specific steps are shown in the following figure. Use SoloPi Converter to convert the exported JSON file into an Appium script. Here, you need to select the element search method used to generate the script, including class_name, ResourceId, Xpath, Text... Select Text if the node contains text. 2.2 Connectivity verification between Appium and mobile phone Before executing the script, it is necessary to determine whether the tested terminal can communicate with Appium server and verify whether the tested app can be invoked. The session checker provided by Appium desktop can meet this requirement. Appium desktop session manager provides an editor to generate desired_caps. After the converter provided by SoloPi is converted, the variable needs to be reassigned according to the actual situation. The parameters include platformName, platformVersion, deviceName, appPackag, appActivity, automationName, etc., as follows: 1. deviceName can be obtained by commanding adb devices. 2. Before appPackag and appActivity are acquired, test the mobile phone to connect to the computer, start the APP under test, and execute the following command: adb shell dumpsys activity| find "mFocusedActivity" or adb shell dumpsys window w| findstr \/|findstr name=(Note: Android 7.0 and above). AppPackage and appActivity are obtained after execution, where appPackage = com.android.bankabc, appActivity=com.alipay.mobile.quinox.LauncherActivity It should be noted that for apps with a launch page, appActivity needs to set the value of the launch page, that is, use the adb shell command immediately after the launch page opens. Appium 1.51.1 and Android 10 currently have compatibility issues using uiautomator2, automationName uses uiautomator1. Start Appium desktop to open the session manager, fill in the above values, the editor automatically generates a string in JSON format, the JSON string needs to be assigned to the desired_caps variable, as shown in the figure below, after the session manager is started, such as the Appium edit window is displayed, that is, the connection is successful. 2.3 Perfect Appium Script SoloPi Converter converts exported JSON files into Appium scripts. The converted code needs to be simply modified to execute. The contents that need to be modified are as follows. 1. Modify the connection parameter. The Appium script converted from SoloPi lacks key parameters. First, assign the JSON above to desired_caps and define remote server. There is a compatibility problem with an Android 10 mobile phone used for testing. Here, the automationName specified is uiautator1. 2. Modify the script screenshot storage path. This section of code is automatically generated by the conversion tool. The SCREEN obtained can be used by testers later. If there is no need, this section of code can be commented to avoid compilation failure. Get the width and height values of the device screenshot by making get_screenshot_as_file and store them in the SCREEN variable. Here, the temporary storage path of the script defaults to "/tmp/xxx.png" and can be modified to the local actual path. 3. Modify the function ① Use tag_name to locate the element in the original code. This function is searched through the tag tag of H5. The classname is selected during the conversion in the test process, which needs to be modified. The code generated here first obtains the rect attribute of the current node type of the app (this attribute obtains the size and dimension of the element, and the related function of returning the screen size is not directly used here, possibly to consider the case where the app runs in window mode/or has a bottom bar), which provides the basis for the relevant parameters of subsequent screen sliding.② In the figure below, the custom function swipe encapsulates the Appium framework's sliding screen function swipe. The parameters of Appium framework function swipe include startx, starty, endx, endy, duration, where startx, starty, endx, endy need to input the pixel coordinates of the screen. The coordinate offset interval of the start and end positions recorded in the original script of SoloPi is [0,1](this value represents the offset of the position from the center point of the screen, and the default screen upper left corner is (0,0) and the lower right corner is (1,1)). In the original code, the coordinate value of the end slide appears negative, manually change it to the correct value, it is best to manually debug to get a satisfactory position. The custom swipe method transmits parameters to load_x_y to process them into screen pixel coordinates, and processes the two sets of offset values with load_x_y to obtain the actual pixel coordinate values (fx,fy) and (tx,ty) of the slide. Note: In load_x_y, rect.left and rect.top are also automatically generated by the conversion tool. There is no such item in the dictionary returned from step ①, so it should be deleted. When indexing width and height values, you should also change to the dictionary value method. In addition, the driver parameter in swipe should also be deleted. Modify the specific implementation steps, since Appium 1.5 has removed support for by_name. Replace with uiautomator method to find text: assert driver.find_element_by_android_uiautomator ('text (\"Dear user, hello\")').text == "Dear user, hello" Hide the keyboard and replace as follows: ④ After modification, the script execution is completed. The execution process of each step of the execution process can be recorded by writing a log, but it is not optimal for the mobile terminal to judge the specific occurrence of errors. Screenshots are saved after each step is executed, which is more conducive to testers to locate the cause of the problem. During execution, add a screenshot function at the end of each step. After the test, screenshots are automatically generated in the folder. 2.4 Before using jenkins remote call execution, you need to use PyCharm to execute on the remote machine to verify the connectivity between the client and the server, and then start jenkins by creating an empty project and establishing an environment variable for the directory of test cases for subsequent modification. Then enter the compile command, save the project compiled, the results of successful execution. Note that the screenshot path in the script should be changed to the path of the jenkins server, not the path on the Appium server, depending on whether jenkins is deployed with Appium server. 2.5 The real machine concurrently performs the above operations, only using one android device, the following describes the method performed by multiple devices. First verify connectivity with server, modify desired_caps, use 2 Android devices, Android 7.0 and 10.0 respectively, first use session editor to verify connectivity. Use the command to check that 2 devices have been connected to Appium server, start 2 Appium servers, each server communicates with one of the phones, if 4 phones, you need to start 4 Appium servers. When starting two Appium, set up a separate port for the second Appium. After the server starts normally, in the execution script, the main flow of the use case is defined in the run method, which contains 3 parameters. url and desired_caps are the parameters necessary to start the session, and picloc is the specified location for screenshot generation. Usually write multi-threaded or multi-process multi-do using threading and multiprocess to achieve, two methods, as shown in the figure: the above code after execution, is actually executed according to CPU time slicing, if the code logic is very short, or execution is fast, will immediately get results, if the code execution efficiency is very slow, the final result is actually in serial operation. In the above code, MEIZU and honorV20 in the actual execution process, MEIZU will be executed once, and then honorV20 will be executed, loop repeated. Therefore, here we use ProcessPoolExecutor process pool under concurrent.futures module, which can take advantage of multicore CPU and let scripts execute in parallel. Submit commits instances to the process pool and schedules process execution if the CPU has free cores. The main function is as follows. It should be noted here that when multiple devices execute in parallel, you need to specify the parameter udid in desired_caps, which is obtained through adb devices. newCommandTimeout refers to the timeout time of the newly obtained command by the server: after execution, you can see that the process is not executed in "serial". The final execution result, the two machines can execute simultaneously, and save the screenshot in their respective price folders. This paper mainly describes the process of transferring process recording to Appium script based on SoloPi in detail from the perspective of practical operation, taking mobile banking interface test as an example, and explains the configuration of tools, environment and parameters that need to be used. By integrating Appium scripts into jenkins, the automatic deployment and execution of scripts and the storage of results are realized, and the practical process of single machine execution and multi-machine execution is described.
The methods and methods of mobile banking testing need to be explored continuously in practice. The excellent cutting-edge technology and tools of Internet testing are constantly strengthening the guidance and reference significance for commercial banks. I hope that the testing practice of this paper can provide beneficial reference for mobile APP interface level testing and promote the continuous development of new ideas and new realms in the testing field.
Add me VX: 17324089390 Reply keyword "test" Get limited software test learning materials Oh ~~
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.