Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit ceb2402

Browse files
committedApr 4, 2018
Completed cleanup and Test api fixes.
1 parent f56a07d commit ceb2402

13 files changed

+195
-344
lines changed
 

‎bootstrap/config.php

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@
2626
/*
2727
|--------------------------------------------------------------------------
2828
| Web Drivers
29+
| Note: filename denote when url is been complete after extracting then it
30+
| find the filename given below and rename it as per operating system and
31+
| and driver name. Example file would become now mac-chrome and in windows
32+
| win-chrome.exe
33+
| Special execution permission will be given for windows file.
2934
|--------------------------------------------------------------------------
3035
*/
3136
'web-drivers' => [
@@ -46,7 +51,24 @@
4651
'filename' => 'chromedriver',
4752
],
4853
],
49-
'firefox' => [],
54+
'firefox' => [
55+
'mac' => [
56+
'version' => 'v0.20.0',
57+
'url' => 'https://github.com/mozilla/geckodriver/releases/download/v0.20.0/geckodriver-v0.20.0-macos.tar.gz',
58+
'filename' => 'geckodriver'
59+
],
60+
61+
'win' => [
62+
'version' => 'v0.20.0',
63+
'url' => 'https://github.com/mozilla/geckodriver/releases/download/v0.20.0/geckodriver-v0.20.0-win32.zip',
64+
'filename' => 'geckodriver.exe'
65+
],
66+
'linux' => [
67+
'version' => 'v0.20.0',
68+
'url' => 'https://github.com/mozilla/geckodriver/releases/download/v0.20.0/geckodriver-v0.20.0-linux32.tar.gz',
69+
'filename' => 'geckodriver'
70+
]
71+
],
5072
],
5173

5274
/*

‎composer.json

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,16 @@
88
"email": "hello@mudasir.me"
99
}
1010
],
11+
"collaborators": [
12+
{
13+
"name": "John Hoopes",
14+
"email": "john.hoopes@madisoncreativeweb.com"
15+
}
16+
],
1117
"require": {
1218
"php": ">=7.1",
1319
"lmc/steward": "dev-master",
14-
"guzzlehttp/guzzle": "^6.2"
15-
},
16-
"require-dev": {
20+
"guzzlehttp/guzzle": "^6.2",
1721
"orchestra/testbench": "^3.3"
1822
},
1923
"autoload": {
@@ -23,7 +27,7 @@
2327
},
2428
"autoload-dev": {
2529
"psr-4": {
26-
"Modelizer\\Selenium\\Tests\\" : "tests"
30+
"Modelizer\\Selenium\\Tests\\" : "tests/"
2731
}
2832
},
2933
"extra": {

‎src/Console/BootSelenium.php

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,23 @@ class BootSelenium extends Command
1111
{
1212
use WebDriverUtilsTrait;
1313

14+
/**
15+
* DWebDriver name to be use
16+
* @var array
17+
*/
18+
protected $dWebDriver = [
19+
'chrome' => 'chrome',
20+
'firefox' => 'gecko',
21+
'edge' => 'edge'
22+
];
23+
1424
/**
1525
* The name and signature of the console command.
1626
*
1727
* @var string
1828
*/
19-
protected $signature = 'selenium:start {driver=chrome}';
29+
protected $signature = 'selenium:start {driver=chrome : (chrome|firefox) Driver version} '.
30+
'{serverVersion=3.11.0 : Selenium Server Version} ';
2031

