site.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. var brower = require('casper').create({
  2. pageSettings : {
  3. webSecurityEnabled : false
  4. },
  5. logLevel : "debug",// 日志等级
  6. verbose : true, // 记录日志到控制台
  7. onWaitTimeout : function() {
  8. this.echo('** Wait-TimeOut **');
  9. },
  10. onStepTimeout : function() {
  11. this.echo('** Step-TimeOut **');
  12. }
  13. });
  14. var indexUrl = 'https://www.mouser.cn/MyMouser/MouserLogin.aspx';
  15. // 每次操作间隔时间
  16. var time_pre_step = 10000;
  17. // 1. 登录页面
  18. brower.start(indexUrl, function() {
  19. this.capture('login.png');
  20. });
  21. brower.then(function() {
  22. this.wait(100000, function() {
  23. this.echo('waited');
  24. });
  25. });
  26. brower.then(function() {
  27. this.fill('#ctl00_ContentMain_login_login_panelLogin', {
  28. "ctl00$ContentMain$login$login$UserName" : "_mouser_",
  29. "ctl00$ContentMain$login$login$Password" : "select123"
  30. }, false);
  31. this.capture('login.png');
  32. });
  33. brower.then(function(){
  34. this.click('#ctl00_ContentMain_login_login_LoginButton');
  35. });
  36. brower.then(function() {
  37. this.wait(time_pre_step, function() {
  38. this.echo('waited');
  39. });
  40. });
  41. brower.then(function() {
  42. if (this.getCurrentUrl() == indexUrl)
  43. this.echo('can not login');
  44. else
  45. this.capture('afterlogin.png');
  46. });
  47. // 2.打开特定界面
  48. // brower
  49. // .thenOpen('http://www.mouser.cn/Semiconductors/Discrete-Semiconductors/Discrete-Semiconductor-Modules/_/N-awv5t/');
  50. //
  51. // brower.then(function() {
  52. // this.capture('3.png');
  53. // });
  54. // 3.退出
  55. brower.then(function() {
  56. this.exit();
  57. });
  58. // 将前面定义的步骤 跑起来
  59. brower.run();