use `xvfb-run java -Dwebdriver.chrome.driver=/home/vagrant/sites/millenium-testsuite/bin/drivers/chromedriver -jar bin/server/selenium-server-standalone-3.12.0.jar` or
`xvfb-run java -Dwebdriver.gecko.driver=/home/vagrant/sites/millenium-testsuite/bin/drivers/geckodriver -jar bin/server/selenium-server-standalone-3.12.0.jar
` to avoid issues in phantomjs
download link for selenium-server-standalone-3.12.0.jar: https://goo.gl/tbd1NS
start phantomjs server node_modules/.bin/phantomjs --webdriver=8001 or use selenium server java -jar bin/server/selenium-server-standalone-3.12.0.jar
or use  xvfb-run phantomjs --webdriver=8001  or phantomjs -platform offscreen --webdriver=8001
if you want to use https use node_modules/.bin/phantomjs --ignore-ssl-errors=yes
or `xvfb-run phantomjs  --ignore-ssl-errors=true --webdriver=8001`
run tests vendor/phpunit/phpunit/phpunit tests/ or.
run tests vendor/phpunit/phpunit/phpunit tests/mytest.php.- 
      
- 
        Save 031nna/014b17fc63543e338b78cf2ec9d71161 to your computer and use it in GitHub Desktop. 
- 
Open a browser # start an instance of firefox with selenium-webdriver $browser_type = 'firefox' $host = 'http://localhost:4444/wd/hub' $capabilities = array(\WebDriverCapabilityType::BROWSER_NAME => $browser_type); $driver = RemoteWebDriver::create($host, $capabilities); $browser_type # :firefox => firefox # :chrome => chrome # :ie => iexplore
- 
Go to a specified URL $driver->get('http://google.com'); $driver->navigate()->to('http://google.com');'NOTE' -- the WebDriver may not wait for the page to load, you'd better using explicit and implicit waits. 
- 
Locating Elements - 
'findElement(WebDriverBy $by)' -- Find the first element matching the given arguments. 
- 
'findElements(WebDriverBy $by)' -- Find all elements matching the given arguments 
- 
'WebDriverBy' -- Class with static methods for selecting elements using different mechanisms. - 'WebDriverBy
- 'class name'
- 'css selector'
- 'id'
- 'name'
- 'link text'
- 'partial link text'
- 'tag name'
- 'xpath'
 
 
- 'WebDriverBy
- 
Finding Element By ID # example html # <input id="q">...</input> $element = $driver->findElement(WebDriverBy::id("q"));
- 
By Class Name # example html # <div class="highlight-java" style="display: none; ">...</div> $element = $driver->findElement(WebDriverBy::className('highlight-java'));
- 
By Tag Name # example html # <div class="highlight-java" style="display: none; ">...</div> $element = $driver->findElement(WebDriverBy::tagName("div"));
- 
By Name # example html # <input id="q" name='search' type='text'>…</input> $element = $driver->findElement(WebDriverBy::name('search'));
- 
By Link Text # example html # <a href="http://www.google.com/search?q=cheese">cheese</a> $element = $driver->findElement(WebDriverBy::linkText("cheese"));
- 
By Partial Link Text # example html # <a href="http://www.google.com/search?q=cheese">search for cheese</a> $element = $driver->findElement(WebDriverBy::partialLinkText("chee"));
- 
By XPath # example html # <ul class="dropdown-menu"> # <li><a href="/login/form">Login</a></li> # <li><a href="/logout">Logout</a></li> # </ul> $element = $driver->findElement(WebDriverBy::xpath('//a[@href='/logout']'));- 
NOTE-- When using Element#findElement withWebDriverBy::xpath, be aware that,- webdriver follows standard conventions: a search prefixed with "//" will search the entire document, not just the children of this current node.
- Use ".//" to limit your search to the children of the receiving Element.
 
 
- 
- 
By CSS Selector # example html # <div id="food"> # <span class="dairy">milk</span> # <span class="dairy aged">cheese</span> # </div> $element = $driver->findElement(WebDriverBy::cssSelector('#food span.dairy'));
 
- 
- 
Element's operation - 
Button/Link/Image $element = $driver->findElement(WebDriverBy::id('BUTTON_ID'))->click();
- 
Text Field # input some text $driver->findElement(WebDriverBy::id('BUTTON_ID'))->click(); $driver->getKeyboard()->sendKeys('InputText'); # send keyboard actions, press `cmd+a` & `delete` $driver->getKeyboard() ->sendKeys(array( WebDriverKeys::COMMAND, // Use control on non-mac computers. 'a', )); $driver->getKeyboard() ->sendKeys(array( WebDriverKeys::BACKSPACE, ));*'Note' -- /RemoteWebElement->clear() will clear text from a textarea or a text input. 
- 
Checkbox/Radio # check if it is selected $driver->findElement(WebDriverBy::id('CheckBox'))->isSelected(); # select the element $driver->findElement(WebDriverBy::id('CheckBox'))->click(); # deselect the element $driver->findElement(WebDriverBy::id('CheckBox'))->clears();
- 
Select # get the select element $select = $driver->findElement(WebDriverBy::tagName('select')); # get all the options for this element $allOptions = $select->findElement(WebDriverBy::tagName('option')); # select the options foreach ($allOptions as $option) { echo "Value is:" . $option->getAttribute('value); $option->click(); }
- 
visibility $driver->findElement(WebDriverBy::id('element'))->isDisplayed();
- 
get text $driver->findElement(WebDriverBy::id('element'))->getText();
- 
get attribute $driver->findElement(WebDriverBy::id('element'))->getAttribute('class');
 
- 
- 
Driver's operation - 
execute javascript $driver->executeScript("return window.location.pathname");
- 
wait for a specific element to show up # set the timeout to 20 seconds, and the time in interval to 1000 ms $driver->wait(20, 1000)->until( WebDriverExpectedCondition::titleIs('WebDriver Page') );
- 
implicit waits 
 An implicit wait is to tell WebDriver to poll the DOM for a certain amount of time when trying to find an element or elements if they are not immediately available # set the timeout for implicit waits as 10 seconds $driver->manage()->timeouts()->implicitlyWait = 10 $driver->get("http://somedomain/url_that_delays_loading"); $element = $driver->findElement(WebDriverBy::id('some-dynamic-element'));- 
switch between frames # switch to an iframe $driver->switchTo()->frame(/WebDriverElement('the id or the name of the frame"some-frame" # name or id')); # switch back to the main document $driver->switchTo()->defaultContent();
- 
swich between windows #TODO: Add examples.
- 
handle javascript dialog # get the alert $a = $driver->switchTo->alert(); # operation on the alert if ($a->getText == 'A value you are looking for') { a->dismiss(); } else { a->accept(); }
 
- 
- 
Cookies - 
Delete cookies # You can delete cookies in 2 ways # By name $driver->manage()->deleteCookieNamed('CookieName'); # Or all of them $driver->manage()->deleteAllCookies();
 
- 
| - Step 1: Update the system | |
| Before starting, it is recommended to update the system with the latest stable release. You can do this with the following command: | |
| `sudo apt-get update ` | |
| - Step 2: Install PhantomJS | |
| Before installing PhantomJS, you will need to install some required packages on your system. You can install all of them with the following command: | |
| sudo apt-get install build-essential chrpath libssl-dev libxft-dev libfreetype6-dev libfreetype6 libfontconfig1-dev libfontconfig1 -y | |
| - Next, you will need to download the PhantomJS. You can download the latest stable version of the PhantomJS from their official website. Run the following command to download PhantomJS: | |
| sudo wget https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-linux-x86_64.tar.bz2 | |
| - Once the download is complete, extract the downloaded archive file to desired system location: | |
| `sudo tar xvjf phantomjs-2.1.1-linux-x86_64.tar.bz2 -C /usr/local/share/` | |
| - Next, create a symlink of PhantomJS binary file to systems bin dirctory: | |
| `sudo ln -s /usr/local/share/phantomjs-2.1.1-linux-x86_64/bin/phantomjs /usr/local/bin/` | |
| Step 3: Verify PhantomJS | |
| - PhantomJS is now installed on your system. You can now verify the installed version of PhantomJS with the following command: | |
| `phantomjs --version` | |
| - You should see the following output: | |
| `2.1.1` | |
| from https://www.vultr.com/docs/how-to-install-phantomjs-on-ubuntu-16-04 |