Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't fail element command in IE #3874

Merged
merged 1 commit into from Apr 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 10 additions & 5 deletions packages/webdriver/src/utils.js
Expand Up @@ -28,11 +28,16 @@ export function isSuccessfulResponse (statusCode, body) {
/**
* ignore failing element request to enable lazy loading capability
*/
if (body.status && body.status === 7 && body.value && body.value.message &&
(body.value.message.toLowerCase().startsWith('no such element') ||
//Appium
body.value.message ===
'An element could not be located on the page using the given search parameters.')) {
if (
body.status === 7 && body.value && body.value.message &&
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is body.status always defined? Any reason for removing the first if check on that.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if status is undefined the assertion will fail, no need to check whether status exists or not

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI:

on Edge and Safari the response body does not have a 'status':

{
    value: {
        stacktrace: 'org.openqa.selenium.NoSuchElementException: The specified element was not found in the current fra
        me or window.(WARNING: The server did not provide any stacktrace information)\ nCommand duration or timeout: 0 millis
        econds\ nFor documentation on this error,
        please visit: http: //seleniumhq.org/exceptions/no_such_element.html\nBuild i
            nfo: version: \'3.14.0\', revision: \'aacccce0\', time: \'2018-08-02T20:13:22.693Z\'\nSystem info: host: \'SAUCE-WIN1
        0\ ', ip: \'172.20.59.68\', os.name: \'Windows 10\', os.arch: \'amd64\', os.version: \'10.0\', java.version: \'1.8.0_1
        31\ '\nDriver info: driver.version: unknown\r\n\tat sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Meth
        od)\ r\ n\ tat sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)\ r\ n\ tat sun.reflect.DelegatingConst
    ructorAccessorImpl.newInstance(Unknown Source)\ r\ n\ tat java.lang.reflect.Constructor.newInstance(Unknown Source)\ r\ n\
    tat org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java: 214)\ r\ n\ tat org.openqa.selenium.remote
    .ErrorHandler.throwIfResponseFailed(ErrorHandler.java: 166)\ r\ n\ tat org.openqa.selenium.remote.http.JsonHttpResponseCo
    dec.reconstructValue(JsonHttpResponseCodec.java: 40)\ r\ n\ tat org.openqa.selenium.remote.http.AbstractHttpResponseCodec
    .decode(AbstractHttpResponseCodec.java: 80)\ r\ n\ tat org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(A bstractHttpResponseCodec.java: 44)\ r\ n\ tat org.openqa.selenium.remote.server.ProtocolConverter.handle(ProtocolConverte r.java: 87)\ r\ n\ tat org.openqa.selenium.remote.server.RemoteSession.execute(RemoteSession.java: 127)\ r\ n\ tat org.openqa
    .selenium.remote.server.WebDriverServlet.lambda$handle$3(WebDriverServlet.java: 250)\ r\ n\ tat java.util.concurrent.Exec
    utors$RunnableAdapter.call(Unknown Source)\ r\ n\ tat java.util.concurrent.FutureTask.run(Unknown Source)\ r\ n\ tat java.u
    til.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)\ r\ n\ tat java.util.concurrent.ThreadPoolExecutor$Worker.ru
    n(Unknown Source)\ r\ n\ tat java.lang.Thread.run(Unknown Source)\ r\ n ',
    message: 'The specified element was not found in the current frame or window. (WARNING: The server did not prov
    ide any stacktrace information)\ nCommand duration or timeout: 0 milliseconds\ nFor documentation on this error, please
visit: http: //seleniumhq.org/exceptions/no_such_element.html\nBuild info: version: \'3.14.0\', revision: \'aacccce0\
    ', time: \'2018-08-02T20:13:22.693Z\'\nSystem info: host: \'SAUCE-WIN10\', ip: \'172.20.59.68\', os.name: \'Windows 1
0\ ', os.arch: \'amd64\', os.version: \'10.0\', java.version: \'1.8.0_131\'\nDriver info: driver.version: unknown',
    error: 'no such element'
}
}

so we may need to do something like:

  /**
   * ignore failing element request to enable lazy loading capability
   */
  if (
    body.status === 7 && body.value && body.value.message &&
    // body.value && body.value.message &&
    (
      body.value.message.toLowerCase().startsWith('no such element') ||
      // Appium
      body.value.message === 'An element could not be located on the page using the given search parameters.' ||
      // Internet Explorter
      body.value.message.toLowerCase().startsWith('unable to find element')
    )
  ) {
    console.log(body)
    return true
  }
  else if (body.value && body.value.message && 
    // Edge
    (
    body.value.message.toLowerCase().startsWith('the specified element was not found') ||
    // Safari
    body.value.message.toLowerCase().startsWith('an element could not be located on the page')
    )
  ) {
    console.log(body)
    return true
  }

but not sure if that will break when an actual element is not there that we expect to bet etc?

(
body.value.message.toLowerCase().startsWith('no such element') ||
// Appium
body.value.message === 'An element could not be located on the page using the given search parameters.' ||
// Internet Explorter
body.value.message.toLowerCase().startsWith('unable to find element')
)
) {
return true
}

Expand Down
4 changes: 4 additions & 0 deletions packages/webdriver/tests/utils.test.js
Expand Up @@ -27,6 +27,10 @@ describe('utils', () => {
undefined,
{ status: 7, value: { message: 'no such element: foobar' } }
)).toBe(true)
expect(isSuccessfulResponse(
200,
{ value: { message: 'Unable to find element with xpath == //foobar' } }
)).toBe(true)
})

it('isValidParameter', () => {
Expand Down