Example
Below is an example of a sample wpselenium test. This test is based on the sample node-login project by @braitsch which can be cloned on downloaded from github here.
As can be deduced by the test below, it tests to see that the user is not logged in if the entered details are wrong.
<?php
use WPSelenium\WPSTestCase;
use Facebook\WebDriver\WebDriverBy;
use Facebook\WebDriver\WebDriverExpectedCondition;
use Facebook\WebDriver\WebDriverElement;
class SampleTest extends WPSTestCase{
protected function setUp()
{
$this->driver = $this->GetSeleniumDriver();
$this->driver->get($this->GetTestSite());
}
function testCanNotLogin(){
$usernameField = $this->driver->findElement(WebDriverBy::id("user-tf"));
$passwordField = $this->driver->findElement(WebDriverBy::id("pass-tf"));
$loginButton = $this->driver->findElement(WebDriverBy::id("btn_sign_in"));
$alertModal = $this->driver->findElement(WebDriverBy::className("modal-alert"));
$this->assertInstanceOf(WebDriverElement::class, $usernameField);
$this->assertInstanceOf(WebDriverElement::class, $passwordField);
$this->assertInstanceOf(WebDriverElement::class, $loginButton);
$usernameField->click();
$this->driver->getKeyboard()->sendKeys("wrong_user");
$passwordField->click();
$this->driver->getKeyboard()->sendKeys("wrong_password");
$loginButton->click();
$this->driver->wait(10, 1000)->until(
WebDriverExpectedCondition::visibilityOf($alertModal)
);
$this->assertContains('show', $alertModal->getAttribute("class"));
$this->assertContains('Login Failure',
$alertModal->findElement(WebDriverBy::className("modal-title"))->getText());
}
}
Below is what you would expect to see from your console, and browser window respectively.