Appium+python automation (thirty-three) - local debugging test code, remote control test environment - Remote (super detailed explanation)

Introduction

There is such a line of code driver =webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps) when starting the app . Many friends and students do not know this ip and port Where did it come from, I think it is necessary to explain to my friends, so I decided to write an article about the server ip of this appium! Come to answer your questions and solve your doubts! In this way, you will not ask some naive questions and make others laugh out loud after reading the joke. eg: I set up a test environment on the test server, so I can only debug the code on the test server and then test it. In this way, I have to build an environment that does not write scripts. . . . Waiting for the question of the silly widow, Remote  , let's meet him first, and then we will know what it means: remote. Then, should we change that IP address to the IP of the test server, and all problems will be solved.

Purpose

  Generally speaking, the default address of 127.0.0.1 in appium does not need to be modified. In the process of automation, if you need remote operation, this function can come in handy. Think about it, if the company configures you a separate computer to run automated testing, and then write scripts on your own working computer, and run the scripts on the automated machine, so that the work is automated and correct, wouldn't it be great? 

illustrate

127.0.0.1

127.0.0.1 is the loopback (loopback) address, used to test the local TCP/IP protocol stack, for example, you enter in cmd: ping 127.0.0.1:

What you see is to send a request packet to the local machine. This request will only run locally and will not be sent out through the network.

 " Local ", you must have thought of localhost, open your hosts file (right click to open with notepad++):

can be seen:

Yes, 127.0.0.1 and localhost are "equivalent":

localhost is a domain name, similar in nature to "www.baidu.com". (You cannot bind the socket directly, you must first gethostbyname) to bind to the IP - I don't quite understand the words in the brackets. That is to say, the default ip of your localhost is 127.0.0.1.

Now we can understand it this way. Writing 127.0.0.1 in the address means to access it locally:

We write the address directly as localhost, which can also be adjusted.

Port number: 4723

This value is not fixed, the only requirement is - do not conflict, you can check the currently occupied port number in cmd, enter the command

netstat -ano to view all port usage;

netstat -ano | findstr "4723" Check which program occupies port 4723

The first one did not view the program because appium was not turned on

Start appium and check it out for the second time

Also open your appium:

You can modify the port number here, but how do you change the port number here, then you need to modify the port number in your code accordingly.

/wd/hub

Position the mouse on the remote  and put it on top, then hold down Ctrl and click the left mouse button to enter the source code, let's look at the source code:

It can be seen that the WebDriver class also defines an address when it is initialized, except that the port number is different, and the others are the same as what we passed. Therefore, we can simply understand /wd/hub as a rule.

set IP 

1. Open appium>General Setting interface

2. Here use appium's default server address 127.0.0.1 port 4723, generally debug on your own machine without modification

address

1. Where does the address in the code point to?

After starting the appium service, enter in the browser: http://127.0.0.1:4723/wd/hub. Appears as shown in the figure below, indicating that the service has started successfully, and appium can be seen as a server.

2.appium background access log

Configure test machine

1. One working computer and one running automated testing, how to use the working computer to remotely control the automated testing computer?

2. Change the appium service address on the test computer to the local IP address, such as: 192.168.1.1 (pay attention, pay attention!!! If this is the local IP address)

3. Start appium on the test computer. (You can see the log startup address 192.0.0.1, port 4723)

remote operation

1. Open a browser on your work computer and enter: 192.168.1.1:4723/wd/hub. This step is very important. Be sure to see the following interface to confirm that the remote link is successful.

 2. Modify the address in the code in the script

3. After the environment on the test machine is ready, run the script on this machine, so the test machine can run automatically. 

summary

