Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2018
124
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.         commonSteps();
  56.         this.then(function(){
  57.             this.evaluate(function(){
  58.                 commonSteps();
  59.             })
  60.  
  61.         })
  62.         this.then(function(){
  63.             var html_url = this.getElementsAttribute(ex("//a[starts-with(@onclick,'selectAllInSelect')]"), "href");
  64.             console.log("================ " +html_url.length)
  65.             this.evaluate(function(){
  66.                 selectAllInSelect("pos1");
  67.                 selectAllInSelect("pos2");
  68.                 selectAllInSelect("pos3");
  69.             });
  70.             if (html_url==4){
  71.                 this.evaluate(function(){
  72.                     selectAllInSelect("pos4");
  73.                 });
  74.             }
  75.             else if (html_url==5){
  76.                 this.evaluate(function(){
  77.                     selectAllInSelect("pos4");
  78.                     selectAllInSelect("pos5");
  79.                 });
  80.             }
  81.         });
  82.         this.wait(2000);
  83.         this.waitAndClick(ex("//input[contains(@value,'Cauta')]"))
  84.         this.wait(5000);
  85.     });
  86.  
  87. var files2 = genie.files();
  88.  
  89. files2.blacklist(blacklist)
  90.     .retry(5)
  91.     .add({
  92.         'file15.html': {
  93.             'fileName': "//a[contains(text(),'FOM104F')]"
  94.         },
  95.         'file16.html': {
  96.             'fileName': "//a[contains(text(),'FOM105F')]"
  97.         }
  98.     })
  99.  
  100.     .steps(function (parameters) {
  101.         this.thenOpen("http://statistici.insse.ro/shop/?lang=ro");
  102.         this.wait(5000);
  103.         this.waitForSelector(ex("//input[contains(@value,'Login')]"),function success(){
  104.                 this.sendKeys(ex("//input[contains(@name,'Login')]"), USERNAME);
  105.                 this.wait(2000);
  106.                 this.sendKeys(ex("//input[contains(@name,'Password')]"), PASSWORD);
  107.                 this.wait(2000);
  108.                 this.then(function(){
  109.                     this.capture("downloads/input.png")
  110.                 })
  111.                 this.evaluate(function(){
  112.                     $(document).xpath("//input[contains(@value,'Login')]").click().change()
  113.                 })
  114.             },
  115.             function fail() {
  116.                 console.log("Already log in")
  117.          });
  118.         this.wait(2000);
  119.         this.waitAndClick(ex("//a[contains(text(),'MISCAREA')]/following::a[contains(text(),'FORTA')]"));
  120.         this.waitAndClick(ex(parameters.fileName));
  121.         this.wait(5000);
  122.         this.then(function(){
  123.             this.evaluate(function(){
  124.                 selectAllInSelect("pos1");
  125.                 selectAllInSelect("pos4");
  126.             });
  127.         });
  128.         this.wait(2000);
  129.         this.waitAndClick(ex("//input[contains(@value,'Cauta')]"))
  130.         this.wait(5000);
  131.     });
  132.  
  133. var files3 = genie.files();
  134.  
  135. files3.blacklist(blacklist)
  136.     .retry(5)
  137.     .add({
  138.         'file6.html': {
  139.             'fileName': "//a[contains(text(),'AMG155B')]"
  140.         },
  141.         'file8.html': {
  142.             'fileName': "//a[contains(text(),'AMG156B')]"
  143.         }
  144.     })
  145.  
  146.     .steps(function (parameters) {
  147.         this.thenOpen("http://statistici.insse.ro/shop/?lang=ro");
  148.         this.wait(5000);
  149.         this.waitForSelector(ex("//input[contains(@value,'Login')]"),function success(){
  150.                 this.sendKeys(ex("//input[contains(@name,'Login')]"), USERNAME);
  151.                 this.wait(2000);
  152.                 this.sendKeys(ex("//input[contains(@name,'Password')]"), PASSWORD);
  153.                 this.wait(2000);
  154.                 this.then(function(){
  155.                     this.capture("downloads/input.png")
  156.                 })
  157.                 this.evaluate(function(){
  158.                     $(document).xpath("//input[contains(@value,'Login')]").click().change()
  159.                 })
  160.             },
  161.             function fail() {
  162.                 console.log("Already log in")
  163.          });
  164.         this.wait(2000);
  165.         this.waitAndClick(ex("//a[contains(text(),'MISCAREA')]/following::a[contains(text(),'FORTA')]"));
  166.         this.waitAndClick(ex(parameters.fileName));
  167.         this.wait(2000);
  168.         this.then(function(){
  169.             this.evaluate(function(){
  170.                 $(document).xpath("//option[contains(text(),'Total ')]").attr('selected', false)
  171.                 $(document).xpath("//option[contains(text(),'Urban')]").attr('selected', true)
  172.                 $(document).xpath("//option[contains(text(),'Rural')]").attr('selected', true)
  173.                 selectAllInSelect("pos3");
  174.             });
  175.         });
  176.         this.wait(2000);
  177.         this.waitAndClick(ex("//input[contains(@value,'Cauta')]"))
  178.         this.wait(5000);
  179.     });
  180.  
  181. genie.run(files1);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement