Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Instagram viewStories #105

Merged
merged 54 commits into from
Apr 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
ccbd26b
[wip] instagram & core botactions/helpers
mrWh1te Mar 5, 2021
4a6e03e
clickText
mrWh1te Mar 5, 2021
b3b287b
clickElementWithText helper
mrWh1te Mar 5, 2021
93ed6f8
working viewStories
mrWh1te Mar 5, 2021
7ddacfa
clean up
mrWh1te Mar 5, 2021
6aa6b90
fix #102 $$ multiple elements scraping
mrWh1te Mar 5, 2021
c287de9
unnecessary
mrWh1te Mar 5, 2021
0e8787e
botactions getCookies & deleteCookies & instagram logout
mrWh1te Mar 6, 2021
29b2ac3
instagram logout concept
mrWh1te Mar 6, 2021
9382026
wip delete IndexedDB database by name
mrWh1te Mar 6, 2021
6bdc619
instagram logout
mrWh1te Mar 7, 2021
fe3fbe9
e2e test $() for not finding node
mrWh1te Mar 9, 2021
c24b6dd
e2e test textExists & elementExists
mrWh1te Mar 10, 2021
51dfea6
remove code-coverage check in evaluated func's
mrWh1te Mar 10, 2021
12ee8d7
e2e clickText
mrWh1te Mar 10, 2021
5b11056
e2e clickText edge-case
mrWh1te Mar 10, 2021
42a03cd
integration test getCookies
mrWh1te Mar 10, 2021
0c8a6e3
integration test deleteCookies
mrWh1te Mar 10, 2021
64e8bb6
e2e cookies testing
mrWh1te Mar 10, 2021
542d404
comment simplification
mrWh1te Mar 10, 2021
df0b481
[concept] runOnDiceRoll()() BotAction #85
mrWh1te Mar 15, 2021
8e99988
naming
mrWh1te Mar 15, 2021
b284515
onDiceRoll name change & helper diceRoll() unit-test
mrWh1te Mar 17, 2021
5371c7e
probably() botaction concept - new BotAction group: Random
mrWh1te Mar 17, 2021
ccc660a
naming
mrWh1te Mar 17, 2021
b583aed
rollDice()() implementation to use probably()()
mrWh1te Mar 17, 2021
7c2467c
delete randomDiceRoll()
mrWh1te Mar 17, 2021
036fe6a
added ability to override random decimal function
mrWh1te Mar 17, 2021
4921569
probably()() HO 2nd param (optional) to override random number generator
mrWh1te Mar 17, 2021
b5da118
refine test expectations
mrWh1te Mar 17, 2021
42f9feb
notes
mrWh1te Mar 17, 2021
95505e9
[wip] randomGenerator HO BotAction to inject randomizer func
mrWh1te Mar 18, 2021
5108279
[concept] probably()() accepts inject for random number function
mrWh1te Mar 18, 2021
ac74747
use unpipeInjects() helper
mrWh1te Mar 18, 2021
a3ccdb4
concept set randomDecimal HO injector for NumberReturningFunc
mrWh1te Mar 18, 2021
673cbe3
not going to force pipe() on randomDecimal()() injector
mrWh1te Mar 18, 2021
4bc7547
consistent naming
mrWh1te Mar 18, 2021
653ea14
[wip] unit & integration tests
mrWh1te Mar 19, 2021
24b0b71
random botactions test coverage
mrWh1te Mar 23, 2021
b1acc3c
indexed-db e2e testing
mrWh1te Mar 25, 2021
84af13a
house cleaning
mrWh1te Mar 25, 2021
8bb5e45
code smells
mrWh1te Mar 25, 2021
d813f88
Nullish Assignment
mrWh1te Apr 13, 2021
48d0cf6
Nullish Assignment
mrWh1te Apr 13, 2021
6d0efe8
Nullish Assignment
mrWh1te Apr 13, 2021
ac8f438
code smell
mrWh1te Apr 16, 2021
84b4d24
simplify goTo implementation
mrWh1te Apr 20, 2021
5d7ffcf
tests + code polish
mrWh1te Apr 20, 2021
6ea0cb3
17 botaction groups - added random
mrWh1te Apr 20, 2021
c6c48f8
consolidated URL helpers into simpler constants
mrWh1te Apr 20, 2021
1bb45e3
fix instagram barrel + desktop widths
mrWh1te Apr 21, 2021
5cd99fc
fix
mrWh1te Apr 21, 2021
9804fee
new minor versions for core and instagram pckgs
mrWh1te Apr 21, 2021
6f8f49f
instagram reference latest core pckg
mrWh1te Apr 21, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
## v1.3.0 @botmation/core

New BotActions group called "Random" for running BotActions on a probability.

Couple bug fixes.

New auxiliary Instagram package v1.1.0:
- navigation
- view stories
- logout

