Element-34 / php-webdriver

thin php client for webdriver.
122 stars 55 forks source link

Incorrectly constructs URLs (two session IDs in the call) #48

Open linguinee opened 11 years ago

linguinee commented 11 years ago

I'm trying to use php-webdriver to communicate with Appium (which uses the WebDriver Wire Protocol) to test mobile apps. However, I get errors when I try to send requests, and it looks like the URLs are malformed.

Test code:

require_once '../vendor/element-34/php-webdriver/PHPWebDriver/__init__.php';
require_once '../vendor/element-34/php-webdriver/PHPWebDriver/WebDriverBy.php';                                    

class LoginTest extends PHPUnit_Framework_TestCase
{
  protected static $session;

  protected static $server_url   = 'http://localhost:4723/wd/hub';
  protected static $capabilities = array('app' => '/Users/lkung/Documents/iOS/AcceptanceTests/Test.app',
                                         'device' => 'iPhone Simulator',
                                         'version' => '6.1'
                                         );

  public static function setUpBeforeClass()
  {
    $driver = new PHPWebDriver_WebDriver(self::$server_url);
    self::$session = $driver->session('iphone', self::$capabilities);
    self::$session->implicitlyWait(15);
  }

  public static function tearDownAfterClass()
  {
    self::$session->close();
  }

  public function test()
  {
    $element = self::$session->element(PHPWebDriver_WebDriverBy::NAME,
                                       'Log in with Facebook');
    $element->click("");
  }
}

Appium logs:

info: Appium session started with sessionId 5b0446ac-c0ad-4441-9366-361c72783312
POST /wd/hub/session 303 5555ms - 9
debug: Appium request initiated at /wd/hub/session/5b0446ac-c0ad-4441-9366-361c72783312
info: Responding to client with success: {"status":0,"value":{"version":"6.0","webStorageEnabled":false,"locationContextEnabled":false,"browserName":"iOS","platform":"MAC","javascriptEnabled":true,"databaseEnabled":false,"takesScreenshot":true},"sessionId":"5b0446ac-c0ad-4441-9366-361c72783312"}
GET /wd/hub/session/5b0446ac-c0ad-4441-9366-361c72783312 200 2ms - 319
info: [INST] 2013-09-19 22:36:43 +0000 Default: Set bootstrap config key 'useLocationServices' to true
debug: Appium request initiated at /wd/hub/session/5b0446ac-c0ad-4441-9366-361c72783312/5b0446ac-c0ad-4441-9366-361c72783312/timeouts
debug: Request received with params: {"type":"implicit","ms":15000}
info: Responding to client that we did not find a valid resource
POST /wd/hub/session/5b0446ac-c0ad-4441-9366-361c72783312/5b0446ac-c0ad-4441-9366-361c72783312/timeouts 404 2ms - 47
debug: Appium request initiated at /wd/hub/session/5b0446ac-c0ad-4441-9366-361c72783312/5b0446ac-c0ad-4441-9366-361c72783312/element
debug: Request received with params: {"using":"name","value":"Log in with Facebook"}
info: Responding to client that we did not find a valid resource
POST /wd/hub/session/5b0446ac-c0ad-4441-9366-361c72783312/5b0446ac-c0ad-4441-9366-361c72783312/element 404 1ms - 47

As seen in the logs, the implicit wait request and the element find request respond with the Responding to client that we did not find a valid resource error. The PHPUnit test fails due to Fatal error: Call to a member function click() on a non-object in /Users/lkung/Documents/iOS/AcceptanceTests/tests/test.php on line 30, since the element was not returned.

Looking at where the Appium request came from, Appium request initiated at /wd/hub/session/5b0446ac-c0ad-4441-9366-361c72783312/ 5b0446ac-c0ad-4441-9366-361c72783312 /timeouts, the session ID is present twice.

The error Appium throws for Android (using Selendroid) is slightly different (Proxied response received with status 500: undefined), but still looks like it has the session ID present twice. The PHPUnit test fails the same way - due to "click() on a non-object".

Appium logs:

info: Successfully started selendroid session
info: Waiting for app's activity to become focused
info: Getting focused package and activity
info: Overriding session id with 0049f9d7-8184-4d23-bf20-674bacb5faa0
info: Appium session started with sessionId 0049f9d7-8184-4d23-bf20-674bacb5faa0
POST /wd/hub/session 303 21472ms - 9
debug: Appium request initiated at /wd/hub/session/0049f9d7-8184-4d23-bf20-674bacb5faa0
debug: Proxying command to localhost:8080
info: Making http request with opts: {"url":"http://localhost:8080/wd/hub/session/0049f9d7-8184-4d23-bf20-674bacb5faa0","method":"GET"}
debug: Proxied response received with status 200: "{\"value\":{\"platform\":\"android\",\"acceptSslCerts\":true,\"javascriptEnabled\":true,\"handlesAlerts\":false,\"browserName\":\"selendroid\",\"rotatable\":false,\"takesScreenshot\":true,\"version\":\"0.5.0\"},\"status\":0,\"sessionId\":\"0049f9d7-8184-4d23-bf20-674bacb5faa0\"}"
GET /wd/hub/session/0049f9d7-8184-4d23-bf20-674bacb5faa0 200 21ms - 249
debug: Appium request initiated at /wd/hub/session/0049f9d7-8184-4d23-bf20-674bacb5faa0/0049f9d7-8184-4d23-bf20-674bacb5faa0/timeouts
debug: Request received with params: {"type":"implicit","ms":15000}
debug: Proxying command to localhost:8080
info: Making http request with opts: {"url":"http://localhost:8080/wd/hub/session/0049f9d7-8184-4d23-bf20-674bacb5faa0/0049f9d7-8184-4d23-bf20-674bacb5faa0/timeouts","method":"POST","json":{"type":"implicit","ms":15000}}
debug: Proxied response received with status 500: undefined
POST /wd/hub/session/0049f9d7-8184-4d23-bf20-674bacb5faa0/0049f9d7-8184-4d23-bf20-674bacb5faa0/timeouts 500 36ms
debug: Appium request initiated at /wd/hub/session/0049f9d7-8184-4d23-bf20-674bacb5faa0/0049f9d7-8184-4d23-bf20-674bacb5faa0/element
debug: Request received with params: {"using":"id","value":"button_fbLogin"}
debug: Proxying command to localhost:8080
info: Making http request with opts: {"url":"http://localhost:8080/wd/hub/session/0049f9d7-8184-4d23-bf20-674bacb5faa0/0049f9d7-8184-4d23-bf20-674bacb5faa0/element","method":"POST","json":{"using":"id","value":"button_fbLogin"}}
debug: Proxied response received with status 500: undefined
POST /wd/hub/session/0049f9d7-8184-4d23-bf20-674bacb5faa0/0049f9d7-8184-4d23-bf20-674bacb5faa0/element 500 60ms