Set up seleniumserver in centos and use php to complete automated website testing and data collection selenium server
Because a graphical interface is required, we will first introduce
Installation and configuration of vncserver
1. install gnome graphical desktop
yum groupinstall -y "X Window System"yum groupinstall -y "Desktop"yum groupinstall -y "Chinese Support"
2. install vncserver and configure 1. install vncserver
yum install -y tigervnc-server
2. configure vncserver
1) configure to start automatically
chkconfig --level 345 vncserver on
2) configure the vnc password
Vncserver
You will require a password to access your desktop.
Password:
Verify:
3) configure to use gnome desktop
Modify the/root/. vnc/xstartup file and add gnome-session & to the last twm & delete file &.
4) configure the listening port and environment parameters after vncserver is started
Modify the/etc/sysconfig/vncservers file and add the following content:
VNCSERVERS = "1: root"
# Desktop number: the user listens to Port 590 *
VNCSERVERARGS [1] = "-geometry 1200 × 800 ″
5) restart the vncserver service.
# Service vncserver restart
3. allow the root user to access the graphic interface and generate a new machine-id.
sed -i 's/.*!= root.*/#&/' /etc/pam.d/gdm dbus-uuidgen >/var/lib/dbus/machine-id
4. disable selinux and NetworkManager services
1. check selinux service and disable
# Vi/etc/selinux/config
Make sure that the value of the SELINUX field is disabled. if not, change it to disabled.
2. disable the NetworkManager service.
# Chkconfig-del NetworkManager
5. test logon: cleint can be downloaded here
Now, install selenium server 1: java is required.
yum -y install java
2: We use frefox for browser support.
yum -y install firefox
3: download Selenium server
wget http://selenium-release.storage.googleapis.com/2.48/selenium-server-standalone-2.48.2.jar
4. Download Selenium server
java -jar selenium-server-standalone-2.48.2.jar -port 4444
Finally, we use PHP to manipulate firefox browsing through selenium server. the client library uses https://code.google.com/p/php-webdriver-bindings/
Sample code:
require_once "phpwebdriver/WebDriver.php";require("phpwebdriver/LocatorStrategy.php");$webdriver = new WebDriver("localhost", "4444");$webdriver->connect("firefox"); $webdriver->get("http://google.com");$element = $webdriver->findElementBy(LocatorStrategy::name, "q");$element->sendKeys(array("selenium google code" ) );$element->submit();$webdriver->close();
Finally, we can use it to automate the testing of PC websites, or simulate a browser to collect data that is difficult to collect. of course, we can also use the automated website function, this mainly depends on your interest!