Skip to content

detect events fired on document load #1654

@raquelhortab

Description

@raquelhortab

Hi,
I am trying to detect events / function calls (more specifically an alert) that is fired directly when the document loads (it is placed directly on the script tag, not binded by any event listener:

<script language="JavaScript">
    alert("CODELEARN");  
</script>

but it does not seem to work

I got this on the preload script

window.alert = function(message) {
  send('page', 'alert', message)
}

and

beforeEach(() => {
  nightmare.on('page', (type, message) => {
  if (type == 'alert'){
     alert_messages.push(message);
  }
}

I then check in the test whether I got the expected alert_messages.

This works when the alert is triggered by a click or some other event but not with the example above.

Does anyone know a way to check this other than, for example, duplicating the script tag during the test?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions