title: cakephp 3 selenium facebook webdriver auth
body: <p>I am using cakephp 3, selenium facebook web driver and phpunit.</p>
  
  <p>The problem I have is that I can't access pages that require authentication. I have tried adding the same auth session that I used in my controller unit tests. This doesn't work.</p>
  
  <pre><code>$this-&gt;session(['Auth.User.id' =&gt; 1, 'Auth.User.role' =&gt; 'admin']);
  </code></pre>
  
  <p>I then got the test to login first before executing the other tests. This didn't work. I guess I have to add a session.</p>
  
  <pre><code>    &lt;?php
  
  use \Facebook\WebDriver\Remote\DesiredCapabilities;
  use \Facebook\WebDriver\Remote\RemoteWebDriver;
  use \Facebook\WebDriver\WebDriverBy;
  
  /**
   * Description of UserEditTest
   *
   * @author john
   */
  class UserEditTest extends PHPUnit_Framework_TestCase 
  {
  
      protected $webDriver;
  
  
  
  
      public function setUp()
      {
           $this-&gt;webDriver = RemoteWebDriver::create('http://localhost:4444/wd/hub', DesiredCapabilities::firefox());
          // $this-&gt;session(['Auth.User.id' =&gt; 1, 'Auth.User.role' =&gt; 'admin']);
      }
  
      protected $url = 'http://localhost:81/dev/usedCars/users/edit/11'; 
  
  
        //return should contain Please enter your username and password
      public function validLoginProvider()
      {
          $inputs[] = [
              [
                  'username'              =&gt; 'testuser',
                  'password'              =&gt; 'test',               
              ]
          ];
  
          return $inputs;
      }
      //login input
    public function fillLoginFormAndSubmit($inputs)
  {
  
  
      $this-&gt;webDriver-&gt;get('http://localhost:81/dev/usedCars/users/login');
      $form = $this-&gt;webDriver-&gt;findElement(WebDriverBy::id('login'));
      var_dump($inputs);
  
      foreach ($inputs as $input =&gt; $value) {
          $form-&gt;findElement(WebDriverBy::name($input))-&gt;sendKeys($value);      
      }
      $form-&gt;submit();
  }
  
  /**
   * @dataProvider validLoginProvider
   */
  public function testValidFormSubmission(array $inputs)
  {
      $this-&gt;fillLoginFormAndSubmit($inputs);
  
      $content = $this-&gt;webDriver-&gt;findElement(WebDriverBy::tagName('body'))-&gt;getText();
      $this-&gt;assertContains('Showroom', $content);
  
      testValidEditSubmission();
  
  }
  
  
  
   //for testing the edit view page
        public function validInputsProvider()
      {
  
             $inputs[] = [
              [
                 'interests'              =&gt; 'changed'
              ] 
          ];
  
          return $inputs;
      }
  
       //for testing the edit page
      public static function invalidInputsProvider()
      {
           $inputs[] = [
              [              
                  'email'              =&gt; 'mypassword'
  
              ]
          ];
  
  
          return $inputs;
      }
  
  
  
        public function fillFormAndSubmit($inputs)
  {
         // $this-&gt;session(['Auth.User.id' =&gt; 1, 'Auth.User.role' =&gt; 'admin']);
  
      $this-&gt;webDriver-&gt;get('http://localhost:81/dev/usedCars/users/edit/11');
      $form = $this-&gt;webDriver-&gt;findElement(WebDriverBy::id('edit'));
      var_dump($inputs);
  
      foreach ($inputs as $input =&gt; $value) {
          $form-&gt;findElement(WebDriverBy::name($input))-&gt;sendKeys($value);
  
  
      }
  
      $form-&gt;submit();
  }
  
  
  /**
   * @dataProvider validInputsProvider
   */
  public function testValidEditSubmission(array $inputs)
  {
  
  
      $this-&gt;fillFormAndSubmit($inputs);
  
      $content = $this-&gt;webDriver-&gt;findElement(WebDriverBy::tagName('body'))-&gt;getText();
      $this-&gt;assertContains('The user has been saved', $content);
  }
  
  
  /**
   * @dataProvider invalidInputsProvider
   */
  public function testInvalidEditSubmission(array $inputs)
  {
      $this-&gt;fillFormAndSubmit($inputs);
  
     $content = $this-&gt;webDriver-&gt;findElement(WebDriverBy::tagName('body'))-&gt;getText();
       $this-&gt;assertContains('valid email', $content);
  }
  
      public function tearDown()
  {
      $this-&gt;webDriver-&gt;quit();
  }   //put your code here
  }
  </code></pre>