mirror of
https://github.com/koel/koel
synced 2024-11-28 15:00:42 +00:00
Add several handy WebDriver shortcuts
This commit is contained in:
parent
7b4908f85d
commit
6760ce4619
11 changed files with 77 additions and 76 deletions
|
@ -8,7 +8,7 @@ class AlbumsScreenTest extends TestCase
|
||||||
{
|
{
|
||||||
public function testAlbumsScreen()
|
public function testAlbumsScreen()
|
||||||
{
|
{
|
||||||
$this->loginAndWait()->goto('albums');
|
$this->loginAndGoTo('albums');
|
||||||
|
|
||||||
static::assertNotEmpty($this->els('#albumsWrapper .albums article.item'));
|
static::assertNotEmpty($this->els('#albumsWrapper .albums article.item'));
|
||||||
$firstAlbum = $this->el('#albumsWrapper .albums article.item:nth-child(1)');
|
$firstAlbum = $this->el('#albumsWrapper .albums article.item:nth-child(1)');
|
||||||
|
|
|
@ -8,7 +8,7 @@ class ArtistsScreenTest extends TestCase
|
||||||
{
|
{
|
||||||
public function testArtistsScreen()
|
public function testArtistsScreen()
|
||||||
{
|
{
|
||||||
$this->loginAndWait()->goto('artists');
|
$this->loginAndGoTo('artists');
|
||||||
|
|
||||||
static::assertNotEmpty($this->els('#artistsWrapper .artists article.item'));
|
static::assertNotEmpty($this->els('#artistsWrapper .artists article.item'));
|
||||||
$firstArtist = $this->el('#artistsWrapper .artists article.item:nth-child(1)');
|
$firstArtist = $this->el('#artistsWrapper .artists article.item:nth-child(1)');
|
||||||
|
|
|
@ -2,9 +2,6 @@
|
||||||
|
|
||||||
namespace E2E;
|
namespace E2E;
|
||||||
|
|
||||||
use Facebook\WebDriver\WebDriverBy;
|
|
||||||
use Facebook\WebDriver\WebDriverExpectedCondition;
|
|
||||||
|
|
||||||
class KoelTest extends TestCase
|
class KoelTest extends TestCase
|
||||||
{
|
{
|
||||||
public function testDefaults()
|
public function testDefaults()
|
||||||
|
@ -17,24 +14,18 @@ class KoelTest extends TestCase
|
||||||
static::assertCount(1, $this->els($formSelector));
|
static::assertCount(1, $this->els($formSelector));
|
||||||
|
|
||||||
// We submit rubbish and expect an error class on the form.
|
// We submit rubbish and expect an error class on the form.
|
||||||
$this->login('foo@bar.com', 'ThisIsWongOnSoManyLevels');
|
$this->login('foo@bar.com', 'ThisIsWongOnSoManyLevels')
|
||||||
$this->waitUntil(WebDriverExpectedCondition::presenceOfElementLocated(
|
->waitUntilSeen("$formSelector.error");
|
||||||
WebDriverBy::cssSelector("$formSelector.error")
|
|
||||||
));
|
|
||||||
|
|
||||||
// Now we submit good stuff and make sure we're in.
|
// Now we submit good stuff and make sure we're in.
|
||||||
$this->login();
|
$this->login()
|
||||||
$this->waitUntil(WebDriverExpectedCondition::textToBePresentInElement(
|
->waitUntilTextSeenIn('Koel Admin', '#userBadge > a.view-profile.control > span');
|
||||||
WebDriverBy::cssSelector('#userBadge > a.view-profile.control > span'), 'Koel Admin'
|
|
||||||
));
|
|
||||||
|
|
||||||
// Default URL must be Home
|
// Default URL must be Home
|
||||||
static::assertEquals($this->url.'/#!/home', $this->driver->getCurrentURL());
|
static::assertEquals($this->url.'/#!/home', $this->driver->getCurrentURL());
|
||||||
|
|
||||||
// While we're at this, test logging out as well.
|
// While we're at this, test logging out as well.
|
||||||
$this->click('#userBadge > a.logout');
|
$this->click('#userBadge > a.logout');
|
||||||
$this->waitUntil(WebDriverExpectedCondition::visibilityOfElementLocated(
|
$this->waitUntilSeen($formSelector);
|
||||||
WebDriverBy::cssSelector($formSelector)
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,4 @@
|
||||||
<?php
|
<?php
|
||||||
/**
|
|
||||||
* Created by PhpStorm.
|
|
||||||
* User: an
|
|
||||||
* Date: 15/11/16
|
|
||||||
* Time: 4:14 PM
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace E2E;
|
namespace E2E;
|
||||||
|
|
||||||
|
@ -14,9 +8,7 @@ class HomeScreenTest extends TestCase
|
||||||
{
|
{
|
||||||
public function testHomeScreen()
|
public function testHomeScreen()
|
||||||
{
|
{
|
||||||
$this->loginAndWait();
|
$this->loginAndGoTo('home');
|
||||||
|
|
||||||
$this->click('#sidebar a.home');
|
|
||||||
|
|
||||||
// We must see some greetings
|
// We must see some greetings
|
||||||
static::assertTrue($this->el('#homeWrapper > h1')->isDisplayed());
|
static::assertTrue($this->el('#homeWrapper > h1')->isDisplayed());
|
||||||
|
|
|
@ -2,33 +2,23 @@
|
||||||
|
|
||||||
namespace E2E;
|
namespace E2E;
|
||||||
|
|
||||||
use Facebook\WebDriver\WebDriverBy;
|
|
||||||
use Facebook\WebDriver\WebDriverExpectedCondition;
|
|
||||||
|
|
||||||
class PlaylistScreenTest extends TestCase
|
class PlaylistScreenTest extends TestCase
|
||||||
{
|
{
|
||||||
use SongListActions;
|
use SongListActions;
|
||||||
|
|
||||||
public function testPlaylistScreen()
|
public function testPlaylistScreen()
|
||||||
{
|
{
|
||||||
$this->loginAndWait()
|
$this->loginAndGoTo('songs')
|
||||||
->goto('songs')
|
|
||||||
->selectRange()
|
->selectRange()
|
||||||
->createPlaylist('Bar');
|
->createPlaylist('Bar');
|
||||||
|
|
||||||
$this->waitUntil(WebDriverExpectedCondition::textToBePresentInElement(
|
$this->waitUntilTextSeenIn('Bar', '#playlists > ul');
|
||||||
WebDriverBy::cssSelector('#playlists > ul'), 'Bar'
|
|
||||||
));
|
|
||||||
|
|
||||||
$this->click('#sidebar .playlist:nth-last-child(1)');
|
$this->click('#sidebar .playlist:nth-last-child(1)');
|
||||||
$this->waitUntil(WebDriverExpectedCondition::visibilityOfElementLocated(
|
$this->waitUntilSeen('#playlistWrapper');
|
||||||
WebDriverBy::id('playlistWrapper')
|
|
||||||
));
|
|
||||||
|
|
||||||
$this->click('#playlistWrapper .btn-delete-playlist');
|
$this->click('#playlistWrapper .btn-delete-playlist');
|
||||||
// expect a confirmation
|
// expect a confirmation
|
||||||
$this->waitUntil(WebDriverExpectedCondition::visibilityOfElementLocated(
|
$this->waitUntilSeen('.sweet-alert');
|
||||||
WebDriverBy::cssSelector('.sweet-alert')
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,8 +6,7 @@ class QueueScreenTest extends TestCase
|
||||||
{
|
{
|
||||||
public function test()
|
public function test()
|
||||||
{
|
{
|
||||||
$this->loginAndWait();
|
$this->loginAndGoTo('queue');
|
||||||
$this->goto('queue');
|
|
||||||
static::assertContains('Current Queue', $this->el('#queueWrapper > h1 > span')->getText());
|
static::assertContains('Current Queue', $this->el('#queueWrapper > h1 > span')->getText());
|
||||||
|
|
||||||
// As the queue is currently empty, the "Shuffling all song" link should be there
|
// As the queue is currently empty, the "Shuffling all song" link should be there
|
||||||
|
|
22
tests/e2e/SettingsScreenTest.php
Normal file
22
tests/e2e/SettingsScreenTest.php
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace E2E;
|
||||||
|
|
||||||
|
class SettingsScreenTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testSettingsScreen()
|
||||||
|
{
|
||||||
|
$this->loginAndGoTo('settings');
|
||||||
|
$this->typeIn('#inputSettingsPath', dirname(__DIR__.'/../songs'));
|
||||||
|
$this->enter();
|
||||||
|
// Wait for the page to reload
|
||||||
|
$this->waitUntil(function () {
|
||||||
|
return $this->driver->executeScript('return document.readyState') === 'complete';
|
||||||
|
});
|
||||||
|
// And for the loading screen to disappear
|
||||||
|
$this->waitUntilNotSeen('#overlay');
|
||||||
|
$this->goto('albums');
|
||||||
|
// and make sure the scanning is good.
|
||||||
|
$this->waitUntilTextSeenIn('Koel Testing Vol', '#albumsWrapper');
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,10 +2,6 @@
|
||||||
|
|
||||||
namespace E2E;
|
namespace E2E;
|
||||||
|
|
||||||
use Facebook\WebDriver\WebDriverBy;
|
|
||||||
use Facebook\WebDriver\WebDriverElement;
|
|
||||||
use Facebook\WebDriver\WebDriverExpectedCondition;
|
|
||||||
|
|
||||||
class SideBarTest extends TestCase
|
class SideBarTest extends TestCase
|
||||||
{
|
{
|
||||||
public function testSideBar()
|
public function testSideBar()
|
||||||
|
@ -22,44 +18,26 @@ class SideBarTest extends TestCase
|
||||||
|
|
||||||
// Add a playlist
|
// Add a playlist
|
||||||
$this->click('#playlists > h1 > i.create');
|
$this->click('#playlists > h1 > i.create');
|
||||||
$this->waitUntil(WebDriverExpectedCondition::visibilityOfElementLocated(
|
$this->waitUntilSeen('#playlists > form.create');
|
||||||
WebDriverBy::cssSelector('#playlists > form.create')
|
|
||||||
));
|
|
||||||
$this->typeIn('#playlists > form > input[type="text"]', 'Bar');
|
$this->typeIn('#playlists > form > input[type="text"]', 'Bar');
|
||||||
$this->enter();
|
$this->enter();
|
||||||
/** @var WebDriverElement $mostRecentPlaylist */
|
$this->waitUntil(function () {
|
||||||
$mostRecentPlaylist = null;
|
|
||||||
$this->waitUntil(function () use (&$mostRecentPlaylist) {
|
|
||||||
/* @var WebDriverElement $mostRecentPlaylist */
|
|
||||||
$list = $this->els('#playlists .playlist');
|
$list = $this->els('#playlists .playlist');
|
||||||
$mostRecentPlaylist = end($list);
|
|
||||||
|
|
||||||
return $mostRecentPlaylist->getText() === 'Bar';
|
return end($list)->getText() === 'Bar';
|
||||||
});
|
});
|
||||||
|
|
||||||
// Double click to edit/rename a playlist
|
// Double click to edit/rename a playlist
|
||||||
$this->doubleClick('#playlists .playlist:nth-child(2)');
|
$this->doubleClick('#playlists .playlist:nth-child(2)');
|
||||||
$this->waitUntil(WebDriverExpectedCondition::visibilityOfElementLocated(
|
$this->waitUntilSeen('#playlists .playlist:nth-child(2) input[type="text"]');
|
||||||
WebDriverBy::cssSelector('#playlists .playlist:nth-child(2) input[type="text"]')
|
|
||||||
));
|
|
||||||
$this->typeIn('#playlists .playlist:nth-child(2) input[type="text"]', 'Qux');
|
$this->typeIn('#playlists .playlist:nth-child(2) input[type="text"]', 'Qux');
|
||||||
$this->enter();
|
$this->enter();
|
||||||
$this->waitUntil(
|
$this->waitUntilTextSeenIn('Qux', '#playlists .playlist:nth-child(2)');
|
||||||
WebDriverExpectedCondition::textToBePresentInElement(
|
|
||||||
WebDriverBy::cssSelector('#playlists .playlist:nth-child(2)'),
|
|
||||||
'Qux'
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
// Edit with an empty name shouldn't do anything.
|
// Edit with an empty name shouldn't do anything.
|
||||||
$this->doubleClick('#playlists .playlist:nth-child(2)');
|
$this->doubleClick('#playlists .playlist:nth-child(2)');
|
||||||
$this->click('#playlists .playlist:nth-child(2) input[type="text"]')->clear();
|
$this->click('#playlists .playlist:nth-child(2) input[type="text"]')->clear();
|
||||||
$this->enter();
|
$this->enter();
|
||||||
$this->waitUntil(
|
$this->waitUntilTextSeenIn('Qux', '#playlists .playlist:nth-child(2)');
|
||||||
WebDriverExpectedCondition::textToBePresentInElement(
|
|
||||||
WebDriverBy::cssSelector('#playlists .playlist:nth-child(2)'),
|
|
||||||
'Qux'
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -125,7 +125,7 @@ class SongListTest extends TestCase
|
||||||
|
|
||||||
public function testContextMenu()
|
public function testContextMenu()
|
||||||
{
|
{
|
||||||
$this->loginAndWait()->goto('songs');
|
$this->loginAndGoTo('songs');
|
||||||
$this->rightClickOnSong();
|
$this->rightClickOnSong();
|
||||||
|
|
||||||
$by = WebDriverBy::cssSelector('#songsWrapper .song-menu');
|
$by = WebDriverBy::cssSelector('#songsWrapper .song-menu');
|
||||||
|
|
|
@ -76,20 +76,22 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase
|
||||||
*
|
*
|
||||||
* @param string $username
|
* @param string $username
|
||||||
* @param string $password
|
* @param string $password
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
*/
|
*/
|
||||||
protected function login($username = 'koel@example.com', $password = 'SoSecureK0el')
|
protected function login($username = 'koel@example.com', $password = 'SoSecureK0el')
|
||||||
{
|
{
|
||||||
$this->typeIn("#app > div.login-wrapper > form > [type='email']", $username);
|
$this->typeIn("#app > div.login-wrapper > form > [type='email']", $username);
|
||||||
$this->typeIn("#app > div.login-wrapper > form > [type='password']", $password);
|
$this->typeIn("#app > div.login-wrapper > form > [type='password']", $password);
|
||||||
$this->enter();
|
$this->enter();
|
||||||
|
|
||||||
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function loginAndWait()
|
protected function loginAndWait()
|
||||||
{
|
{
|
||||||
$this->login();
|
$this->login();
|
||||||
$this->waitUntil(WebDriverExpectedCondition::textToBePresentInElement(
|
$this->waitUntilTextSeenIn('Koel Admin', '#userBadge > a.view-profile.control > span');
|
||||||
WebDriverBy::cssSelector('#userBadge > a.view-profile.control > span'), 'Koel Admin'
|
|
||||||
));
|
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
@ -113,13 +115,16 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase
|
||||||
$this->click("#sidebar a.$screen");
|
$this->click("#sidebar a.$screen");
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->waitUntil(WebDriverExpectedCondition::visibilityOfElementLocated(
|
$this->waitUntilSeen($this->wrapperId);
|
||||||
WebDriverBy::cssSelector($this->wrapperId)
|
|
||||||
));
|
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function loginAndGoTo($screen)
|
||||||
|
{
|
||||||
|
return $this->loginAndWait()->goto($screen);
|
||||||
|
}
|
||||||
|
|
||||||
protected function waitForUserInput()
|
protected function waitForUserInput()
|
||||||
{
|
{
|
||||||
if (trim(fgets(fopen('php://stdin', 'rb'))) !== chr(13)) {
|
if (trim(fgets(fopen('php://stdin', 'rb'))) !== chr(13)) {
|
||||||
|
|
|
@ -6,6 +6,7 @@ use Facebook\WebDriver\Interactions\Internal\WebDriverDoubleClickAction;
|
||||||
use Facebook\WebDriver\Remote\RemoteWebDriver;
|
use Facebook\WebDriver\Remote\RemoteWebDriver;
|
||||||
use Facebook\WebDriver\WebDriverBy;
|
use Facebook\WebDriver\WebDriverBy;
|
||||||
use Facebook\WebDriver\WebDriverElement;
|
use Facebook\WebDriver\WebDriverElement;
|
||||||
|
use Facebook\WebDriver\WebDriverExpectedCondition;
|
||||||
use Facebook\WebDriver\WebDriverKeys;
|
use Facebook\WebDriver\WebDriverKeys;
|
||||||
|
|
||||||
trait WebDriverShortcuts
|
trait WebDriverShortcuts
|
||||||
|
@ -97,6 +98,27 @@ trait WebDriverShortcuts
|
||||||
return $this->driver->wait($timeout)->until($func);
|
return $this->driver->wait($timeout)->until($func);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function waitUntilSeen($selector)
|
||||||
|
{
|
||||||
|
return $this->waitUntil(WebDriverExpectedCondition::visibilityOfElementLocated(
|
||||||
|
WebDriverBy::cssSelector($selector)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function waitUntilNotSeen($selector)
|
||||||
|
{
|
||||||
|
return $this->waitUntil(WebDriverExpectedCondition::invisibilityOfElementLocated(
|
||||||
|
WebDriverBy::cssSelector($selector)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function waitUntilTextSeenIn($text, $selector)
|
||||||
|
{
|
||||||
|
$this->waitUntil(WebDriverExpectedCondition::textToBePresentInElement(
|
||||||
|
WebDriverBy::cssSelector($selector), $text
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
protected function back()
|
protected function back()
|
||||||
{
|
{
|
||||||
return $this->driver->navigate()->back();
|
return $this->driver->navigate()->back();
|
||||||
|
@ -111,4 +133,6 @@ trait WebDriverShortcuts
|
||||||
{
|
{
|
||||||
return $this->driver->navigate()->refresh();
|
return $this->driver->navigate()->refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue