0

I have protractor selenium tests running in a docker container. I have to test an insecure website. For one of the functions where API call is made to get some data back from backed chrome returns status code 400. I have added the following in my protractor config file:

chrome args ("--headless", "--no-sandbox", "--disable-dev-shm-usage")

directConnection: true,
disableChecks: true

Capabilities:

acceptInsecureCerts: true
acceptSslCerts: true

I have also added following in my .env file:

NODE_TLS_REJECT_UNAUTHORIZED=0

Below are the network logs I`ve gotten:

{
  method: 'Network.responseReceived',
  params: {
    frameId: '721A00F872D1255AA1DAE58D2DF5D75E',
    loaderId: '70EAE0F82B0AB6BDE6489BC26D77DA34',
    requestId: '117.239',
    response: {
      connectionId: 309,
      connectionReused: true,
      encodedDataLength: 123,
      fromDiskCache: false,
      fromPrefetchCache: false,
      fromServiceWorker: false,
      headers: [Object],
      mimeType: 'application/problem+json',
      protocol: 'h2',
      remoteIPAddress: 'remote ip',
      remotePort: 443,
      securityDetails: [Object],
      securityState: 'insecure',
      status: 400,
      statusText: '',
      timing: [Object],
      url: 'https://api call link'
    },
    timestamp: 15184.562748,
    type: 'XHR'
  }
}
{
  method: 'Network.dataReceived',
  params: {
    dataLength: 185,
    encodedDataLength: 0,
    requestId: '117.239',
    timestamp: 15184.562954
  }
}
{
  method: 'Network.dataReceived',
  params: {
    dataLength: 0,
    encodedDataLength: 203,
    requestId: '117.239',
    timestamp: 15184.563471
  }
}
{
  method: 'Network.loadingFinished',
  params: {
    encodedDataLength: 326,
    requestId: '117.239',
    shouldReportCorbBlocking: false,
    timestamp: 15184.552973
  }
}

To be noted, that when run locally outside of docker container this function works as expected and API call returns with status code: 200

P.S. Running it in Zelenium has the same results as locally in docker.

EDIT: Console logs contain follwoing error:

Failed to load resource: the server responded with a status of 400 ()
Tralots
  • 63
  • 1
  • 5
  • Update the question with the error stack trace. – undetected Selenium Feb 21 '20 at 10:58
  • There is no error stack trace. From backed everything is fine, and API call returns necesarry data, but this does not get back to docker container. – Tralots Feb 21 '20 at 11:33
  • @DebanjanB Sorry, there was an error stack trace, if you meant from console logs. It is "Failed to load resource: the server responded with a status of 400 ()" Also, your provided link did not help me, as all of the resources have been loaded already. – Tralots Feb 21 '20 at 12:46

1 Answers1

0

status: 400

status: 400 implies 400 Bad Request and HTTP 400 Bad Request response status code indicates that the server cannot or will not process the request due to something that is perceived to be a client error e.g. a malformed request syntax, invalid request message framing, or deceptive request routing.


Some information interms of your code trials, the relevant HTML and the complete error stack trace would have helped us to analyze the issue in a better way. However, as per the discussion in Failed to load resource: the server responded with a status of 400 () it seems the HTML DOM of the webpage contains AJAX and JavaScript enabled elements.

So while you invoke get() method, before interacting with any of the elements on the particular webpage, you need to induce WebDriverWait for the desired elements to be clickable which will ensure that:

  • The associated JavaScript and AJAX Calls have completed rendering the DOM Tree.
  • The desired elements are enabled and visible to recognize click events propagated through Selenium.

References

You can find a couple of relevant discussions in:


tl; dr

Failed to load resource: the server responded with a status of 429 (Too Many Requests) and 404 (Not Found) with ChromeDriver Chrome through Selenium

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352