Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
166 views
in Technique[技术] by (71.8m points)

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

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 I want to do.

So I'll login browser window A, then login to browser window B, then back in browser window A I'd input the chat message, call click() on the send button, and then back in browser B I'd wait for the message to appear. Then write a message, and go back to browser A to make sure it arrives.

I found this discussion on parallel browsing, which turns out to be serial. Serial is fine for me, but it appears doing more than one action in each browser is going to get very messy. It'd 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've not actually tested that will work; I started writing it that way and thought there must be a better way?!)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...