File upload with invalid path doesnt fail test - karate

Below is the sample code which is suppoe to fail as the file path is invalid.
Scenario: test input
* driver "https://fineuploader.com/demos.html"
* print "performing file upload"
* input("[name='qqfile']","in valid path")
* print "done file upload"
I see the error on the console
12:03:27.773 [chromedriver_1584979407695] WARN com.intuit.karate.shell.Command - exit code was non-zero: 1 - [/Users/vxt82/Apps/chromedriver, --port=9515, --user-data-dir=/Users/vxt82/repo/bitbucket/xtaf-unified-framwork/target/chromedriver_1584979407695]
12:03:31.648 [ForkJoinPool-1-worker-3] INFO com.intuit.karate - [print] performing file upload
12:03:31.711 [ForkJoinPool-1-worker-3] WARN com.intuit.karate - http response code: 404, response: {"value":{"stacktrace":"0 chromedriver 0x0000000108d72e99 chromedriver + 3747481\n1 chromedriver 0x0000000108d074d3 chromedriver + 3306707\n2 chromedriver 0x0000000108a96fef chromedriver + 749551\n3 chromedriver 0x0000000108a03128 chromedriver + 143656\n4 chromedriver .... 0x00007fff767a040d thread_start + 13\n","error":"no such element","message":"no such element: Element_id length is invalid\n (Session info: chrome=78.0.3904.50)"}}, request: [method: POST, responseTime: 4.207512, body: {"text":"in valid path"}]
12:03:31.718 [ForkJoinPool-1-worker-3] INFO com.intuit.karate - [print] done file upload
I was expecting test to fail but surprisingly it's passing. I looked into documentation but did not find anything specific to this scenarios.
Is this is expected behaviour, or I am doing some mistake in understanding?

Karate's file upload (input()) works similar to Selenium WebDrivers sendkeys(). It just does setting the text without validating is it file type and a path, Which I think is ok and as per design. May be as suggested Peter assertion can help at some extent to confirm file upload works.

Related

Karate - screenshot method throws a 'failed to get reply' exception

I'm using Karate 1.1.0 and running tests that combine both driver and robot instances. The tests are passing locally, but fail intermittently when executed through Jenkins with the following error:
js failed:
>>>>
01: delay(20000).screenshot()
<<<<
org.graalvm.polyglot.PolyglotException: failed to get reply for: [id: 2052, sessionId: D9DA8BB2B46A340A64D04C96EDFC9231, method: Page.captureScreenshot]
- com.intuit.karate.driver.DevToolsDriver.sendAndWait(DevToolsDriver.java:161)
- com.intuit.karate.driver.DevToolsMessage.send(DevToolsMessage.java:213)
- com.intuit.karate.driver.DevToolsMessage.send(DevToolsMessage.java:209)
- com.intuit.karate.driver.DevToolsDriver.screenshot(DevToolsDriver.java:823)
- com.intuit.karate.driver.DevToolsDriver.screenshot(DevToolsDriver.java:801)
- com.intuit.karate.driver.Driver.screenshot(Driver.java:119)
- <js>.:program(Unnamed:1)
In this particular example screenshot() call is 'ambiguous', but I've also tried it like so driver.screenshot(), which didn't make a difference:
js failed:
>>>>
01: driver.screenshot()
<<<<
org.graalvm.polyglot.PolyglotException: failed to get reply for: [id: 1832, sessionId: F7B7D4210527DE4B28FD2B85ACF66638, method: Page.captureScreenshot]
- com.intuit.karate.driver.DevToolsDriver.sendAndWait(DevToolsDriver.java:161)
- com.intuit.karate.driver.DevToolsMessage.send(DevToolsMessage.java:213)
- com.intuit.karate.driver.DevToolsMessage.send(DevToolsMessage.java:209)
- com.intuit.karate.driver.DevToolsDriver.screenshot(DevToolsDriver.java:823)
- com.intuit.karate.driver.DevToolsDriver.screenshot(DevToolsDriver.java:801)
- com.intuit.karate.driver.Driver.screenshot(Driver.java:119)
- <js>.:program(Unnamed:1)
Chrome is not running in headless mode and in some runs screenshots get captured successfully. Some other things I tried are:
changed the window size (addOptions: ['--window-size=1920,1080']);
used screenshotFull();
increased timeout (timeout: 90000);
increased Java heap space.
Any help will be greatly appreciated.

Selenium Headless Firefox - Very Slow

I am trying to fetch some web data using Selenium to run Firefox in headless mode in a Python3 script. I am running the script on Debian.
The code works fine, but is very very slow. Half a minute to get the title of the webpage. I need to use this in a production environment and it won't work if it's that slow. I am new to Selenium so it may be a basic mistake I am making...
import selenium
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.firefox.options import Options
import time
from decimal import Decimal
start_time = time.time()
fireFoxOptions = webdriver.FirefoxOptions()
fireFoxOptions.set_headless()
browser = webdriver.Firefox(firefox_options=fireFoxOptions)
fetchUrl = "https://www.amazon.com/CakCity-Military-Waterproof-Luminous-Stopwatch/dp/B018HTGSN8/ref=sxin_1_ac_d_rm?ac_md=0-0-d2F0Y2g%3D-ac_d_rm&keywords=watch&pd_rd_i=B018HTGSN8&pd_rd_r=ad451c0c-abfe-4436-bee4-d11f9e1dbb1e&pd_rd_w=J9Zl5&pd_rd_wg=AqMuw&pf_rd_p=ed481207-4bea-4e19-bbad-73ed40fdc292&pf_rd_r=A7B9299YFYD1G0JZ81YH&psc=1&qid=1573502062"
browser.get( fetchUrl )
print ( browser.title )
executionTime = round(time.time() - start_time, 2)
print( "- execution time [" + str( executionTime ) + "]" )
browser.close()
browser.quit()
Execution time varies from 20s to 30s
Debian 9.4 (Stretch)
Firefox 70.0.1
Geckodriver 0.26.0
Selenium 3.141.0
Python 3.5.3
I have tried limiting the libraries I import, and it has no change.
I have tested several different websites, such as just google.com, and the response time is the same. I can load these sites within seconds manually through any browser, so I would think headless mode would be faster. The script does not throw any errors.
Gecko log
1573530232430 mozrunner::runner
INFO Running command: "/usr/bin/firefox" "-marionette" "-headless" "-foreground" "-no-remote" "-profile" "/tmp/rust_mozprofileKfYEBK"
*** You are running in headless mode.
1573530233337 addons.webextension.screenshots#mozilla.org
WARN Loading extension 'screenshots#mozilla.org': Reading manifest: Invalid extension permission: mozillaAddons
1573530233337
addons.webextension.screenshots#mozilla.org
WARN Loading extension 'screenshots#mozilla.org': Reading manifest: Invalid extension permission: telemetry
1573530233338
addons.webextension.screenshots#mozilla.org
WARN Loading extension 'screenshots#mozilla.org': Reading manifest: Invalid extension permission: resource://pdf.js/
1573530233338
addons.webextension.screenshots#mozilla.org
WARN Loading extension 'screenshots#mozilla.org': Reading manifest: Invalid extension permission: about:reader*
1573530237793 Marionette
INFO Listening on port 36801
1573530237852 Marionette
WARN TLS certificate errors will be ignored for this session
[Parent 1707, Gecko_IOThread]
WARNING: pipe error: Broken pipe: file /builds/worker/workspace/build/src/ipc/chromium/src/chrome/common/ipc_channel_posix.cc, line 728
1573530254051
Marionette
INFO Stopped listening on port 36801
I researched all of the warnings listed above with mixed ideas on solutions.
The "pipe error" does not always show up in the logs, seems random. Also unusual as it says chromium, but I am using Firefox...
I am unclear on the permission errors even after reading up on them, some say to just disregard them as not important.
Any suggestions?
Thanks

RIDE WebDriverException: Message: session not created exception from unknown error

I was able to run robot framework tests on Google Chrome using RIDE without issue. However just today I tried to run tests that had run properly before and now I'm getting the following error:
Starting test: Bbh-Robot.Test Cases.Search.Search 01 - Basics.Search for Toronto
20161108 13:48:44.163 : INFO : Opening browser 'googlechrome' to base url 'https://www.google.com/'
20161108 13:48:50.591 : FAIL : No browser is open
20161108 13:48:50.592 : WARN : Keyword 'Capture Page Screenshot' could not be run on failure: No browser is open
20161108 13:48:50.596 : FAIL :
WebDriverException: Message: session not created exception
from unknown error: Runtime.executionContextCreated has invalid 'context': {"auxData":{"frameId":"7332.1","isDefault":true},"id":1,"name":"","origin":"://"}
(Session info: chrome=54.0.2840.87)
(Driver info: chromedriver=2.22.397933 (1cab651507b88dec79b2b2a22d1943c01833cc1b),platform=Windows NT 6.1.7601 SP1 x86_64)
Ending test: Bbh-Robot.Test Cases.Search.Search 01 - Basics.Search for Toronto
I thought it might be an issue with chromedriver so I updated to the most recent version (and made sure the executable was included in my Path variable)
https://chromedriver.storage.googleapis.com/index.html?path=2.25/
But it still thinks I'm using 2.22 for some reason and I'm not sure where to proceed. Is there something I can do with RIDE specifically?
There is nothing you could do with RIDE (other than a clean restart).
This is a problem with PATH setting that somehow is finding first the old version of chromedriver.
(There could be also a running instance of the old chromedriver.)

Selenium IDE fails to open a test suite (no file open dialog)

I am not able to access the file open dialog in Selenium IDE 2.9.1 (Firefox 48.0, Win 10). File > Open results in this error message:
There was an unexpected error. Msg: NS_ERROR_FILE_UNRECOGNIZED_PATH: Component returned failure code: 0x80520001 (NS_ERROR_FILE_UNRECOGNIZED_PATH) [nsILocalFile.initWithPath]
Url: chrome://selenium-ide/content/file-utils.js, line: 32
FileUtils.getFile#chrome://selenium-ide/content/file-utils.js:32:5
showFilePicker#chrome://selenium-ide/content/tools.js:102:31
Application.prototype.loadTestCaseWithNewSuite#chrome://selenium-ide/content/application.js:259:20
Editor.prototype.loadRecentTestCase#chrome://selenium-ide/content/editor.js:489:5
Editor.controller.doCommand#chrome://selenium-ide/content/editor.js:366:9
goDoCommand#chrome://global/content/globalOverlay.js:100:7
oncommand#chrome://selenium-ide/content/selenium-ide.xul:1:1
File > Open Test Suite results in a shorter error:
error loading test suite: [Exception... "Component returned failure code: 0x80520001 (NS_ERROR_FILE_UNRECOGNIZED_PATH) [nsILocalFile.initWithPath]" nsresult: "0x80520001 (NS_ERROR_FILE_UNRECOGNIZED_PATH)" location: "JS frame :: chrome://selenium-ide/content/file-utils.js :: FileUtils.getFile :: line 32" data: no]
Does anyone have a clue what's wrong here?
In a new Firefox Tab type in about:config, and once in there search for: extensions.selenium-‌​ide.testCaseDirectory and extensions.selenium-‌​ide.testSuiteDirector‌​y Check the file path there and make sure it is a valid one. They control the default location you start at when opening files, could be an issue with that.

WebDriver: ChromeDriver attempting to reach http://localhost/session on initialization and failing

The full error message is:
Test(s) failed. OpenQA.Selenium.WebDriverException : The HTTP request to the remote WebDriver server for URL http://localhost:59662/session timed out after 60 seconds.
----> System.Net.WebException : The operation has timed out
The line in my code where this is happening simply instances a new ChromeDriver instance:
CurrentDriver = new ChromeDriver(section["chromedriverfolder"]);
So my question is... why does a new ChromeDriver invokes the /session URL, and what could be causing it to fail?
I experienced this same error using Selenium.WebDriver.ChromeDriver v2.22 and Chrome v52.0.2743.116 m running on TeamCity 9.x. I was able to fix the problem by rolling back the version of Chrome running on the TeamCity agents to v51.
When examining the agent executing the test, there is a popup with error: "Chrome Automation extension has crashed. Click this balloon to reload the extension."
It seems like a bug with the latest version of Chrome and Selenium.WebDriver.ChromeDriver, but as of yet this is the only lead I've found
EDIT: The link to the ChromeDriver issue
EDIT2: The link to the resolution
I have the answer where ChromeDriver invokes the /session URL, but not to the second part why it is timing out. Please see if it can provide some lead to the debug process to find out the failure :
When we call new ChromeDriver()
It creates RemoteWebDriver in the constructor :
super(new DriverCommandExecutor(service), capabilities);
which ultimately goes to :
public RemoteWebDriver(CommandExecutor executor, Capabilities desiredCapabilities,
Capabilities requiredCapabilities) {
In this method we do startClient which basically does nothing in this particular case
After startClient we do :
startSession(desiredCapabilities, requiredCapabilities);
This method issues the request /session in the following line :
Response response = execute(DriverCommand.NEW_SESSION, parameters);
The DriverCommand.NEW_SESSION is set as newSession which is mapped to post /session in the Command Codec
defineCommand(NEW_SESSION, post("/session"));