Modelizer / Laravel-Selenium

Selenium Testing for Laravel 5
MIT License
108 stars 33 forks source link

Tests not hitting APP_URL in proxy environment #15

Closed haakym closed 6 years ago

haakym commented 8 years ago

Hi. Firstly, great idea for a package I look forward to seeing it develop further!

I'm developing locally using Laragon on Windows 7 for which I used to start up a fresh install of Laravel 5.3 and pulled in the package and then followed the installation instructions from the readme.

I've added the following values to my .env file:

APP_URL="http://modelizer-selenium.dev/" SELENIUM_WIDTH=1024 SELENIUM_HEIGHT=768

Then when I run the selenium server and phpunit it hits localhost and not http://modelizer-selenium.dev/, this is what I've got in the console which is the Laragon splash page which is returned when you hit localhost:

C:\laragon\www\modelizer-selenium (master) 29/09/2016 14:57:15.43                                                                     
λ phpunit                                                                                                                             
PHPUnit 5.5.5 by Sebastian Bergmann and contributors.                                                                                 

.E                                                                  2 / 2 (100%)                                                      

Time: 318 ms, Memory: 8.00MB                                                                                                          

There was 1 error:                                                                                                                    

1) SeleniumExampleTest::testBasicExample                                                                                              
PHPUnit_Extensions_Selenium2TestCase_Exception: JSON decoding of remote response failed.                                              
Error code: 4                                                                                                                         
The response: '<!DOCTYPE html>                                                                                                        
<html>                                                                                                                                
    <head>                                                                                                                            
        <title>Laragon</title                                                                                                        
    </head>                                                                                                                           
    <body>                                                                                                                            
        <div class="container">                                                                                                       
            <div class="content">                                                                                                     
                <div class="title" title="Laragon">Laragon</div>                                                                      

                <div class="info"><br />                                                                                              
                      Apache/2.4.23 (Win32) mod_authnz_sspi/0.1.0 OpenSSL/1.0.2h PHP/7.0.10<br />                                     
                      PHP version: 7.0.10   <span><a title="phpinfo()" href="/?q=info">info</a></span><br />                          
                      Document Root: C:/laragon/www<br />                                                                             

                </div>                                                                                                                
                <div class="opt">                                                                                                     
                  <div><a title="Getting Started" href="http://laragon.org/?q=getting-started">Getting Started</a></div>              
                </div>                                                                                                                
            </div>                                                                                                                    

        </div>                                                                                                                        
    </body>                                                                                                                           
</html>'                                                                                                                              

C:\laragon\www\modelizer-selenium\vendor\phpunit\phpunit-selenium\PHPUnit\Extensions\Selenium2TestCase\Driver.php:142                 
C:\laragon\www\modelizer-selenium\vendor\phpunit\phpunit-selenium\PHPUnit\Extensions\Selenium2TestCase\Driver.php:71                  
C:\laragon\www\modelizer-selenium\vendor\phpunit\phpunit-selenium\PHPUnit\Extensions\Selenium2TestCase\SessionStrategy\Isolated.php:67
C:\laragon\www\modelizer-selenium\vendor\phpunit\phpunit-selenium\PHPUnit\Extensions\Selenium2TestCase.php:296                        
C:\laragon\www\modelizer-selenium\vendor\phpunit\phpunit-selenium\PHPUnit\Extensions\Selenium2TestCase.php:337                        
C:\laragon\www\modelizer-selenium\vendor\phpunit\phpunit-selenium\PHPUnit\Extensions\Selenium2TestCase.php:314                        
C:\Users\djones.SACBUK\AppData\Roaming\Composer\vendor\phpunit\phpunit\src\TextUI\Command.php:162                                     
C:\Users\djones.SACBUK\AppData\Roaming\Composer\vendor\phpunit\phpunit\src\TextUI\Command.php:113                                     

ERRORS!                                                                                                                               
Tests: 2, Assertions: 2, Errors: 1.                                                                                                   

I also tried adding the following to my phpunit.xml:

<env name="APP_URL" value="http://modelizer-selenium.dev/"/>

this to my tests/TestCase.php:

protected $baseUrl = 'http://modelizer-selenium.dev';

The failing test looks like this:

    public function testBasicExample()
    {
        // This is a sample code you can change as per your current scenario
        $this->visit('/')
             ->see('Laravel')
             ->hold(3);
    }

Any ideas? Thanks!

haakym commented 8 years ago

Related?

https://github.com/Codeception/Codeception/issues/2651

If this is an issue with proxy settings, how or where can I set them?

Modelizer commented 8 years ago

Thanks a lot @haakym If this is in your test case

$this->visit('/')
             ->see('Laravel')
             ->hold(3);

Then test will fail because it's looking for Laravel and your body contain Laragon

Also, it seems the problem is not related to baseUrl because phpunit is not able to decode json PHPUnit_Extensions_Selenium2TestCase_Exception: JSON decoding of remote response failed.

Also, your tag at <title>Laragon</title is not been close properly.

haakym commented 8 years ago

@Modelizer

Thanks for your reply! I'm not sure you fully understood my issue, I will try to explain in more detail.

