Back to Browse

Selenium Demo with PHP

20.7K views
Jun 5, 2019
8:59

This tutorial will show you how to setup and run an automated test from Selenium with PHP. This set up is done in a Linux environment. Step 1: Open Terminal and create a new directory mkdir Selenim cd Selenium Step 2: Download the latest selenium standalone server from https://www.seleniumhq.org/download/ wget https://selenium-release.storage.googleapis.com/3.141/selenium-server-standalone-3.141.59.jar Step 3: Install PHP extensions sudo apt-get install php7.2-zip php7.2-curl -y Step 4: Install Composer sudo apt update sudo apt install composer -y Step 5: Install PHP webdriver from Facebook composer require facebook/webdriver Step 6: Install Java if you don't already have it sudo apt-get install openjdk-8-jre -y Step 7: Get the latest Chrome driver from http://chromedriver.chromium.org/downloads Step 8: After you unzip the file, move it your bin folder sudo mv -i chromedriver /usr/bin/. Step 9: Create a new file within your Selenium directory vim demoTest.php Step 10: Fill the file with skeleton code. (Hit "i" to type, hit "esc" followed by ":wq" and "enter" to save and exit) "put less than bracket here"?php use Facebook\Webdriver; require_once(__DIR__ . '/vendor/autoload.php'); $host = 'http://localhost:4444/wd/hub'; $driver = Facebook\WebDriver\Remote\RemoteWebDriver::create($host, Facebook\WebDriver\Remote\DesiredCapabilities::chrome()); $driver-"put greater than bracket here"get("http://www.google.com"); $driver-"put greater than bracket here"manage()-"put greater than bracket here"window()-"put greater than bracket here"maximize(); // ENTER AUTOMATED ACTIONS BELOW // $driver-"put greater than bracket here"quit(); Step 11: Open Chrome, download extensions Katalon Recorder PHPUnit formatter for Katalon Recorder Step 12: Open Katalon Recorder and record a new test Step 13: Export the test as PHP, copy the actions, paste into vim code and make the necessary changes Step 14: Run the selenium server from your terminal java -jar selenium-server-standalone-3.141.59.jar Step 15: Open a new instance of terminal, navigate to you PHP file, and run the file cd Selenium php demoTest.php

Download

0 formats

No download links available.

Selenium Demo with PHP | NatokHD