How to test two interacting browsers (e.g. chat app)

后端 未结 2 1439
攒了一身酷
攒了一身酷 2020-12-11 08:23

I want to test the interaction between two users, communicating through a remote server, using CasperJS. My app is not a chat app, but that is an easy way to illustrate what

相关标签:
2条回答
  • 2020-12-11 09:17

    This will not work because of the step/scheduling nature of casperjs. See also Running multiple instances of casperjs.

    In your code example the B instance is only started when A is finished, because the execution begins with the call to run.

    The easiest would be to write two separate casperjs scripts (or one script, but invoked with different data for the two sides) and let each of them run asynchronously from the commandline. On linux I would use nohup ... & for this.


    As for the specific test steps. I think it is easier to let your application handle the events that are needed for the synchronization of the two casperjs clients. If it is a chat app and you want to let the two caspers chat, you would write a dialog beforehand, which includes at what step a client says what.

    You can then synchronize the clients using waitForText:

    1. A sends some fixed/known text while B waits for this fixed text to appear
    2. B receives this fixed text while A is in the next step and waits for B's response (also known text)
    3. B sends the next fixed text and A is still waiting

    Of course you would need to play around with wait timeouts.

    0 讨论(0)
  • 2020-12-11 09:18

    and let each of them run asynchronously from the commandline

    +1

    I would do it that way :

    Two scripts :

    • script A with A login
    • script B with B login

    Then script A first step (after login) : writing in the chat. Script B first step : waiting for A text then sending its answer. Script A second step : waiting for B answer etc...

    You launch these two scripts in parallel using node (child process) and they will interact with the wait() statements.

    There is just one delicate point : wait for the two pages to be rendered -or to login- at the same time (approximatively), because if one of them freeze a little, you could get the timeouterror... So maybe increase the waitTimeout; to be safer. (though for me the 5sec default timeout should be sufficient).

    You could also use an external file to 'synchronize' it, but I don't see how it could be helpful, because you would have to wait for the data to be updated in this file anyway.

    So this solution it's asynchronous, but it works.

    0 讨论(0)
提交回复
热议问题