1. First of all, localhost is a domain name. In the past, it pointed to the IP address 127.0.0.1. After the operating system supports ipv6, it also points to the ipv6 address [::1]
In Windows, this domain name is predefined, from the hosts file (c:\windows\system32\drivers\etc\hosts) (etc/ hosts) can be seen:
# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost
In Linux, its definition is located in /etc/hosts:
127.0.0.1 localhost
Note that this value is optional Modified, for example, if I change it to
192.068.206.1 localhost
and then ping localhost, the prompt becomes
PING localhost (192.168.206.1) 56(84) bytes of data.
Of course, most people are not like me.
————Splitting line—After talking about localhost, let’s talk about 127.0.0.1———
127.0.0.1 This address is usually assigned to the loopback interface. loopback is a special network interface (can be understood as a virtual network card), which is used for network interaction between various applications in this machine. As long as the networking components of the operating system are healthy, loopbacks will work. This interface cannot be seen in Windows, and this interface is called lo in Linux:
#ifconfig
eth0 Link encap:Ethernet hwaddr 00:00:00:00:00:00
inet addr:192.168.0.1 Bcase:192.168.0.255 Mask:255.255.255.0
......
lo Link encap:Local Loopback
inetaddr:127.0.0.1 Mask: 255.0.0.0
......
It can be seen that the address of the lo interface is 127.0.0.1. In fact, the entire 127.* network segment can be used. For example, you can also ping 127.0.0.2.
But it is just a convention to use 127.0.0.1 as the default address of the loopback interface , such as the following:
#ifconfig lo 192.168.128.1
#ping localhost #Oops, I can't ping
#ping 192.128.128.1 #Can be connected
#ifconfig lo
lo Link encap:Local Loopback
inetaddr: 192.168.128.1 Mask: 255.255.255.0
......
Of course, most people are not like me. If these configurations are changed casually, many software that only recognize 127.0.0.1 may hang up.
———Separation line——After talking about 127.0.0.1, let’s talk about the address of this machine———
To be precise, "local address" is not a canonical term. Usually, it refers to "the network protocol address bound to the local physical network card". Since the current common network protocol is only IPV4, IPX/Apple Tak has disappeared, and IPV6 has not been popularized, so it usually only refers to IP addresses or even ipv4 addresses. Under normal circumstances, 127.0.0.1 is not regarded as the address of the local machine - because there is no need to specify it, everyone knows it.
The local machine address is bound to a specific network interface. For example, an Ethernet card, a wireless network card, or a virtual network card of a PPP/PPPoE dial-up network must be bound to an address in order to work normally, otherwise other devices will not know how to access it.

————Finally summarize the difference———

  • localhost is a domain name, not an address, it can be configured as any IP address, but usually points to 127.0.0.1(ipv4) and [::1](ipv6)
  • The entire 127.* segment is usually used as the default address for the loopback network interface, which is usually set to 127.0.0.1 by convention. This address cannot be accessed on other computers. Even if you want to access it, you are accessing yourself, because basically every device with a TCP/IP protocol stack has localhost/127.0.0.1.
  • A local address usually refers to an IP address bound to a physical or virtual network interface, which can be accessed by other devices.
  • Finally, from the perspective of development
    • localhost is a domain name, similar in nature to "www.baidu.com". The socket cannot be bound directly, and gethostbyname must be converted to IP before binding.
    • 127.0.0.1 is the address bound to the loopback interface. If the server socket is bound to it, your client program can only be accessed locally.
    • If there are multiple network cards in the host, connected to different physical networks, such as 192.168.1.1/255.255.255.0, then when your server socket is bound to the address 192.168.0.1 , other computers located in the 192.168.1.* network segment cannot connect, and only computers located in the 192.168.0.* network segment can access your server program.

2. Well, I will share it here today. Presumably, all the friends and children's shoes have a new understanding of the problems derived from this line of code.


              [The following is the most complete software test engineer learning knowledge architecture system diagram in 2023 that I compiled]


1. From entry to mastery of Python programming

2. Interface automation project actual combat

3. Actual Combat of Web Automation Project


4. Actual Combat of App Automation Project

5. Resume of first-tier manufacturers


6. Test and develop DevOps system

7. Commonly used automated testing tools


Eight, JMeter performance test

9. Summary (little surprise at the end)

life is long so add oil. Every effort will not be let down, as long as you persevere, there will be rewards in the end. Cherish your time and pursue your dreams. Don't forget the original intention, forge ahead. Your future is in your hands!

Life is short, time is precious, we cannot predict what will happen in the future, but we can grasp the present moment. Cherish every day and work hard to make yourself stronger and better. Firm belief, persistent pursuit, success will eventually belong to you!

Only by constantly challenging yourself can you constantly surpass yourself. Persist in pursuing your dreams and move forward bravely, and you will find that the process of struggle is so beautiful and worthwhile. Believe in yourself, you can do it!

Guess you like

Origin blog.csdn.net/NHB456789/article/details/131980832