Skip to content

Commit 56eed93

Browse files
committed
driverをテストごとに独立して作るように
1 parent 72ba4c6 commit 56eed93

File tree

1 file changed

+26
-24
lines changed

1 file changed

+26
-24
lines changed

e2e/top.test.js

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,44 +7,46 @@ import selenium from 'selenium-webdriver'
77
import chrome from 'selenium-webdriver/chrome.js'
88
import { injectDriver } from '@rozelin-dc/js-uitestfix'
99

10-
describe('test typing-lyrics top page', () => {
11-
/** @type {selenium.WebDriver} */
12-
let driver
13-
14-
beforeEach(async (context) => {
15-
const options = new chrome.Options()
16-
options.addArguments('--headless', '--window-size=1920,1080')
17-
driver = await new selenium.Builder()
18-
.forBrowser('chrome')
19-
.setChromeOptions(options)
20-
.build()
21-
const __dirname = path.dirname(fileURLToPath(import.meta.url))
22-
driver = await injectDriver(driver, context.name, {
23-
outputDir: path.join(__dirname, '../output'),
24-
answerDataDir: path.join(__dirname, '../answer-data'),
25-
configPath: path.join(__dirname, '../config.properties'),
26-
resultSavePath: path.join(__dirname, '../result'),
27-
})
28-
await driver.get('http://localhost:1123')
10+
const createDriver = async (testName) => {
11+
const options = new chrome.Options()
12+
options.addArguments('--headless', '--window-size=1920,1080')
13+
let driver = await new selenium.Builder()
14+
.forBrowser('chrome')
15+
.setChromeOptions(options)
16+
.build()
17+
const __dirname = path.dirname(fileURLToPath(import.meta.url))
18+
driver = await injectDriver(driver, testName, {
19+
outputDir: path.join(__dirname, '../output'),
20+
answerDataDir: path.join(__dirname, '../answer-data'),
21+
configPath: path.join(__dirname, '../config.properties'),
22+
resultSavePath: path.join(__dirname, '../result'),
2923
})
24+
await driver.get('http://localhost:1123')
25+
return driver
26+
}
3027

31-
afterEach(async () => {
32-
await driver.quit()
33-
})
28+
describe('test typing-lyrics top page', () => {
29+
it('get caption', async (context) => {
30+
const driver = await createDriver(context.name)
3431

35-
it('get caption', async () => {
3632
const captionElement = await driver.findElement(
3733
selenium.By.className('caption')
3834
)
3935
const captionText = await captionElement.getText()
4036
assert.equal(captionText.includes('UTAWO UTAOU'), true)
37+
38+
await driver.quit()
4139
})
4240

43-
it('get caption container', async () => {
41+
it('get caption container', async (context) => {
42+
const driver = await createDriver(context.name)
43+
4444
const captionElement = await driver.findElement(
4545
selenium.By.className('caption-container')
4646
)
4747
const visible = await captionElement.isDisplayed()
4848
assert.equal(visible, true)
49+
50+
await driver.quit()
4951
})
5052
})

0 commit comments

Comments
 (0)