1. Introduction
Hello, I’m Anguo!
If the Python automation program you write is stable locally, you can consider deploying it to the server, combined with scheduled tasks completely free your hands
However, because automation is associated with platform compatibility, some dependent libraries need special treatment when running on the server
In this article, a Python automation program written in Selenium will talk about the detailed process of scripting server deployment
2. Procedure
The following uses the CentOS server as an example
2-1 Installing the desktop environment
PS: If installed, you can skip to the next step
We need to install a desktop environment “Take GNOME as an example”, set to start in graphical mode, and enable the graphical interface
# yum groupinstall -y "GNOME Desktop" # yum groupinstall -y "GNOME Desktop" # yum groupinstall -y "GNOME Desktop" # yum groupinstall -y "GNOME DesktopCopy the code
2-2 Installing and configuring the remote desktop
Take VNC, the most common
First, install VNC Server on the Server and set the login password
# yum install tigerVnc-server -y # yum install tigervnC-server -yCopy the code
Then, start VNC Server and enable the corresponding port number
Systemctl start vncserver @ # open VNC service: 1 # set boot from rev systemctl enable vncserver @ : 1 # check VNC service port netstat LNPT | grep Xvnc # Firewall-cmd --add-port=5901/ TCP --permanent firewall-cmd --reloadCopy the code
Finally, download the VNC Viewer and use IP address + port number + login password to remotely connect to the server
Download address:
www.realvnc.com/en/connect/…
PS: Specify the IP address and port number of the VNC Server explicitly
2-3 Install Chrome
FireFox is installed on the server by default. You need to manually install Chrome
# # download the latest Chrome wget https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm installation browser yum install RPM # Check the version of the Chrome browserCopy the code
After the installation is complete, Chrome fails to be started as user Root. PS: Chrome cannot be directly used on the server. Use the –no-sandbox parameter to start Chrome
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # --no-sandboxCopy the code
2-4 Configuring Chrome Driver and Authorization
Download the Chrome Driver of the corresponding version from the official website
Download address:
chromedriver.storage.googleapis.com/index.html
Decompress the package and upload it to the usr/bin directory on the server
Finally, grant executable permissions to the Chromedriver file
[root@localhost xh]# CD /usr/bin # Grant executable permissions [root@localhost bin]# sudo chmod +x ChromeDriverCopy the code
2-5 Run tests visually
Upload the automation script to the server and set it to run in header mode
Note: Since Chrome on the server needs to be configured to start in no-sandbox mode, the automation script needs to add Settings properties
Option.add_argument ('headless') option.add_argument('no-sandbox') option.add_argument('disable-dev-shm-usage') option.add_experimental_option('useAutomationExtension', False) option.add_experimental_option('excludeSwitches', ['enable-automation']) browser = webdriver.Chrome(chrome_options=option)Copy the code
After the “Headless mode” test runs normally, you can enable the “Headless mode” to write scheduled tasks and associate automatic scripts with scheduled tasks
3. The last
In this paper, the steps of Selenium automated scripting server deployment are described
It should be noted that visual debugging tests on the server are really necessary to help identify compatibility issues ahead of time
For more technical details, follow the public account “AirPython” to unlock it!
If you think the article is good, please like, share, leave a message, because this will be my continuous output of more high-quality articles the strongest power!