Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var genie = require('genie').create({ xpathVersion: '2.0' });
  2.  
  3. var x = require('casper').selectXPath;
  4. var ex = genie.extendedXpath(x);
  5.  
  6. var blacklist = ['.css', '.png', '.gif', '.jpeg', 'google-analytics', 'yandex'];
  7.  
  8. var USERNAME = "mbaltova@ceicdata.com";
  9. var PASSWORD = "ceicdata";
  10.  
  11. function commonSteps() {
  12.  
  13.         this.wait(5000);
  14.         this.waitForSelector(ex("//input[contains(@value,'Login')]"),function success(){
  15.         this.sendKeys(ex("//input[contains(@name,'Login')]"), USERNAME);
  16.         this.wait(2000);
  17.         this.sendKeys(ex("//input[contains(@name,'Password')]"), PASSWORD);
  18.         this.wait(2000);
  19.         this.evaluate(function(){
  20.             $(document).xpath("//input[contains(@value,'Login')]").click().change()
  21.         })
  22.         },function fail() {
  23.             console.log("Already log in")
  24.         });
  25.         this.wait(2000);
  26.         this.waitAndClick(ex("//a[contains(text(),'MISCAREA')]/following::a[contains(text(),'FORTA')]"));
  27.         this.waitAndClick(ex(parameters.fileName));
  28.  
  29. }
  30.  
  31. var files1 = genie.files();
  32.  
  33. files1.blacklist(blacklist)
  34.     .retry(5)
  35.     .add({
  36.         'file1.html': {
  37.             'fileName': "//a[contains(text(),'AMG157H')]"
  38.         },
  39.         'file4.html': {
  40.             'fileName': "//a[contains(text(),'FOM105E')]"
  41.         },
  42.         'file5.html': {
  43.             'fileName': "//a[contains(text(),'AMG155A')]"
  44.         },
  45.         'file12.html': {
  46.             'fileName': "//a[contains(text(),'FOM103D')]"
  47.         },
  48.         'file13.html': {
  49.             'fileName': "//a[contains(text(),'FOM111C')]"
  50.         }
  51.     })
  52.  
  53.     .steps(function (parameters) {
  54.         this.thenOpen("http://statistici.insse.ro/shop/?lang=ro");
  55. //        this.then(function(){
  56. //            commonSteps.call(this);
  57. //        })
  58.         commonSteps.call(this);
  59.         this.then(function(){
  60.             var html_url = this.getElementsAttribute(ex("//a[starts-with(@onclick,'selectAllInSelect')]"), "href");
  61.             console.log("================ " +html_url.length)
  62.             this.evaluate(function(){
  63.                 selectAllInSelect("pos1");
  64.                 selectAllInSelect("pos2");
  65.                 selectAllInSelect("pos3");
  66.             });
  67.             if (html_url==4){
  68.                 this.evaluate(function(){
  69.                     selectAllInSelect("pos4");
  70.                 });
  71.             }
  72.             else if (html_url==5){
  73.                 this.evaluate(function(){
  74.                     selectAllInSelect("pos4");
  75.                     selectAllInSelect("pos5");
  76.                 });
  77.             }
  78.         });
  79.         this.wait(2000);
  80.         this.waitAndClick(ex("//input[contains(@value,'Cauta')]"))
  81.         this.wait(5000);
  82.     });
  83.  
  84. var files2 = genie.files();
  85.  
  86. files2.blacklist(blacklist)
  87.     .retry(5)
  88.     .add({
  89.         'file15.html': {
  90.             'fileName': "//a[contains(text(),'FOM104F')]"
  91.         },
  92.         'file16.html': {
  93.             'fileName': "//a[contains(text(),'FOM105F')]"
  94.         }
  95.     })
  96.  
  97.     .steps(function (parameters) {
  98.         this.thenOpen("http://statistici.insse.ro/shop/?lang=ro");
  99.         commonSteps.call(this);
  100. //        this.wait(5000);
  101. //        this.waitForSelector(ex("//input[contains(@value,'Login')]"),function success(){
  102. //                this.sendKeys(ex("//input[contains(@name,'Login')]"), USERNAME);
  103. //                this.wait(2000);
  104. //                this.sendKeys(ex("//input[contains(@name,'Password')]"), PASSWORD);
  105. //                this.wait(2000);
  106. //                this.then(function(){
  107. //                    this.capture("downloads/input.png")
  108. //                })
  109. //                this.evaluate(function(){
  110. //                    $(document).xpath("//input[contains(@value,'Login')]").click().change()
  111. //                })
  112. //            },
  113. //            function fail() {
  114. //                console.log("Already log in")
  115. //         });
  116. //        this.wait(2000);
  117. //        this.waitAndClick(ex("//a[contains(text(),'MISCAREA')]/following::a[contains(text(),'FORTA')]"));
  118. //        this.waitAndClick(ex(parameters.fileName));
  119.         this.wait(5000);
  120.         this.then(function(){
  121.             this.evaluate(function(){
  122.                 selectAllInSelect("pos1");
  123.                 selectAllInSelect("pos4");
  124.             });
  125.         });
  126.         this.wait(2000);
  127.         this.waitAndClick(ex("//input[contains(@value,'Cauta')]"))
  128.         this.wait(5000);
  129.     });
  130.  
  131. var files3 = genie.files();
  132.  
  133. files3.blacklist(blacklist)
  134.     .retry(5)
  135.     .add({
  136.         'file6.html': {
  137.             'fileName': "//a[contains(text(),'AMG155B')]"
  138.         },
  139.         'file8.html': {
  140.             'fileName': "//a[contains(text(),'AMG156B')]"
  141.         }
  142.     })
  143.  
  144.     .steps(function (parameters) {
  145.         this.thenOpen("http://statistici.insse.ro/shop/?lang=ro");
  146.         this.wait(5000);
  147.         this.waitForSelector(ex("//input[contains(@value,'Login')]"),function success(){
  148.                 this.sendKeys(ex("//input[contains(@name,'Login')]"), USERNAME);
  149.                 this.wait(2000);
  150.                 this.sendKeys(ex("//input[contains(@name,'Password')]"), PASSWORD);
  151.                 this.wait(2000);
  152.                 this.then(function(){
  153.                     this.capture("downloads/input.png")
  154.                 })
  155.                 this.evaluate(function(){
  156.                     $(document).xpath("//input[contains(@value,'Login')]").click().change()
  157.                 })
  158.             },
  159.             function fail() {
  160.                 console.log("Already log in")
  161.          });
  162.         this.wait(2000);
  163.         this.waitAndClick(ex("//a[contains(text(),'MISCAREA')]/following::a[contains(text(),'FORTA')]"));
  164.         this.waitAndClick(ex(parameters.fileName));
  165.         this.wait(2000);
  166.         this.then(function(){
  167.             this.evaluate(function(){
  168.                 $(document).xpath("//option[contains(text(),'Total ')]").attr('selected', false)
  169.                 $(document).xpath("//option[contains(text(),'Urban')]").attr('selected', true)
  170.                 $(document).xpath("//option[contains(text(),'Rural')]").attr('selected', true)
  171.                 selectAllInSelect("pos3");
  172.             });
  173.         });
  174.         this.wait(2000);
  175.         this.waitAndClick(ex("//input[contains(@value,'Cauta')]"))
  176.         this.wait(5000);
  177.     });
  178.  
  179. genie.run(files1);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement