画面テスト自動化
- 8. 実際のコード(Selenium)
const webdriver = require('selenium-webdriver');
const { Builder, By, until } = webdriver;
// ブラウザ設定
const webdriver = require('selenium-webdriver');
const { Builder, By, until } = webdriver;
const assert = require('assert');
const capabilities = webdriver.Capabilities.chrome();
capabilities.set('chromeOptions', {
args: [
'--headless',
'--no-sandbox',
'--disable-gpu',
`--window-size=1980,1200`
]
});
// ログイン成功
(async () => {
const driver = await new Builder().withCapabilities(capabilities).build();
await driver.get("http://localhost:3000");
// IDパスワードを入力
let userId = await driver.findElement(By.id('loginId'));
userId.sendKeys("buto.risa");
let password = await driver.findElement(By.id('password'));
password.sendKeys("xxxxx");
// ログイン
let loginButton = await driver.findElement(By.id('loginButton'));
loginButton.click();
await driver.wait(until.elementLocated(By.id('paymentList')), 10000);
// 支払い一覧ページへ遷移していること
assert.strictEqual(await driver.getCurrentUrl(),
"http://localhost:3000/payment");
driver.quit();
})();
- 9. 実際のコード(puppeteer)
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch({ headless: false });
const page = await browser.newPage();
await page.goto('http://localhost:3000');
// IDパスワードを入力
const userId = await page.$('#loginId');
await userId.type('buto.risa');
const password = await page.$('#password');
await password.type('xxxxx');
// ログイン
const loginButton = await page.$('#loginButton');
await loginButton.click();
await page.waitForTimeout(3000);
// 支払い一覧ページへ遷移していること
assert.strictEqual(await page.url(), "http://localhost:3000/payment");
await browser.close();
})();