-
Notifications
You must be signed in to change notification settings - Fork 0
/
my-test.js
76 lines (56 loc) · 3.25 KB
/
my-test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import { assert } from 'chai';
import { Builder, By, Key, until } from "selenium-webdriver";
const chrome = require('selenium-webdriver/chrome');
const HarCapture = require('../capture-har');
const server = 'https://loadmill-test-blog.herokuapp.com'
describe('Loadmill selenium demo', async function () {
let driver;
this.timeout(50000);
// create an HarCapture
const { startRecording, endRecording } = HarCapture();
before(async () => {
let chrome_options = new chrome.Options()
.addArguments("--remote-debugging-port=9223");
driver = await new Builder()
.setChromeOptions(chrome_options)
.forBrowser('chrome')
.build();
// start the recording
await startRecording({ port: 9223 });
});
it('Publish a blog post', async function () {
const randomPostTitle = 'Test post title ' + Math.floor(Math.random() * 1000000);
await driver.navigate().to(server + '/ghost/signin/');
await driver.wait(until.elementLocated(By.name('identification')));
// login to blog
await driver.findElement(By.name('identification')).sendKeys('[email protected]');
await driver.findElement(By.name('password')).sendKeys('Test1234' + Key.RETURN);
// Create blog post
await driver.wait(until.elementLocated(By.xpath('//a[@href="/ghost/editor/"]')));
await driver.findElement(By.xpath('//a[@href="/ghost/editor/"]')).click();
// Set post title and text
await driver.wait(until.elementLocated(By.id('entry-title')));
await driver.findElement(By.id('entry-title')).sendKeys(randomPostTitle);
await driver.findElement(By.xpath('//section[@id="entry-markdown-content"]//textarea')).sendKeys('Test post text');
await driver.wait(until.elementLocated(By.xpath("//button[text()='Save Draft']"))); // wait for autosave
await driver.findElement(By.xpath("//button[text()='Save Draft']")).click(); // save post draft
await driver.wait(until.elementLocated(By.xpath("//button[text()='Save Draft']"))); // wait save to finish
// Publish post
await driver.findElement(By.xpath("//button[.//*[text()='Toggle Settings Menu']]")).click(); // open publish menu
await driver.wait(until.elementLocated(By.xpath("//a[text()='Publish Now']")));
await driver.findElement(By.xpath("//a[text()='Publish Now']")).click(); // click publish
await driver.wait(until.elementLocated(By.xpath("//button[text()='Publish Now']")));
await driver.findElement(By.xpath("//button[text()='Publish Now']")).click(); // confirm publish
await driver.wait(until.elementLocated(By.xpath("//button[text()='Update Post']"))); // wait save to finish
// validate post is published
await driver.navigate().to(server);
await driver.wait(until.elementLocated(By.xpath("/html/body/div[2]/header/div/div/h1")));
let topBlogPost = driver.findElement(By.xpath(`//*[@id='content']/article[1]/header/h2/a[text()='${randomPostTitle}']`));
assert.isTrue(await topBlogPost.isDisplayed(), 'Post title match');
});
after(async () => {
// stop the recording and save to file
endRecording('create-blog-post.har');
driver.quit();
});
});