|
13 | 13 |
|
14 | 14 | namespace Symfony\Component\Panther\Tests\ProcessManager;
|
15 | 15 |
|
| 16 | +use Facebook\WebDriver\Firefox\FirefoxOptions; |
| 17 | +use Facebook\WebDriver\Remote\DesiredCapabilities; |
16 | 18 | use PHPUnit\Framework\TestCase;
|
17 | 19 | use Symfony\Component\Panther\Exception\RuntimeException;
|
18 | 20 | use Symfony\Component\Panther\ProcessManager\FirefoxManager;
|
@@ -68,4 +70,54 @@ public function testMultipleInstances(): void
|
68 | 70 | $driver1->quit();
|
69 | 71 | $driver2->quit();
|
70 | 72 | }
|
| 73 | + |
| 74 | + public function testCanOverrideOptions(): void |
| 75 | + { |
| 76 | + $manager = new FirefoxManager(null, null, [ |
| 77 | + 'capabilities' => [ |
| 78 | + 'platform' => 'LINUX', |
| 79 | + 'browserName' => 'firefox-esr', |
| 80 | + 'moz:firefoxOptions' => [ |
| 81 | + 'prefs' => [ |
| 82 | + 'devtools.console.stdout.content' => true, |
| 83 | + 'reader.parse-on-load.enabled' => true, |
| 84 | + ], |
| 85 | + 'args' => [ |
| 86 | + '--new-instance', |
| 87 | + ], |
| 88 | + ], |
| 89 | + ], |
| 90 | + ]); |
| 91 | + $refl = new \ReflectionMethod($manager, 'buildCapabilities'); |
| 92 | + $refl->setAccessible(true); |
| 93 | + $capabilities = $refl->invoke($manager); |
| 94 | + |
| 95 | + $this->assertInstanceOf(DesiredCapabilities::class, $capabilities); |
| 96 | + $this->assertEquals('LINUX', $capabilities->getCapability('platform')); |
| 97 | + $this->assertEquals('firefox-esr', $capabilities->getCapability('browserName')); |
| 98 | + |
| 99 | + $this->assertInstanceOf(FirefoxOptions::class, $capabilities->getCapability('moz:firefoxOptions')); |
| 100 | + $mozFirefoxOptions = $capabilities->getCapability('moz:firefoxOptions')->toArray(); |
| 101 | + $this->assertArrayHasKey('prefs', $mozFirefoxOptions); |
| 102 | + |
| 103 | + // // our preferences should be set |
| 104 | + $this->assertArrayHasKey('devtools.console.stdout.content', $mozFirefoxOptions['prefs']); |
| 105 | + $this->assertTrue($mozFirefoxOptions['prefs']['devtools.console.stdout.content']); |
| 106 | + |
| 107 | + // but the default one should still be there |
| 108 | + $this->assertArrayHasKey('ui.prefersReducedMotion', $mozFirefoxOptions['prefs']); |
| 109 | + $this->assertEquals('1', $mozFirefoxOptions['prefs']['ui.prefersReducedMotion']); |
| 110 | + $this->assertArrayHasKey('devtools.jsonview.enabled', $mozFirefoxOptions['prefs']); |
| 111 | + $this->assertFalse($mozFirefoxOptions['prefs']['devtools.jsonview.enabled']); |
| 112 | + |
| 113 | + // except if we override then |
| 114 | + $this->assertArrayHasKey('reader.parse-on-load.enabled', $mozFirefoxOptions['prefs']); |
| 115 | + $this->assertTrue($mozFirefoxOptions['prefs']['reader.parse-on-load.enabled']); |
| 116 | + |
| 117 | + // default arguments should still be there |
| 118 | + $this->assertContains('--headless', $mozFirefoxOptions['args']); |
| 119 | + |
| 120 | + // but our custom one should be there too |
| 121 | + $this->assertContains('--new-instance', $mozFirefoxOptions['args']); |
| 122 | + } |
71 | 123 | }
|
0 commit comments