Skip to content

Commit

Permalink
from nodejs@gcloud
Browse files Browse the repository at this point in the history
  • Loading branch information
gcloud committed Dec 18, 2017
1 parent 835e223 commit 1b7cc46
Show file tree
Hide file tree
Showing 12 changed files with 1,192 additions and 0 deletions.
1,031 changes: 1,031 additions & 0 deletions example/package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"author": "",
"license": "ISC",
"dependencies": {
"cheerio-httpcli": "^0.7.2",
"puppeteer": "^0.13.0"
}
}
160 changes: 160 additions & 0 deletions example/rl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
/*
'#rlogin-username-ja'
'#rlogin-password-ja'
'body > div.rf-form-login.rf-red > main > div > section.rf-form-login--step-1 > form > p:nth-child(7) > button'
$
npm i --save puppeteer
*/
'use strict';

const puppeteer = require('puppeteer');
const devices = require('./DeviceDescriptors');

//const debug = require('debug')('puppeteer');

let CREDS1 = require('./cred2');// load IPASS
// let CREDS = CREDS1.test; // アカウント切り替え
let CREDS = CREDS1.kuroko; // アカウント切り替え
// let CREDS = CREDS1.kuroko; // アカウント切り替え
//let chromeGuiFlg = false;// NoGUI:true GUI:false
let chromeGuiFlg = true;// NoGUI:true GUI:false
const slowMotion = 50;// GUI時に早すぎる動きを遅くする、大きいほど遅く


/*/////////////////////////////*/