The test fails because it's hitting the wrong URL which gives different content to what is expected. I'm using a WAMP app called Laragon and that's the splash page which is shown at http://localhost.

I thought the issue was related to the baseUrl because it was going to http://localhost instead of my desired URL: http://modelizer-selenium.dev

After googling some of the output after running phpunit I now believe the issue is related to the chrome webdriver and proxy settings (I'm behind a proxy at my work place), as others were having issues using codeception and the chrome webdriver here: https://github.com/Codeception/Codeception/issues/3042 and here https://github.com/Codeception/Codeception/issues/2651

How would I be able to set the proxy settings to resolve this issue?

Modelizer commented 8 years ago

Okay.

What if we provide an option which will be loaded when selenium server is started. Example PHP artisan selenium:start --proxy-server=192.168.1.1

Will this help you? Because right now I think we need to tell selenium which proxy needs to be loaded, check this out.

This issue is new for me correct me if I'm wrong :)

haakym commented 8 years ago

@Modelizer

Sorry for the late reply.

What if we provide an option which will be loaded when selenium server is started. Example PHP artisan selenium:start --proxy-server=192.168.1.1

Will this help you?

Yes, that looks good! To be honest, it's new for me too.

Modelizer commented 8 years ago

Now you can try https://github.com/Modelizer/Selenium/wiki/Selenium-Options#proxyinjectionmode

haakym commented 8 years ago

@Modelizer - awesome, I'll give this a try soon and will be sure to give feedback

Modelizer commented 7 years ago

closing this issue for now.

haakym commented 7 years ago

@Modelizer I've done the following...

  1. laravel new seleniumtest

now if I go to http://seleniumtest.dev/ I see the following in my browser:

image

  1. composer require modelizer/selenium "~1.0"

  2. add to .env:

    APP_URL="http://seleniumtest.dev/"
    SELENIUM_WIDTH=1024
    SELENIUM_HEIGHT=768
  3. add to app.php

    Modelizer\Selenium\SeleniumServiceProvider::class,
  4. php artisan selenium:make:test SeleniumExampleTest

  5. add to SeleniumExampleTest.php:

    public function testBasicExample()
    {
        // This is a sample code you can change as per your current scenario
        $this->visit('/')
             ->see('Laravel')
             ->hold(3);
    }
  6. create file: config/selenium.php with following content:

    
    <?php

return [ 'proxyInjectionMode' => true ];


Unsure I am doing the correct thing here?

8. `php artisan selenium:start`

When running `phpunit` I get the same issue as before:
 - the tests appear to be hitting the server software splash page on `http://localhost` not `http://seleniumtest.dev`

PHPUnit 5.6.5 by Sebastian Bergmann and contributors.

.E 2 / 2 (100%)

Time: 234 ms, Memory: 10.00MB

There was 1 error:

1) SeleniumExampleTest::testBasicExample
PHPUnit_Extensions_Selenium2TestCase_Exception: JSON decoding of remote response failed.
Error code: 4
The response: '<!DOCTYPE html>

Laragon
Laragon

Apache/2.4.23 (Win32) mod_authnz_sspi/0.1.0 OpenSSL/1.0.2h PHP/7.0.10
PHP version: 7.0.10 info
Document Root: C:/laragon/www
' C:\laragon\www\seleniumtest\vendor\phpunit\phpunit-selenium\PHPUnit\Extensions\Selenium2TestCase\Driver.php:142 C:\laragon\www\seleniumtest\vendor\phpunit\phpunit-selenium\PHPUnit\Extensions\Selenium2TestCase\Driver.php:71 C:\laragon\www\seleniumtest\vendor\phpunit\phpunit-selenium\PHPUnit\Extensions\Selenium2TestCase\SessionStrategy\Isolated.php:67 C:\laragon\www\seleniumtest\vendor\phpunit\phpunit-selenium\PHPUnit\Extensions\Selenium2TestCase.php:296 C:\laragon\www\seleniumtest\vendor\phpunit\phpunit-selenium\PHPUnit\Extensions\Selenium2TestCase.php:337 C:\laragon\www\seleniumtest\vendor\phpunit\phpunit-selenium\PHPUnit\Extensions\Selenium2TestCase.php:314 ERRORS! Tests: 2, Assertions: 2, Errors: 1. ``` Any suggestions would be appreciated. Thank you very much!
Modelizer commented 7 years ago

ping @jhoopes @chrispecoraro Have you guys have any idea what is going on? :thinking:

I think if we able to pass a correct APP_URL in the proxy environment will solve this issue.

haakym commented 7 years ago

Just to add some further context if you didn't read my first few posts on this issue, I am using this package at work where we're behind a proxy and thought this was causing the issue as googling similar errors brought up results related to proxy settings for selenium?

paulg446 commented 7 years ago

@haakym try removing the trailing forward slash from the APP_URL... APP_URL="http://seleniumtest.dev/" => APP_URL="http://seleniumtest.dev" And then with testing, omit first forward slash also, ie $this->visit('foo') instead of $this->visit('/foo')

Modelizer commented 6 years ago

Upgrading to 2.0 should solve this problem.