2132
/**
2233
* The console command description.
@@ -30,16 +41,30 @@ class BootSelenium extends Command
3041
*/
3142
public function handle()
3243
{
33-
$cmd = implode([
34-
'java',
35-
$this->getWebDriver(env('DEFAULT_BROWSER', $this->argument('driver'))),
36-
'-jar',
37-
$this->getSeleniumServerQualifiedName(),
38-
], ' ');
44+
$cmd = collect(array_merge($this->getSeleniumDefaultCommand(), $this->getArguments()))
45+
->except('driver', 'serverVersion')
46+
->implode(' ');
47+
48+
$this->info('Starting Selenium server v'.$this->argument('serverVersion'));
3949

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

53+
/**
54+
* Get the default commands which are require to boot selenium server
55+
* @return array
56+
*/
57+
public function getSeleniumDefaultCommand()
58+
{
59+
return [
60+
'java',
61+
$this->getWebDriver(env('DEFAULT_BROWSER', $this->argument('driver'))),
62+
'-jar '.$this->getSeleniumServerQualifiedName(),
63+
'-enablePassThrough false',
64+
];
65+
}
66+
67+
4368
/**
4469
* Get selenium server qualified location.
4570
*
@@ -52,7 +77,7 @@ public function getSeleniumServerQualifiedName()
5277
$files = opendir($binDirectory = static::prependPackagePath('vendor/bin'));
5378

5479
while (false !== ($file = readdir($files))) {
55-
if (str_contains($file, 'selenium')) {
80+
if (str_contains($file, 'selenium') && str_contains($file, $this->argument('serverVersion'))) {
5681
return $binDirectory.DIRECTORY_SEPARATOR.$file;
5782
}
5883
}
@@ -69,7 +94,7 @@ public function downloadSelenium()
6994
{
7095
$this->info('Downloading Selenium server file. Please wait...');
7196

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

75100
$process->run();
@@ -102,7 +127,7 @@ protected function getWebDriver($driverName)
102127
]);
103128
}
104129

105-
return "-Dwebdriver.$driverName.driver={$driver}";
130+
return "-Dwebdriver.{$this->dWebDriver[$driverName]}.driver={$driver}";
106131
}
107132

108133
protected function getSeleniumOptions()

‎src/Console/Kernel.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
namespace Modelizer\Selenium\Console;
44

55
use Illuminate\Foundation\Console\ServeCommand;
6+
use Orchestra\Testbench\Console\Kernel as OrchestraKernel;
67

7-
class Kernel extends \Orchestra\Testbench\Console\Kernel
8+
class Kernel extends OrchestraKernel
89
{
910
/**
1011
* The Artisan commands provided by your application.
@@ -14,6 +15,6 @@ class Kernel extends \Orchestra\Testbench\Console\Kernel
1415
protected $commands = [
1516
BootSelenium::class,
1617
GetWebDriver::class,
17-
ServeCommand::class,
18+
ServeCommand::class
1819
];
1920
}

‎src/Console/MakeSeleniumTestCommand.php

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@
44

55
use Illuminate\Console\Command;
66
use Illuminate\Console\GeneratorCommand;
7+
use Modelizer\Selenium\Traits\WebDriverUtilsTrait;
78

89
class MakeSeleniumTestCommand extends GeneratorCommand
910
{
11+
use WebDriverUtilsTrait;
12+
1013
/**
1114
* The console command name.
1215
*
@@ -35,7 +38,7 @@ class MakeSeleniumTestCommand extends GeneratorCommand
3538
*/
3639
protected function getStub()
3740
{
38-
return __DIR__.'/stubs/test.stub';
41+
return self::prependPackagePath('stubs/test.stub');
3942
}
4043

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

5255
return $this->laravel['path.base'].'/tests/'.str_replace('\\', '/', $name).'.php';
5356
}
54-
55-
/**
56-
* Get the default namespace for the class.
57-
*
58-
* @param string $rootNamespace
59-
*
60-
* @return string
61-
*/
62-
protected function getDefaultNamespace($rootNamespace)
63-
{
64-
return $rootNamespace;
65-
}
6657
}

‎src/SeleniumTestCase.php

Lines changed: 61 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2,81 +2,96 @@
22

33
namespace Modelizer\Selenium;
44

5+
use Illuminate\Foundation\Bootstrap\LoadEnvironmentVariables;
6+
use Illuminate\Foundation\Testing\Concerns\InteractsWithAuthentication;
7+
use Illuminate\Foundation\Testing\Concerns\InteractsWithConsole;
8+
use Illuminate\Foundation\Testing\Concerns\InteractsWithContainer;
9+
use Illuminate\Foundation\Testing\Concerns\InteractsWithDatabase;
10+
use Illuminate\Foundation\Testing\Concerns\InteractsWithExceptionHandling;
11+
use Illuminate\Foundation\Testing\Concerns\InteractsWithSession;
12+
use Illuminate\Foundation\Testing\Concerns\MakesHttpRequests;
13+
use Illuminate\Foundation\Testing\Concerns\MocksApplicationServices;
514
use Lmc\Steward\Test\AbstractTestCase;
6-
use Modelizer\Selenium\Services\Application as Laravel;
7-
use Modelizer\Selenium\Services\InteractWithPage as Interaction;
8-
use Modelizer\Selenium\Services\ManageWindow;
9-
use Modelizer\Selenium\Services\WaitForElement;
10-
use Modelizer\Selenium\Services\WorkWithDatabase;
15+
use Modelizer\Selenium\Services\InteractWithPage;
16+
use Orchestra\Testbench\Concerns\Testing;
17+
use Orchestra\Testbench\Contracts\TestCase as OrchestraTestCaseContract;
1118

