Skip to content

Instantly share code, notes, and snippets.

@tpai
Last active November 2, 2020 13:50
Show Gist options
  • Select an option

  • Save tpai/2356257ce73dce0701f0 to your computer and use it in GitHub Desktop.

Select an option

Save tpai/2356257ce73dce0701f0 to your computer and use it in GitHub Desktop.

Revisions

  1. tpai revised this gist Nov 12, 2014. 1 changed file with 11 additions and 5 deletions.
    16 changes: 11 additions & 5 deletions readme.md
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    Instruction
    ---

    1) download poe.js, package.json and latest version of [selenium server](http://selenium-release.storage.googleapis.com/index.html)
    1) download poe.js, package.json and latest version of [selenium server](http://selenium-release.storage.googleapis.com/index.html) into the same folder

    2) install require modules

    @@ -19,11 +19,17 @@ Instruction

    $ mkdir tests

    5) be sure to modify the acc and pwd variable in poe.js, and move it to tests/ folder.
    5) modify the acc and pwd variable in poe.js, and move it to tests/ folder.

    6) run command below

    $ mv poe.js tests/

    $ nightwatch --test tests/poe.js
    6) launch selenium server (must install firefox)

    **P.S. Be sure to install firefox and launch selenium server.**

    $ java -jar selenium-server-standalone-{VERSION}.jar

    7) run command below


    $ nightwatch --test tests/poe
  2. tpai revised this gist Nov 12, 2014. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions readme.md
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    Instruction
    ---

    1) download poe.js and package.json
    1) download poe.js, package.json and latest version of [selenium server](http://selenium-release.storage.googleapis.com/index.html)

    2) install require modules

    @@ -26,4 +26,4 @@ Instruction

    $ nightwatch --test tests/poe.js

    **P.S. Be sure to install firefox.**
    **P.S. Be sure to install firefox and launch selenium server.**
  3. tpai revised this gist Nov 11, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion readme.md
    Original file line number Diff line number Diff line change
    @@ -19,7 +19,7 @@ Instruction

    $ mkdir tests

    5) be sure to modify the acc and pwd variable in poe.js
    5) be sure to modify the acc and pwd variable in poe.js, and move it to tests/ folder.

    6) run command below

  4. tpai revised this gist Nov 11, 2014. 2 changed files with 6 additions and 4 deletions.
    2 changes: 1 addition & 1 deletion package.json
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    {
    "name": "nightwatch crawler",
    "name": "nightwatch_webcrawler",
    "description": "A web crawler sample based on nightwatch.",
    "version": "0.0.1",
    "author": {
    8 changes: 5 additions & 3 deletions readme.md
    Original file line number Diff line number Diff line change
    @@ -11,8 +11,8 @@ Instruction
    3) copy examples/ and lib/ at current folder


    $ cp node_modules/nightwatch/examples
    $ cp node_modules/nightwatch/lib
    $ cp node_modules/nightwatch/examples .
    $ cp node_modules/nightwatch/lib .

    4) create tests/ folder

    @@ -24,4 +24,6 @@ Instruction
    6) run command below


    $ nightwatch --test tests/poe.js
    $ nightwatch --test tests/poe.js

    **P.S. Be sure to install firefox.**
  5. tpai renamed this gist Nov 10, 2014. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  6. tpai revised this gist Nov 10, 2014. 1 changed file with 21 additions and 22 deletions.
    43 changes: 21 additions & 22 deletions poe.js
    Original file line number Diff line number Diff line change
    @@ -1,31 +1,30 @@
    module.exports = {
    tags: ['poe'],
    'Get POE Reward Images' : function (client) {

    var cheerio = require("cheerio")
    tags: ['poe'],
    'Get POE Reward Images' : function (client) {

    var cheerio = require("cheerio") // easy to parse HTML
    var acc = "<your-account>"
    var pwd = "<your-password>"

    client
    .url('http://web.poe.garena.tw/login')
    .waitForElementVisible('body', 1000)
    .assert.title('Garena')
    .assert.visible('#sso_login_form_account')
    .setValue('#sso_login_form_account', acc)
    client
    .url('http://web.poe.garena.tw/login')
    .waitForElementVisible('body', 1000)
    .assert.title('Garena')
    .assert.visible('#sso_login_form_account')
    .setValue('#sso_login_form_account', acc)
    .setValue('#sso_login_form_password', pwd)
    .waitForElementVisible('#confirm-btn', 1000)
    .click('#confirm-btn')
    .pause(2000)
    .assert.visible('div.tab-links')
    .waitForElementVisible('#confirm-btn', 1000)
    .click('#confirm-btn')
    .pause(2000)
    .assert.visible('div.tab-links')
    .url("http://web.poe.garena.tw/account/view-profile/"+acc+"/events")
    .source(function(result) {
    $ = cheerio.load(result.value)
    var images = $("div.reward img")
    for(var i=0;i<images.length;i++) {
    console.log($(images[i]).attr("src"));
    }
    .source(function(result) { // .source() will dump the target page into text format
    $ = cheerio.load(result.value) // so it needs to be parse
    var images = $("div.reward img")
    for(var i=0;i<images.length;i++) {
    console.log($(images[i]).attr("src"));
    }
    })
    .end();
    }
    .end();
    }
    };
  7. tpai revised this gist Nov 10, 2014. 2 changed files with 11 additions and 34 deletions.
    27 changes: 0 additions & 27 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -1,27 +0,0 @@
    Instruction
    ---

    1) download poe.js and package.json

    2) install require modules


    $ npm install

    3) copy examples/ and lib/ at current folder


    $ cp node_modules/nightwatch/examples
    $ cp node_modules/nightwatch/lib

    4) create tests/ folder


    $ mkdir tests

    5) be sure to modify the acc and pwd variable in poe.js

    6) run command below


    $ nightwatch --test tests/poe.js
    18 changes: 11 additions & 7 deletions nightwatch_crawler.md
    Original file line number Diff line number Diff line change
    @@ -1,23 +1,27 @@
    Instruction
    ---

    1. download poe.js and package.json
    1) download poe.js and package.json

    2) install require modules

    2. install require modules

    $ npm install

    3. copy examples/ and lib/ at current folder
    3) copy examples/ and lib/ at current folder


    $ cp node_modules/nightwatch/examples
    $ cp node_modules/nightwatch/lib

    4. create tests/ folder
    4) create tests/ folder


    $ mkdir tests

    5. be sure to modify the acc and pwd variable in poe.js
    5) be sure to modify the acc and pwd variable in poe.js

    6) run command below

    6. run command below

    $ nightwatch --test tests/poe
    $ nightwatch --test tests/poe.js
  8. tpai revised this gist Nov 10, 2014. 1 changed file with 6 additions and 6 deletions.
    12 changes: 6 additions & 6 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -1,27 +1,27 @@
    Instruction
    ---

    1. download poe.js and package.json
    1) download poe.js and package.json

    2. install require modules
    2) install require modules


    $ npm install

    3. copy examples/ and lib/ at current folder
    3) copy examples/ and lib/ at current folder


    $ cp node_modules/nightwatch/examples
    $ cp node_modules/nightwatch/lib

    4. create tests/ folder
    4) create tests/ folder


    $ mkdir tests

    5. be sure to modify the acc and pwd variable in poe.js
    5) be sure to modify the acc and pwd variable in poe.js

    6. run command below
    6) run command below


    $ nightwatch --test tests/poe.js
  9. tpai revised this gist Nov 10, 2014. 1 changed file with 27 additions and 0 deletions.
    27 changes: 27 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    Instruction
    ---

    1. download poe.js and package.json

    2. install require modules


    $ npm install

    3. copy examples/ and lib/ at current folder


    $ cp node_modules/nightwatch/examples
    $ cp node_modules/nightwatch/lib

    4. create tests/ folder


    $ mkdir tests

    5. be sure to modify the acc and pwd variable in poe.js

    6. run command below


    $ nightwatch --test tests/poe.js
  10. tpai renamed this gist Nov 10, 2014. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  11. tpai revised this gist Nov 10, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -20,4 +20,4 @@ Instruction

    6. run command below

    $ nightwatch --test tests/poe.js
    $ nightwatch --test tests/poe
  12. tpai created this gist Nov 10, 2014.
    23 changes: 23 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    Instruction
    ---

    1. download poe.js and package.json

    2. install require modules

    $ npm install

    3. copy examples/ and lib/ at current folder

    $ cp node_modules/nightwatch/examples
    $ cp node_modules/nightwatch/lib

    4. create tests/ folder

    $ mkdir tests

    5. be sure to modify the acc and pwd variable in poe.js

    6. run command below

    $ nightwatch --test tests/poe.js
    14 changes: 14 additions & 0 deletions package.json
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    {
    "name": "nightwatch crawler",
    "description": "A web crawler sample based on nightwatch.",
    "version": "0.0.1",
    "author": {
    "name": "tonypai",
    "email": "tony77794@gmail.com"
    },
    "homepage": "https://github.com/tpai",
    "dependencies": {
    "nightwatch": ">=0.5.33",
    "cheerio": ">=0.18.0"
    }
    }
    31 changes: 31 additions & 0 deletions poe.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    module.exports = {
    tags: ['poe'],
    'Get POE Reward Images' : function (client) {

    var cheerio = require("cheerio")

    var acc = "<your-account>"
    var pwd = "<your-password>"

    client
    .url('http://web.poe.garena.tw/login')
    .waitForElementVisible('body', 1000)
    .assert.title('Garena')
    .assert.visible('#sso_login_form_account')
    .setValue('#sso_login_form_account', acc)
    .setValue('#sso_login_form_password', pwd)
    .waitForElementVisible('#confirm-btn', 1000)
    .click('#confirm-btn')
    .pause(2000)
    .assert.visible('div.tab-links')
    .url("http://web.poe.garena.tw/account/view-profile/"+acc+"/events")
    .source(function(result) {
    $ = cheerio.load(result.value)
    var images = $("div.reward img")
    for(var i=0;i<images.length;i++) {
    console.log($(images[i]).attr("src"));
    }
    })
    .end();
    }
    };