async function run() {
// dom element selectors
const USERNAME_SELECTOR = '#rlogin-username-ja';
const PASSWORD_SELECTOR = '#rlogin-password-ja';
const BUTTON_SELECTOR =
'body > div.rf-form-login.rf-navy > main > div > section.rf-form-login--step-1 > form > p:nth-child(6) > button';

const USERNAME_SELECTOR2 = '#rlogin-username-2-ja';
const PASSWORD_SELECTOR2 = '#rlogin-password-2-ja';
const BUTTON_SELECTOR2 =
'body > div > main > div > section.rf-form-login--step-2 > form > p:nth-child(8) > button';

const BUTTON_SELECTOR3 = '#message-ja > section > div > div > div > div > button';
// 'body > div.rf-form-login.rf-red > main > div > section.rf-form-login--step-1 > form > p:nth-child(7) > button';
// 'body > div.rf-form-login.rf-navy > main > div > section.rf-form-login--step-1 > form > p:nth-child(6) > button'
const LOGIN_URL = 'https://glogin.rms.rakuten.co.jp/' ;
const LOGIN_URL2 = 'https://mainmenu.rms.rakuten.co.jp/' ;

// const browser = await puppeteer.launch();
const browser = await puppeteer.launch({
headless: chromeGuiFlg,
slowMo: slowMotion // slow down by 250ms
});
const page = await browser.newPage();
await page.setViewport({ width: 400, height: 800 }); // view portの指定
// await page.emulate(devices['iPhone 6']);

await page.goto(LOGIN_URL);
await page.screenshot({ path: 'screenshots/login.png' });
// 1st
await page.click(USERNAME_SELECTOR);
await page.keyboard.type(CREDS.username);

await page.keyboard.down('Shift');
for (let i = 0; i < ' World'.length; i++)
await page.keyboard.press('ArrowLeft');
await page.keyboard.up('Shift');
await page.keyboard.down('Tab');

await page.click(PASSWORD_SELECTOR);
await page.keyboard.type(CREDS.password);
await page.click(BUTTON_SELECTOR);
await page.screenshot({ path: 'screenshots/login1.png' });

// await page.waitForNavigation();
await page.screenshot({ path: 'screenshots/afterLogin.png' });
// 2nd
await page.click(USERNAME_SELECTOR2);
await page.keyboard.type(CREDS.username2);

await page.click(PASSWORD_SELECTOR2);
await page.keyboard.type(CREDS.password2);
await page.click(BUTTON_SELECTOR2);
await page.screenshot({ path: 'screenshots/login2.png' });

await page.waitFor(1000);

await setTimeout(() => {
// await page.click(BUTTON_SELECTOR3);
page.click(BUTTON_SELECTOR3);
}, 1000);
// body > main > div > div.rf-grid.rf-grid--1--1--2.rf-service-top-page-grid > dl:nth-child(2) > dd > a
// await page.goto(LOGIN_URL2);
// body > main > div > div.rf-grid.rf-grid--1--1--2.rf-service-top-page-grid > dl:nth-child(2) > dd > a
// await page.click('a[href="https://mainmenu.rms.rakuten.co.jp/?act=login&sp_id=1"]');
// await page.click('body > main > div > div.rf-grid.rf-grid--1--1--2.rf-service-top-page-grid > dl:nth-child(2) > dd > a');
await setTimeout(() => {
// page.click('body > main > div > div.rf-grid.rf-grid--1--1--2.rf-service-top-page-grid > dl:nth-child(2) > dd > a');
}, 1000);
// const xpathUrl = '/html/body/main/div/div[3]/dl[2]/dd/a';
// await page.click(xpath(page, '/html/body/main/div/div[3]/dl[2]/dd/a'));

/* <a class="rf-medium" href="https://mainmenu.rms.rakuten.co.jp/?act=login&amp;sp_id=1">RMS<span class="rf-icon rf-icon-chevron-right"></span></a> */
await page.waitFor(3000);

for (let i = 0; i < 8; i++){
await page.waitFor(500);
await page.keyboard.press('Tab');
}

await page.waitFor(1000);
await page.keyboard.press('Enter');
// await page.keyboard.press('Space');

const SUBMIT= 'body > form > table:nth-child(4) > tbody > tr > td > input[type="submit"]';
await page.waitFor(1000);
for (let i = 0; i < 5; i++){
await page.waitFor(500);
await page.keyboard.press('Tab');
}
await page.keyboard.press('Space');

// await page.click(SUBMIT);

await page.waitFor(1000);
const ITEM_UPDATE = 'https://mainmenu.rms.rakuten.co.jp/?left_navi=11';
await page.goto(ITEM_UPDATE);

await page.waitFor(1000);
// const ITEM_UPDATE1 = 'https://item.rms.rakuten.co.jp/rms/mall/rsf/item/vc?__event=RI00_001_002&shop_bid=320124';
const ITEM_UPDATE1 = 'https://item.rms.rakuten.co.jp/rms/mall/rsf/item/vc?__event=RI00_001_002&shop_bid=' + CREDS.shop_bid ;
await page.goto(ITEM_UPDATE1);

await page.waitFor(1000);
const ITEM_UPDATE2 = '#r_07';
// const ITEM_UPDATE2 = 'body > form > table > tbody > tr > td:nth-child(2) > table:nth-child(4) > tbody > tr > td:nth-child(2) > table > tbody > tr:nth-child(17) > td:nth-child(2) > font > b > label';
await page.click(ITEM_UPDATE2);

for (let i = 0; i < 3; i++){
await page.waitFor(500);
await page.keyboard.press('Tab');
}
await page.keyboard.press('Space');



// const ITEM_UPDATE = '#subNav > li:nth-child(1) > ul > li.first > a';
// await page.click(ITEM_UPDATE);
await page.waitFor(2000);

await page.screenshot({ path: 'screenshots/finish.png' });
// const [handle1, handle2] = await xpath(page, '/html/body/main/div/div[3]/dl[2]/dd/a');
// console.log(await page.click(e => e.textContent, handle1));
// console.log(await page.evaluate(e => e.textContent, handle1));
// console.log(await page.evaluate(e => e.textContent, handle2));



// await page.waitForNavigation();
await browser.close();

}
run();

Binary file modified example/screenshots/afterLogin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified example/screenshots/finish.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed example/screenshots/finish1.png
Binary file not shown.
Binary file removed example/screenshots/github.png
Binary file not shown.
Binary file removed example/screenshots/githublogin.png
Binary file not shown.
Binary file removed example/screenshots/githubsearch.png
Binary file not shown.
Binary file modified example/screenshots/login.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified example/screenshots/login1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified example/screenshots/login2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 1b7cc46

Please sign in to comment.