Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests not hitting APP_URL in proxy environment #15

Closed
haakym opened this issue Sep 29, 2016 · 13 comments
Closed

Tests not hitting APP_URL in proxy environment #15

haakym opened this issue Sep 29, 2016 · 13 comments

Comments

@haakym
Copy link
Contributor

haakym commented Sep 29, 2016

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
Copy link
Contributor Author

haakym commented Sep 29, 2016

Related?

Codeception/Codeception#2651

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

@Modelizer
Copy link
Owner

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
Copy link
Contributor Author

haakym commented Sep 30, 2016

@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: Codeception/Codeception#3042 and here Codeception/Codeception#2651

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

@Modelizer
Copy link
Owner

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
Copy link
Contributor Author

haakym commented Oct 6, 2016

@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
Copy link
Owner

@haakym
Copy link
Contributor Author

haakym commented Nov 16, 2016

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

@Modelizer
Copy link
Owner

Modelizer commented Nov 21, 2016

closing this issue for now.

@haakym
Copy link
Contributor Author

haakym commented Nov 22, 2016

@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
  1. add to app.php
Modelizer\Selenium\SeleniumServiceProvider::class,
  1. php artisan selenium:make:test SeleniumExampleTest

  2. 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);
    }
  1. create file: config/selenium.php with following content:
<?php

return [
	'proxyInjectionMode' => true
];

Unsure I am doing the correct thing here?

  1. 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>                                                                                                  
<html>                                                                                                                          
    <head>                                                                                                                      
        <title>Laragon</title>                                                                                                  
                                                                                                                                
        <link href="https://fonts.googleapis.com/css?family=Karla:400" rel="stylesheet" type="text/css">                        
                                                                                                                                
        <style>                                                                                                                 
            html, body {                                                                                                        
                height: 100%;                                                                                                   
            }                                                                                                                   
                                                                                                                                
            body {                                                                                                              
                margin: 0;                                                                                                      
                padding: 0;                                                                                                     
                width: 100%;                                                                                                    
                display: table;                                                                                                 
                font-weight: 100;                                                                                               
                font-family: 'Karla';                                                                                           
            }                                                                                                                   
                                                                                                                                
            .container {                                                                                                        
                text-align: center;                                                                                             
                display: table-cell;                                                                                            
                vertical-align: middle;                                                                                         
            }                                                                                                                   
                                                                                                                                
            .content {                                                                                                          
                text-align: center;                                                                                             
                display: inline-block;                                                                                          
            }                                                                                                                   
                                                                                                                                
            .title {                                                                                                            
                font-size: 96px;                                                                                                
            }                                                                                                                   
                                                                                                                                
            .opt {                                                                                                              
                margin-top: 30px;                                                                                               
            }                                                                                                                   
                                                                                                                                
            .opt a {                                                                                                            
              text-decoration: none;                                                                                            
              font-size: 150%;                                                                                                  
            }                                                                                                                   
                                                                                                                                
            a:hover {                                                                                                           
              color: red;                                                                                                       
            }                                                                                                                   
        </style>                                                                                                                
    </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\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 Modelizer added bug and removed enhancement labels Nov 22, 2016
@Modelizer
Copy link
Owner

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

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

@Modelizer Modelizer reopened this Nov 22, 2016
@haakym
Copy link
Contributor Author

haakym commented Nov 22, 2016

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
Copy link

paulg446 commented Dec 5, 2016

@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 Modelizer changed the title Tests not hitting APP_URL value - instead going to localhost Tests not hitting APP_URL in proxy environment Dec 1, 2017
@Modelizer
Copy link
Owner

Upgrading to 2.0 should solve this problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants