lmc-eu / steward

PHP libraries that makes Selenium WebDriver + PHPUnit functional testing easy and robust
MIT License
221 stars 40 forks source link

Find element fails as returning string instead of expected array #293

Closed andreaschiffo closed 2 years ago

andreaschiffo commented 2 years ago

https://github.com/lmc-eu/steward/blob/5868bdf18eb060d607c6def84e2da92121b4c5f1/src/Test/SyntaxSugarTrait.php#L28

I have a test that does

public function closeNewsletterWidget() {
    try {
        $this->waitForClass(self::CLOSE_NEWSLETTER_WIDGET_CLASS, true)->click();
    } catch (Exception $e) {
        $this->tc->log("Newsletter widget not present when trying to close it.");}
    }

hence goes through the SyntaxSugarTrait waitForClass method, which eventually fails in php-webdriver

`<error type="TypeError">Client\QAAutomation\CheckoutTest::testItemCanBePutInShoppingCart
TypeError: Argument 1 passed to Facebook\WebDriver\Remote\JsonWireCompat::getElement() must be of the type array, string given, called in /home/aschiffo/Documents/Andrea/Client/client-qa-automation/vendor/php-webdriver/webdriver/lib/Remote/RemoteWebDriver.php on line 211

/home/aschiffo/Documents/Andrea/Client/client-qa-automation/vendor/php-webdriver/webdriver/lib/Remote/JsonWireCompat.php:21
/home/aschiffo/Documents/Andrea/Client/client-qa-automation/vendor/php-webdriver/webdriver/lib/Remote/RemoteWebDriver.php:211
/home/aschiffo/Documents/Andrea/client/client-qa-automation/vendor/php-webdriver/webdriver/lib/WebDriverExpectedCondition.php:176
/home/aschiffo/Documents/Andrea/Client/client-qa-automation/vendor/php-webdriver/webdriver/lib/WebDriverWait.php:54
/home/aschiffo/Documents/Andrea/Client/client-qa-automation/vendor/lmc/steward/src/Test/SyntaxSugarTrait.php:320
/home/aschiffo/Documents/Andrea/Client/client-qa-automation/vendor/lmc/steward/src/Test/SyntaxSugarTrait.php:48
/home/aschiffo/Documents/Andrea/Client/client-qa-automation/tests/Pages/WWBasePage.php:54
/home/aschiffo/Documents/Andrea/Client/client-qa-automation/tests/CheckoutTest.php:30`

Here it is shown how waitForElement is correctly used. waitForClass Even though in the end fails on the actual result found as it's a string instead of an expected array findElement And also it seems it's returning that path without any session or similar instead of the actual Element.

Any ideas?

OndraM commented 2 years ago

Hi, what command do you use to: a) start selenium server (or some browser driver / docker) b) start steward

What version of selenium / browsers do you use?

Could you also provide output of steward run with -vvv options?

andreaschiffo commented 2 years ago

Hi @OndraM thanks for taking care

a) start selenium server (or some browser driver / docker)

I'm using Chrome standalone for debugging locally (to which this issue referes), java -jar -Dwebdriver.chrome.driver="./vendor/selenium/chromedriver" -jar ./vendor/selenium/selenium-server-4.0.0.jar standalone though on CI it will be run against a docker container in headless mode; from docker-compose file:

[...]
services:
  chrome:
    image: selenium/node-chrome:4.0.0-20211013
    shm_size: 2gb
    depends_on:
      - selenium-hub
    environment:
      - SE_EVENT_BUS_HOST=selenium-hub
      - SE_EVENT_BUS_PUBLISH_PORT=4442
      - SE_EVENT_BUS_SUBSCRIBE_PORT=4443
      - SE_NODE_GRID_URL=http://localhost:4444
    ports:
      - "6900:5900"
    volumes:
      - /tmp:/dev/shm:rw
[...]
  acme-qa:
    depends_on:
      - selenium-hub
      - chrome
      - firefox
    image: acme/qa-automation
    environment:
      - HUB_PORT_4444_TCP_ADDR=hub
      - HUB_PORT_4444_TCP_PORT=4444
    links:
      - selenium-hub
    volumes:
      - .:/wd/src

  selenium-hub:
    image: selenium/hub:4.0.0-20211013
    container_name: selenium-hub
    ports:
      - "4442:4442"
      - "4443:4443"
      - "4444:4444"

b) start steward

vendor/bin/steward run staging chrome --pattern CheckoutTest.php -vvv

Could you also provide output of steward run with -vvv options?

Using the above command, here it is:

aschiffo@mypc:~/Documents/Andrea/Acme/acme-qa-automation$ vendor/bin/steward run staging chrome --pattern CheckoutTest.php -vvv
Steward 3.0.0-DEV is running the tests... Just for you <3!
Browser: chrome
Environment: staging
Screen size: 
Path to logs: /home/aschiffo/Documents/Andrea/Acme/acme-qa-automation/logs
Ignore delays: no
Parallel limit: 50
Selenium server (hub) url: http://localhost:4444/wd/hub, trying connection...OK
Searching for testcases:
 - in directory "/home/aschiffo/Documents/Andrea/Acme/acme-qa-automation/tests"
 - by pattern "CheckoutTest.php"
Found testcase file #1: /home/aschiffo/Documents/Andrea/Acme/acme-qa-automation/tests/CheckoutTest.php
Testcase "Acme\QAAutomation\CheckoutTest" is prepared to be run`

`Starting execution of testcases
-------------------------------
[2021-11-29 00:40:40] Execution of testcase "Acme\QAAutomation\CheckoutTest" started with command:
'/usr/bin/php7.4' '/home/aschiffo/Documents/Andrea/Acme/acme-qa-automation/vendor/lmc/steward/bin/phpunit-steward' '--log-junit=/home/aschiffo/Documents/Andrea/Acme/acme-qa-automation/logs/Acme-QAAutomation-CheckoutTest.xml' '--configuration=/home/aschiffo/Documents/Andrea/Acme/acme-qa-automation/vendor/lmc/steward/src/phpunit.xml' '--colors=always' '/home/aschiffo/Documents/Andrea/Acme/acme-qa-automation/tests/CheckoutTest.php'
[2021-11-29 00:40:40] Waiting (running: 1, queued: 0, done: 0)
Acme\QAAutomation\CheckoutTest> [2021-11-29 00:40:40] Registering test results publisher "Lmc\Steward\Publisher\XmlPublisher"
Acme\QAAutomation\CheckoutTest> 
Acme\QAAutomation\CheckoutTest> PHPUnit 8.5.21 by Sebastian Bergmann and contributors.
Acme\QAAutomation\CheckoutTest> 
Acme\QAAutomation\CheckoutTest> [2021-11-29 00:40:40] --- Starting execution of test "testItemCanBePutInShoppingCart" ---
Acme\QAAutomation\CheckoutTest> [2021-11-29 00:40:40] Initializing "chrome" WebDriver
Acme\QAAutomation\CheckoutTest> 
Acme\QAAutomation\CheckoutTest> [2021-11-29 00:40:44] [WARN] Error publishing test started status to "Lmc\Steward\Publisher\XmlPublisher" ("Argument 1 passed to Lmc\Steward\Selenium\SeleniumServerAdapter::getSessionExecutor() must be of the type string, null given, called in /home/aschiffo/Documents/Andrea/Acme/acme-qa-automation/vendor/lmc/steward/src/Publisher/XmlPublisher.php on line 277")
Acme\QAAutomation\CheckoutTest> 
Acme\QAAutomation\CheckoutTest> E                                                                   1 / 1 (100%)
Acme\QAAutomation\CheckoutTest> [2021-11-29 00:40:45] [WARN] Error publishing test done status to "Lmc\Steward\Publisher\XmlPublisher" ("File "/home/aschiffo/Documents/Andrea/Acme/acme-qa-automation/logs/results.xml" was already opened by this XmlPublisher and closed")
Acme\QAAutomation\CheckoutTest> [2021-11-29 00:40:44] [DEBUG] Base URL set to "https://stg.acme.com/"
Acme\QAAutomation\CheckoutTest> [2021-11-29 00:40:44] [WebDriver] Loading URL "https://stg.acme.com/us_en/bath/fittings/faucets"
Acme\QAAutomation\CheckoutTest> [2021-11-29 00:40:44] [WebDriver] Executing command "get" with params {"url":"https://stg.acme.com/us_en/bath/fittings/faucets"}
Acme\QAAutomation\CheckoutTest> [2021-11-29 00:40:44] [WebDriver] Executing command "setWindowSize" with params {"width":1280,"height":1024,":windowHandle":"current"}
Acme\QAAutomation\CheckoutTest> [2021-11-29 00:40:44] [WebDriver] Executing command "findElement" with params {"using":"class name","value":"close-widget-newsletter"}
Acme\QAAutomation\CheckoutTest> [2021-11-29 00:40:44] [WebDriver] Executing command "getCurrentUrl" with params []
Acme\QAAutomation\CheckoutTest> [2021-11-29 00:40:44] [WebDriver] Executing command "screenshot" with params []
Acme\QAAutomation\CheckoutTest> [2021-11-29 00:40:45] [WebDriver] Executing command "getPageSource" with params []
Acme\QAAutomation\CheckoutTest> [2021-11-29 00:40:45] 
Acme\QAAutomation\CheckoutTest> [2021-11-29 00:40:45] [WARN] Test failed on page "/session//url", taking page snapshots:
Acme\QAAutomation\CheckoutTest> [2021-11-29 00:40:45] Screenshot: "/home/aschiffo/Documents/Andrea/Acme/acme-qa-automation/logs/Acme-QAAutomation-CheckoutTest-testItemCanBePutInShoppingCart-2021-11-29-00-40-44.png"
Acme\QAAutomation\CheckoutTest> [2021-11-29 00:40:45] HTML snapshot: "/home/aschiffo/Documents/Andrea/Acme/acme-qa-automation/logs/Acme-QAAutomation-CheckoutTest-testItemCanBePutInShoppingCart-2021-11-29-00-40-44.html"
Acme\QAAutomation\CheckoutTest> [2021-11-29 00:40:45] 
Acme\QAAutomation\CheckoutTest> [2021-11-29 00:40:45] Destroying "chrome" WebDriver for session ""
Acme\QAAutomation\CheckoutTest> [2021-11-29 00:40:45] [WebDriver] Executing command "close" with params []
Acme\QAAutomation\CheckoutTest> [2021-11-29 00:40:45] [WebDriver] Executing command "quit" with params []
Acme\QAAutomation\CheckoutTest> [2021-11-29 00:40:45] --- Finished execution of test "testItemCanBePutInShoppingCart" ---
Acme\QAAutomation\CheckoutTest> [2021-11-29 00:40:45] [WARN] Error publishing process done status to "Lmc\Steward\Publisher\XmlPublisher" ("File "/home/aschiffo/Documents/Andrea/Acme/acme-qa-automation/logs/results.xml" was already opened by this XmlPublisher and closed")
Acme\QAAutomation\CheckoutTest> 
Acme\QAAutomation\CheckoutTest> 
Acme\QAAutomation\CheckoutTest> Time: 4.6 seconds, Memory: 8.00 MB
Acme\QAAutomation\CheckoutTest> 
Acme\QAAutomation\CheckoutTest> There was 1 error:
Acme\QAAutomation\CheckoutTest> 
Acme\QAAutomation\CheckoutTest> 1) Acme\QAAutomation\CheckoutTest::testItemCanBePutInShoppingCart
Acme\QAAutomation\CheckoutTest> TypeError: Argument 1 passed to Facebook\WebDriver\Remote\JsonWireCompat::getElement() must be of the type array, string given, called in /home/aschiffo/Documents/Andrea/Acme/acme-qa-automation/vendor/php-webdriver/webdriver/lib/Remote/RemoteWebDriver.php on line 211
Acme\QAAutomation\CheckoutTest> 
Acme\QAAutomation\CheckoutTest> /home/aschiffo/Documents/Andrea/Acme/acme-qa-automation/vendor/php-webdriver/webdriver/lib/Remote/JsonWireCompat.php:21
Acme\QAAutomation\CheckoutTest> /home/aschiffo/Documents/Andrea/Acme/acme-qa-automation/vendor/php-webdriver/webdriver/lib/Remote/RemoteWebDriver.php:211
Acme\QAAutomation\CheckoutTest> /home/aschiffo/Documents/Andrea/Acme/acme-qa-automation/vendor/php-webdriver/webdriver/lib/WebDriverExpectedCondition.php:176
Acme\QAAutomation\CheckoutTest> /home/aschiffo/Documents/Andrea/Acme/acme-qa-automation/vendor/php-webdriver/webdriver/lib/WebDriverWait.php:54
Acme\QAAutomation\CheckoutTest> /home/aschiffo/Documents/Andrea/Acme/acme-qa-automation/vendor/lmc/steward/src/Test/SyntaxSugarTrait.php:320
Acme\QAAutomation\CheckoutTest> /home/aschiffo/Documents/Andrea/Acme/acme-qa-automation/vendor/lmc/steward/src/Test/SyntaxSugarTrait.php:48
Acme\QAAutomation\CheckoutTest> /home/aschiffo/Documents/Andrea/Acme/acme-qa-automation/tests/Pages/WWBasePage.php:54
Acme\QAAutomation\CheckoutTest> /home/aschiffo/Documents/Andrea/Acme/acme-qa-automation/tests/CheckoutTest.php:30
Acme\QAAutomation\CheckoutTest> 
Acme\QAAutomation\CheckoutTest> ERRORS!
Acme\QAAutomation\CheckoutTest> Tests: 1, Assertions: 0, Errors: 1.
Acme\QAAutomation\CheckoutTest> 
[2021-11-29 00:40:45] Finished execution of testcase "Acme\QAAutomation\CheckoutTest" (result: failed, time: 4.7 sec)
[2021-11-29 00:40:45] Waiting (running: 0, queued: 0, done: 1 [failed: 1])
[2021-11-29 00:40:45] All testcases done in 4.8 seconds

 [ERROR] Testcases executed: 1 (failed: 1)`  
andreaschiffo commented 2 years ago

I think this is related to https://github.com/php-webdriver/php-webdriver/issues/944

andreaschiffo commented 2 years ago

Resolved updating to latest chromedriver

andreaschiffo commented 2 years ago

I can confirm this happened right after updating chrome to the latest version. Updating chromedriver to the latest resolves. https://chromedriver.chromium.org/downloads