How to test two interacting browsers (for example, a chat application)

I want to check the interaction between two users by exchanging data through a remote server using CasperJS. My application is not a chat application, but it is an easy way to illustrate what I want to do.

So, I will take browser window A, then go into browser window B, then go back to the browser window. I would enter a chat message, call click() on the submit button, and then back to the browser B I'd wait for the message to appear. Then write a message and return to browser A to make sure it arrives.

I found this discussion of parallel viewing , which turns out to be serial. Serial is great for me, but it seems that more than one action in each browser will be very dirty. It will be something like this:

 A.start(...); A.then(...); A.then(...); B.start(...); B.when(...); A.run(function(){ B.run(function(){ A.start(...); A.then(...); A.run(function(){ B.start(...); B.run(function(){ //and so on }); }); }); }); 

(I didn't really test this, I started writing it that way and thought there should be a better way?)

+4
casperjs
source share
2 answers

and each of them runs asynchronously from the command line

+ 1

I would do this:

Two scenarios:

  • script A with login
  • script B with login name

Then the script The first step (after logging in): record in the chat. Script B first step: waiting for the text and then sending its response. Script Second step: waiting for B response, etc.

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

There is only one delicate point: wait until both pages are rendered, or log in at the same time (approximately), because if one of them freezes a little, you can get time to rush ... So maybe increase waitTimeout ; to be more secure. (although a default wait time of 5 seconds should be enough for me).

You can also use an external file to synchronize it, but I don’t see how this can be useful, because you still have to wait until the data is updated in this file.

So this solution is asynchronous, but it works.

+3
source share

This will not work due to the nature of the step / planning for casperjs. See Also Running multiple instances of casperjs .

In the sample code, instance B starts only after completion of A , since execution begins with a call to run .

The easiest way would be to write two separate casperjs scripts (or one script, but it is called with different data for two parties), and each of them is run asynchronously from the command line. On linux, I would use nohup ... & for this.


As for the specific stages of testing. I think it’s easier for you to allow the application to handle the events necessary to synchronize the two casperjs clients. If this is a chat application and you want two hour chats to chat, you should write a dialogue in advance, which includes at what stage the client says what.

Then you can synchronize clients using waitForText :

  • A sends fixed / known text, while B expects this fixed text to appear.
  • B receives this fixed text, and A is in the next step and is waiting for a response from B (also known text).
  • B sends the next fixed text, and A is still waiting

Of course, you will need to play with expectation expectations.

+2
source share

All Articles