Skip to content

Commit

Permalink
Completed cleanup and Test api fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Modelizer committed Apr 4, 2018
1 parent f56a07d commit ceb2402
Show file tree
Hide file tree
Showing 13 changed files with 195 additions and 344 deletions.
24 changes: 23 additions & 1 deletion bootstrap/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
/*
|--------------------------------------------------------------------------
| Web Drivers
| Note: filename denote when url is been complete after extracting then it
| find the filename given below and rename it as per operating system and
| and driver name. Example file would become now mac-chrome and in windows
| win-chrome.exe
| Special execution permission will be given for windows file.
|--------------------------------------------------------------------------
*/
'web-drivers' => [
Expand All @@ -46,7 +51,24 @@
'filename' => 'chromedriver',
],
],
'firefox' => [],
'firefox' => [
'mac' => [
'version' => 'v0.20.0',
'url' => 'https://github.com/mozilla/geckodriver/releases/download/v0.20.0/geckodriver-v0.20.0-macos.tar.gz',
'filename' => 'geckodriver'
],

'win' => [
'version' => 'v0.20.0',
'url' => 'https://github.com/mozilla/geckodriver/releases/download/v0.20.0/geckodriver-v0.20.0-win32.zip',
'filename' => 'geckodriver.exe'
],
'linux' => [
'version' => 'v0.20.0',
'url' => 'https://github.com/mozilla/geckodriver/releases/download/v0.20.0/geckodriver-v0.20.0-linux32.tar.gz',
'filename' => 'geckodriver'
]
],
],

/*
Expand Down
12 changes: 8 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@
"email": "[email protected]"
}
],
"collaborators": [
{
"name": "John Hoopes",
"email": "[email protected]"
}
],
"require": {
"php": ">=7.1",
"lmc/steward": "dev-master",
"guzzlehttp/guzzle": "^6.2"
},
"require-dev": {
"guzzlehttp/guzzle": "^6.2",
"orchestra/testbench": "^3.3"
},
"autoload": {
Expand All @@ -23,7 +27,7 @@
},
"autoload-dev": {
"psr-4": {
"Modelizer\\Selenium\\Tests\\" : "tests"
"Modelizer\\Selenium\\Tests\\" : "tests/"
}
},
"extra": {
Expand Down
45 changes: 35 additions & 10 deletions src/Console/BootSelenium.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,23 @@ class BootSelenium extends Command
{
use WebDriverUtilsTrait;

/**
* DWebDriver name to be use
* @var array
*/
protected $dWebDriver = [
'chrome' => 'chrome',
'firefox' => 'gecko',
'edge' => 'edge'
];

/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'selenium:start {driver=chrome}';
protected $signature = 'selenium:start {driver=chrome : (chrome|firefox) Driver version} '.
'{serverVersion=3.11.0 : Selenium Server Version} ';

/**
* The console command description.
Expand All @@ -30,16 +41,30 @@ class BootSelenium extends Command
*/
public function handle()
{
$cmd = implode([
'java',
$this->getWebDriver(env('DEFAULT_BROWSER', $this->argument('driver'))),
'-jar',
$this->getSeleniumServerQualifiedName(),
], ' ');
$cmd = collect(array_merge($this->getSeleniumDefaultCommand(), $this->getArguments()))
->except('driver', 'serverVersion')
->implode(' ');

$this->info('Starting Selenium server v'.$this->argument('serverVersion'));

echo shell_exec($cmd.' '.$this->getSeleniumOptions());
}

/**
* Get the default commands which are require to boot selenium server
* @return array
*/
public function getSeleniumDefaultCommand()
{
return [
'java',
$this->getWebDriver(env('DEFAULT_BROWSER', $this->argument('driver'))),
'-jar '.$this->getSeleniumServerQualifiedName(),
'-enablePassThrough false',
];
}


/**
* Get selenium server qualified location.
*
Expand All @@ -52,7 +77,7 @@ public function getSeleniumServerQualifiedName()
$files = opendir($binDirectory = static::prependPackagePath('vendor/bin'));

while (false !== ($file = readdir($files))) {
if (str_contains($file, 'selenium')) {
if (str_contains($file, 'selenium') && str_contains($file, $this->argument('serverVersion'))) {
return $binDirectory.DIRECTORY_SEPARATOR.$file;
}
}
Expand All @@ -69,7 +94,7 @@ public function downloadSelenium()
{
$this->info('Downloading Selenium server file. Please wait...');

$process = new Process(base_path('vendor/bin/steward install'));
$process = new Process(base_path('vendor/bin/steward install '.$this->argument('serverVersion')));
$process->setTimeout(0);

$process->run();
Expand Down Expand Up @@ -102,7 +127,7 @@ protected function getWebDriver($driverName)
]);
}

return "-Dwebdriver.$driverName.driver={$driver}";
return "-Dwebdriver.{$this->dWebDriver[$driverName]}.driver={$driver}";
}

protected function getSeleniumOptions()
Expand Down
5 changes: 3 additions & 2 deletions src/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
namespace Modelizer\Selenium\Console;

use Illuminate\Foundation\Console\ServeCommand;
use Orchestra\Testbench\Console\Kernel as OrchestraKernel;

class Kernel extends \Orchestra\Testbench\Console\Kernel
class Kernel extends OrchestraKernel
{
/**
* The Artisan commands provided by your application.
Expand All @@ -14,6 +15,6 @@ class Kernel extends \Orchestra\Testbench\Console\Kernel
protected $commands = [
BootSelenium::class,
GetWebDriver::class,
ServeCommand::class,
ServeCommand::class
];
}
17 changes: 4 additions & 13 deletions src/Console/MakeSeleniumTestCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@

use Illuminate\Console\Command;
use Illuminate\Console\GeneratorCommand;
use Modelizer\Selenium\Traits\WebDriverUtilsTrait;

class MakeSeleniumTestCommand extends GeneratorCommand
{
use WebDriverUtilsTrait;

/**
* The console command name.
*
Expand Down Expand Up @@ -35,7 +38,7 @@ class MakeSeleniumTestCommand extends GeneratorCommand
*/
protected function getStub()
{
return __DIR__.'/stubs/test.stub';
return self::prependPackagePath('stubs/test.stub');
}

/**
Expand All @@ -51,16 +54,4 @@ protected function getPath($name)

return $this->laravel['path.base'].'/tests/'.str_replace('\\', '/', $name).'.php';
}

/**
* Get the default namespace for the class.
*
* @param string $rootNamespace
*
* @return string
*/
protected function getDefaultNamespace($rootNamespace)
{
return $rootNamespace;
}
}
107 changes: 61 additions & 46 deletions src/SeleniumTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,81 +2,96 @@

namespace Modelizer\Selenium;

use Illuminate\Foundation\Bootstrap\LoadEnvironmentVariables;
use Illuminate\Foundation\Testing\Concerns\InteractsWithAuthentication;
use Illuminate\Foundation\Testing\Concerns\InteractsWithConsole;
use Illuminate\Foundation\Testing\Concerns\InteractsWithContainer;
use Illuminate\Foundation\Testing\Concerns\InteractsWithDatabase;
use Illuminate\Foundation\Testing\Concerns\InteractsWithExceptionHandling;
use Illuminate\Foundation\Testing\Concerns\InteractsWithSession;
use Illuminate\Foundation\Testing\Concerns\MakesHttpRequests;
use Illuminate\Foundation\Testing\Concerns\MocksApplicationServices;
use Lmc\Steward\Test\AbstractTestCase;
use Modelizer\Selenium\Services\Application as Laravel;
use Modelizer\Selenium\Services\InteractWithPage as Interaction;
use Modelizer\Selenium\Services\ManageWindow;
use Modelizer\Selenium\Services\WaitForElement;
use Modelizer\Selenium\Services\WorkWithDatabase;
use Modelizer\Selenium\Services\InteractWithPage;
use Orchestra\Testbench\Concerns\Testing;
use Orchestra\Testbench\Contracts\TestCase as OrchestraTestCaseContract;

class SeleniumTestCase extends AbstractTestCase
abstract class SeleniumTestCase extends AbstractTestCase implements OrchestraTestCaseContract
{
use Laravel,
Interaction,
WorkWithDatabase,
WaitForElement,
ManageWindow;
use Testing,
InteractsWithAuthentication,
InteractsWithConsole,
InteractsWithContainer,
InteractsWithDatabase,
InteractsWithExceptionHandling,
InteractsWithSession,
MakesHttpRequests,
MocksApplicationServices,
InteractWithPage;

/**
* The base URL to use while testing the application.
*
* @var string
*/
protected $baseUrl;
protected $baseUrl = 'http://localhost';

/**
* @var int
* Setup the test environment.
*
* @return void
*/
protected $width;
public function setUp(): void
{
$this->setUpTheTestEnvironment();

$this->baseUrl = env('APP_URL', $this->baseUrl);

parent::setUp();
}

/**
* @var int
* Clean up the testing environment before the next test.
*
* @return void
*/
protected $height;

public function setUp()
protected function tearDown()
{
$this->setUpLaravel();
$this->baseUrl = env('APP_URL', 'http://localhost/');
$this->wd->get($this->baseUrl);

$this->setBrowser(env('DEFAULT_BROWSER', 'chrome'));
$this->tearDownTheTestEnvironment();
}

public function setupPage()
/**
* Boot the testing helper traits.
*
* @return array
*/
protected function setUpTraits()
{
if (empty($this->width)) {
$this->width = env('SELENIUM_WIDTH', 1024);
}

if (empty($this->height)) {
$this->height = env('SELENIUM_HEIGHT', 768);
}

$this->changeWindowSize($this->width, $this->height);
return $this->setUpTheTestEnvironmentTraits();
}

/**
* Force selenium to wait.
* Refresh the application instance.
*
* @param int|float $seconds The number of seconds or partial seconds to wait
*
* @return $this
* @return void
*/
protected function wait($seconds = 1)
protected function refreshApplication()
{
usleep($seconds * 1000000);

return $this;
$this->app = $this->createApplication();
}

/**
* Alias for wait.
* Define environment setup.
*
* @param int $seconds
* @param \Illuminate\Foundation\Application $app
*
* @return SeleniumTestCase
* @return void
*/
public function hold($seconds = 1)
protected function getEnvironmentSetUp($app)
{
return $this->wait($seconds);
putenv('APP_ENV=testing');
$app->useEnvironmentPath(__DIR__.'/..');
$app->loadEnvironmentFrom('testing.env');
$app->bootstrapWith([LoadEnvironmentVariables::class]);
}
}
Loading

0 comments on commit ceb2402

Please sign in to comment.