12-
class SeleniumTestCase extends AbstractTestCase
19+
abstract class SeleniumTestCase extends AbstractTestCase implements OrchestraTestCaseContract
1320
{
14-
use Laravel,
15-
Interaction,
16-
WorkWithDatabase,
17-
WaitForElement,
18-
ManageWindow;
21+
use Testing,
22+
InteractsWithAuthentication,
23+
InteractsWithConsole,
24+
InteractsWithContainer,
25+
InteractsWithDatabase,
26+
InteractsWithExceptionHandling,
27+
InteractsWithSession,
28+
MakesHttpRequests,
29+
MocksApplicationServices,
30+
InteractWithPage;
1931

2032
/**
33+
* The base URL to use while testing the application.
34+
*
2135
* @var string
2236
*/
23-
protected $baseUrl;
37+
protected $baseUrl = 'http://localhost';
2438

2539
/**
26-
* @var int
40+
* Setup the test environment.
41+
*
42+
* @return void
2743
*/
28-
protected $width;
44+
public function setUp(): void
45+
{
46+
$this->setUpTheTestEnvironment();
47+
48+
$this->baseUrl = env('APP_URL', $this->baseUrl);
49+
50+
parent::setUp();
51+
}
2952

3053
/**
31-
* @var int
54+
* Clean up the testing environment before the next test.
55+
*
56+
* @return void
3257
*/
33-
protected $height;
34-
35-
public function setUp()
58+
protected function tearDown()
3659
{
37-
$this->setUpLaravel();
38-
$this->baseUrl = env('APP_URL', 'http://localhost/');
39-
$this->wd->get($this->baseUrl);
40-
41-
$this->setBrowser(env('DEFAULT_BROWSER', 'chrome'));
60+
$this->tearDownTheTestEnvironment();
4261
}
4362

44-
public function setupPage()
63+
/**
64+
* Boot the testing helper traits.
65+
*
66+
* @return array
67+
*/
68+
protected function setUpTraits()
4569
{
46-
if (empty($this->width)) {
47-
$this->width = env('SELENIUM_WIDTH', 1024);
48-
}
49-
50-
if (empty($this->height)) {
51-
$this->height = env('SELENIUM_HEIGHT', 768);
52-
}
53-
54-
$this->changeWindowSize($this->width, $this->height);
70+
return $this->setUpTheTestEnvironmentTraits();
5571
}
5672

5773
/**
58-
* Force selenium to wait.
74+
* Refresh the application instance.
5975
*
60-
* @param int|float $seconds The number of seconds or partial seconds to wait
61-
*
62-
* @return $this
76+
* @return void
6377
*/
64-
protected function wait($seconds = 1)
78+
protected function refreshApplication()
6579
{
66-
usleep($seconds * 1000000);
67-
68-
return $this;
80+
$this->app = $this->createApplication();
6981
}
7082

7183
/**
72-
* Alias for wait.
84+
* Define environment setup.
7385
*
74-
* @param int $seconds
86+
* @param \Illuminate\Foundation\Application $app
7587
*
76-
* @return SeleniumTestCase
88+
* @return void
7789
*/
78-
public function hold($seconds = 1)
90+
protected function getEnvironmentSetUp($app)
7991
{
80-
return $this->wait($seconds);
92+
putenv('APP_ENV=testing');
93+
$app->useEnvironmentPath(__DIR__.'/..');
94+
$app->loadEnvironmentFrom('testing.env');
95+
$app->bootstrapWith([LoadEnvironmentVariables::class]);
8196
}
8297
}

‎src/Services/Application.php

Lines changed: 0 additions & 109 deletions
This file was deleted.

‎src/Services/InteractWithPage.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,4 +295,29 @@ protected function findElement($name)
295295

296296
throw new CannotFindElement('Cannot find element: '.$value.' isn\'t visible on the page');
297297
}
298+
299+
/**
300+
* Force selenium to wait.
301+
*
302+
* @param int|float $seconds The number of seconds or partial seconds to wait
303+
*
304+
* @return $this
305+
*/
306+
protected function wait($seconds = 1)
307+
{
308+
usleep($seconds * 1000000);
309+
310+
return $this;
311+
}
312+
313+
/**
314+
* Alias for wait.
315+
*
316+
* @param int $seconds
317+
* @return TestCase
318+
*/
319+
protected function hold($seconds = 1)
320+
{
321+
return $this->wait($seconds);
322+
}
298323
}

‎src/Services/ManageWindow.php

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,41 @@
22

33
namespace Modelizer\Selenium\Services;
44