More details [here](https://github.com/mrWh1te/Botmation/pull/105).

## v1.2.0 @botmation/core

New BotAction called [restart](https://www.botmation.dev/api/abort#restart) for restarting an assembled lines of BotActions that aborts.

Added support for latest major Puppeteer v8.

More details [here](https://github.com/mrWh1te/Botmation/pull/97).

## v1.1.0 @botmation/core

New `schedule()` BotAction, reorganization of BotAction groups (Utilities => Time, Loops, Branching) and minor performance improvement of a few core BotActions.
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ Import any core API function from:
import { chain, goTo, screenshot } from '@botmation/core'
```

`@botmation/core` v1 has 16 groups of BotActions to choose from:
`@botmation/core` v1 has 17 groups of BotActions to choose from:

<img alt="Leader Bot" src="https://raw.githubusercontent.com/mrWh1te/Botmation/master/assets/art/red_bot.PNG" width="200" align="right" style="position: relative;top: 30px;">

Expand Down Expand Up @@ -98,6 +98,8 @@ import { chain, goTo, screenshot } from '@botmation/core'
- change the page's URL, wait for form submissions to change page URL, back, forward, refresh
- [pipe](https://www.botmation.dev/api/pipe)
- functions specific to Piping
- [random](https://www.botmation.dev/api/random)
- functions specific to randomness like rolling dice
- [scrapers](https://www.botmation.dev/api/scrapers)
- scrape HTML documents with an HTML parser and evaluate JavaScript inside a Page
- [time](https://www.botmation.dev/api/time)
Expand Down
46 changes: 34 additions & 12 deletions apps/bot-instagram/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import {
givenThat,
loadCookies,
saveCookies,
goTo,
screenshot,
logError
logError,
waitForNavigation,
wait,
} from '@botmation/core'

import {
Expand All @@ -18,7 +19,10 @@ import {
isLoggedIn,
closeTurnOnNotificationsModal,
isTurnOnNotificationsModalActive,
getInstagramBaseUrl
goToHome,
viewStories,
isSaveYourLoginInfoActive,
clickSaveYourLoginInfoNoButton,
} from '@botmation/instagram'

(async () => {
Expand All @@ -29,17 +33,26 @@ import {
const pages = await browser.pages()
const page = pages.length === 0 ? await browser.newPage() : pages[0]

// Instagram BotActions were developed for the UI responsiveness in desktop widths
// specifically, in mobile widths, the `viewStories` BotAction will open your story
// instead of the presentation of stories
await page.setViewport({
width: 1000,
height: 600,
deviceScaleFactor: 1,
});

await chain(
log('Botmation running'),

// Sets up the injects for BotFileAction's (optional)
files({cookies_directory: 'simple'})(
files()(
// Takes the name of the file to load cookies from
// Match this value with the same used in saveCookies()
loadCookies('instagram'),
),

goTo(getInstagramBaseUrl()),
goToHome,

// inline, hackish but do-able if your doing something on the fly
// follow the rules, don't return a value in a chain
Expand All @@ -48,26 +61,35 @@ import {
// },

// lets log in, if we are a guest
log('checking Guest status'),
givenThat(isGuest) (
log('is guest so logging in'),
login({username: 'account', password: 'password'}), // <- put your username and password here
files({cookies_directory: 'simple'})(
saveCookies('instagram'), // the Bot will skip login, on next run, by loading cookies
files()(
saveCookies('instagram'), // the Bot will skip login, on next run, by loading the cookies from this file
),
log('Saved Cookies')
),

// in case that log in failed, lets check before we operate as a logged in user
givenThat(isLoggedIn)(
log('is logged in'),
// After initial load, Instagram sometimes prompts the User with a modal...

givenThat(isSaveYourLoginInfoActive)(
clickSaveYourLoginInfoNoButton,
waitForNavigation,
log('save ur login info closed')
),

// Deal with the "Turn On Notifications" Modal, if it shows up
givenThat(isTurnOnNotificationsModalActive)(
closeTurnOnNotificationsModal
),

screenshot('logged-in'),

viewStories,

log('screenshot taken'),

wait(5000),

),

log('Done'),
Expand Down
35 changes: 35 additions & 0 deletions assets/server/cookies.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>Testing: Cookies
</title>
<script type="text/javascript">
document.cookie = "username=John Doe";
document.cookie = "sessionId=1235711"
</script>
</head>
<body>
<h1>Cookies Page</h1>
<aside>
<ul>
<li>
<a href="/index.html" class="home-link">Home Link</a>
</li>
<li>
<a href="/example.html" class="example-link">Example Link</a>
</li>
<li>
<a href="/example2.html" class="example-link">Example Link 2</a>
</li>
</ul>
</aside>
<section>
<form action="/success.html">
<input type="text" name="answer" />
<button type="submit">
Click Me!
</button>
</form>
</section>
</body>
</html>
79 changes: 79 additions & 0 deletions assets/server/indexed-db.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>Testing: IndexedDB</title>
<script type="text/javascript">
const databaseName = 'MyTestDatabase';
const databaseName2 = 'MySecondDatabase';
const databaseVersion = undefined;
const storeName = 'TestObjectStore';
const key = 'TestKey';
const value = 'TestValue234';

const openRequest = indexedDB.open(databaseName, databaseVersion);

openRequest.onerror = function(ev) {
ev.stopPropagation();
console.error(openRequest.error);
}

openRequest.onupgradeneeded = function(ev) {
if (!openRequest.result.objectStoreNames.contains(storeName)) {
openRequest.result.createObjectStore(storeName);
}
}

openRequest.onsuccess = function(ev) {
const db = openRequest.result;

try {
db.transaction(storeName, 'readwrite')
.objectStore(storeName)
.put(value, key)
.onsuccess = function() {
db.close();
}
} catch (error) {
db.close();
}
}

const openRequest2 = indexedDB.open(databaseName2);

openRequest2.onerror = function(ev) {
ev.stopPropagation();
console.error(openRequest2.error);
}

openRequest2.onupgradeneeded = function(ev) {
if (!openRequest2.result.objectStoreNames.contains(storeName)) {
openRequest2.result.createObjectStore(storeName);
}
}

openRequest2.onsuccess = function(ev) {
const db = openRequest2.result;

try {
db.transaction(storeName, 'readwrite')
.objectStore(storeName)
.put(value, key)
.onsuccess = function() {
db.close();
}
} catch (error) {
db.close();
}
}
</script>
</head>
<body>
<h1>IndexedDB</h1>
<ul>
<li>DB name: MyTestDatabase</li>
<li>Store name: TestObjectStore</li>
<li>Key: TestKey</li>
<li>Key Value: TestValue234</li>
</ul>
</body>
</html>
4 changes: 3 additions & 1 deletion libs/core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ Import any core API function from:
import { chain, goTo, screenshot } from '@botmation/core'
```

`@botmation/core` v1 has 16 groups of BotActions to choose from:
`@botmation/core` v1 has 17 groups of BotActions to choose from:

<img alt="Leader Bot" src="https://raw.githubusercontent.com/mrWh1te/Botmation/master/assets/art/red_bot.PNG" width="200" align="right" style="position: relative;top: 30px;">

Expand Down Expand Up @@ -104,6 +104,8 @@ import { chain, goTo, screenshot } from '@botmation/core'
- change the page's URL, wait for form submissions to change page URL, back, forward, refresh
- [pipe](https://www.botmation.dev/api/pipe)
- functions specific to Piping
- [random](https://www.botmation.dev/api/random)
- functions specific to randomness like rolling dice
- [scrapers](https://www.botmation.dev/api/scrapers)
- scrape HTML documents with an HTML parser and evaluate JavaScript inside a Page
- [time](https://www.botmation.dev/api/time)
Expand Down
2 changes: 1 addition & 1 deletion libs/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@botmation/core",
"version": "1.2.1",
"version": "1.3.0",
"description": "Main package of functions for the TypeScript framework Botmation",
"homepage": "https://botmation.dev",
"author": "Michael Lage",
Expand Down
3 changes: 3 additions & 0 deletions libs/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export * from './lib/actions/scrapers'
export * from './lib/actions/loops'
export * from './lib/actions/branching'
export * from './lib/actions/time'
export * from './lib/actions/random'

//
// Helpers
Expand All @@ -36,8 +37,10 @@ export * from './lib/helpers/cases'
export * from './lib/helpers/console'
export * from './lib/helpers/files'
export * from './lib/helpers/indexed-db'
export * from './lib/helpers/input'
export * from './lib/helpers/local-storage'
export * from './lib/helpers/navigation'
export * from './lib/helpers/pipe'
export * from './lib/helpers/scrapers'
export * from './lib/helpers/cases'
export * from './lib/helpers/random'
10 changes: 5 additions & 5 deletions libs/core/src/lib/actions/abort.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ export const restart = (...actions: BotAction<any>[]): BotAction<any> =>
// manually resolving actions in a Pipe instead of using pipe()() to control the AbortLineSignal processing
actionResult = await action(page, ...injects, pipeObject)

// unique recycle aborting behavior
// unique restart aborting behavior
if (isAbortLineSignal(actionResult)) {
// cannot recycle an infinity abort, if desirable, create another BotAction - maybe with a customizing HO function
// assembledLines 1 => recycle actions
// assembledLines 0 or 2+ => abort recycle
// cannot restart an infinity abort, if desirable, create another BotAction - maybe with a customizing HO function
// assembledLines 1 => restart actions
// assembledLines 0 or 2+ => abort restart
if (actionResult.assembledLines > 1 || actionResult.assembledLines === 0) {
return processAbortLineSignal(actionResult, 2) // abort the line and abort recycle()
return processAbortLineSignal(actionResult, 2) // abort the line and abort restart()
} else {
restartActions = true;
pipeObject = wrapValueInPipe(actionResult.pipeValue)
Expand Down
1 change: 1 addition & 0 deletions libs/core/src/lib/actions/branching.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,4 @@ export const givenThat =
}
}
}

2 changes: 1 addition & 1 deletion libs/core/src/lib/actions/console.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('[Botmation] actions/console', () => {
page = await browser.newPage()
})

afterEach(async () => {
afterEach(async() => {
await page.close()
})

Expand Down
Loading