5+
use Facebook\WebDriver\Remote\RemoteWebDriver;
6+
use Facebook\WebDriver\WebDriverPoint;
7+
58
trait ManageWindow
69
{
10+
/**
11+
* @var RemoteWebDriver
12+
*/
13+
public $wd;
14+
715
/**
816
* Change the current window's width and height.
917
*
1018
* @param int $width
1119
* @param int $height
12-
*
1320
* @return $this
1421
*/
15-
public function changeWindowSize($width = 1024, $height = 768)
22+
public function changeWindowSize(int $width = 1024, int $height = 768)
1623
{
17-
if (!empty($width) && !empty($height) &&
18-
is_int(intval($width)) && is_int(intval($height))) {
19-
$this->prepareSession()->currentWindow()->size([
20-
'width' => intval($width),
21-
'height' => intval($height),
22-
]);
23-
}
24+
$this->wd->manage()->window()->setPosition(new WebDriverPoint($width, $height));
2425

2526
return $this;
2627
}
2728

2829
/**
2930
* Set the current window's width.
3031
*
31-
* @param int $width
32-
*
33-
* @return $this
32+
* @param $width
33+
* @return \Facebook\WebDriver\WebDriverWindow
3434
*/
3535
public function setWidth($width)
3636
{
37-
$this->width = $width;
38-
39-
return $this->changeWindowSize($this->width, $this->height);
37+
return $this->wd->manage()
38+
->window()
39+
->setPosition(new WebDriverPoint($width, self::BROWSER_HEIGHT));
4040
}
4141

4242
/**
@@ -48,8 +48,6 @@ public function setWidth($width)
4848
*/
4949
public function setHeight($height)
5050
{
51-
$this->height = $height;
52-
53-
return $this->changeWindowSize($this->width, $this->height);
51+
return $this->changeWindowSize(self::BROWSER_WIDTH, $height);
5452
}
5553
}

‎tests/TestCase.php

Lines changed: 0 additions & 123 deletions
This file was deleted.

‎tests/feature/Console/GetSeleniumServerTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
namespace Modelizer\Selenium\Tests\Feature\Console;
44

5-
use Modelizer\Selenium\Tests\TestCase;
5+
use Modelizer\Selenium\SeleniumTestCase;
66

7-
class GetSeleniumServerTest extends TestCase
7+
class GetSeleniumServerTest extends SeleniumTestCase
88
{
99
/** @test */
1010
public function it_should_download_selenium_web_server()

‎tests/feature/FormTest.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,28 @@
22

33
namespace Modelizer\Selenium\Tests\Feature;
44

5-
use Modelizer\Selenium\Tests\TestCase;
5+
use Modelizer\Selenium\SeleniumTestCase;
66

7-
class FormTest extends TestCase
7+
class FormTest extends SeleniumTestCase
88
{
99
/** @test */
1010
function it_should_fill_input_fields()
1111
{
1212
$this->visit()
1313
->click('Form')
1414
->see('Form Test')
15-
->type('John', 'firstName')
16-
->type('Hoopes', 'lastName')
17-
->typeById('john.hoopes@madisoncreativeweb.com', 'inputEmail');
15+
->type('Mohammed', 'firstName')
16+
->type('Mudassir', 'lastName')
17+
->typeById('hello@mudasir.me', 'inputEmail');
1818
}
1919

2020
/** @test */
2121
function it_should_type_information()
2222
{
2323
$formInfo = [
24-
'firstName' => 'John',
25-
'lastName' => 'Hoopes',
26-
'inputEmail' => 'john.hoopes@madisoncreativeweb.com',
24+
'firstName' => 'Mohammed',
25+
'lastName' => 'Mudassir',
26+
'inputEmail' => 'hello@mudasir.me',
2727
];
2828

2929
$this->visit()
@@ -61,9 +61,9 @@ function it_should_type_by_css_selector()
6161
function it_should_type_information_and_press_a_button()
6262
{
6363
$formInfo = [
64-
'firstName' => 'John',
65-
'lastName' => 'Hoopes',
66-
'inputEmail-name' => 'john.hoopes@madisoncreativeweb.com',
64+
'firstName' => 'Mohammed',
65+
'lastName' => 'Mudassir',
66+
'inputEmail-name' => 'hello@mudasir.me',
6767
];
6868

6969
$this->visit()
@@ -78,9 +78,9 @@ function it_should_type_information_and_press_a_button()
7878
function it_should_submit_form()
7979
{
8080
$formInfo = [
81-
'firstName' => 'John',
82-
'lastName' => 'Hoopes',
83-
'inputEmail-name' => 'john.hoopes@madisoncreativeweb.com',
81+
'firstName' => 'Mohammed',
82+
'lastName' => 'Mudassir',
83+
'inputEmail-name' => 'hello@mudasir.me',
8484
];
8585

8686
$this->visit()

‎tests/feature/InteractionTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
<?php
22

3-
namespace Modelizer\Selenium\Tests;
3+
namespace Modelizer\Selenium\Tests\Feature;
44

5-
class InteractionTest extends TestCase
5+
use Modelizer\Selenium\SeleniumTestCase;
6+
7+
class InteractionTest extends SeleniumTestCase
68
{
79
/** @test */
810
function it_should_visit_page()

0 commit comments

Comments
 (0)
Please sign in to comment.