Skip to content

Commit 57b7a3a

Browse files
authored
Initial commit
0 parents  commit 57b7a3a

5 files changed

+185
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Run Selenium On GitHub Action
2+
on:
3+
workflow_dispatch:
4+
schedule:
5+
- cron: '0 */2 * * *'
6+
jobs:
7+
scrape:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- name: Checking out repo
11+
uses: actions/checkout@v3
12+
- name: Setting up Python
13+
uses: actions/setup-python@v4
14+
with:
15+
python-version: '3.9'
16+
- name: Installing package list
17+
run: apt list --installed
18+
- name: Removing previous chrome instances on runner
19+
run: sudo apt purge google-chrome-stable
20+
21+
# Need to fetch reqs if needed
22+
- name: Installing all necessary packages
23+
run: pip install chromedriver-autoinstaller selenium pyvirtualdisplay
24+
- name: Install xvfb
25+
run: sudo apt-get install xvfb
26+
27+
- name: Running the Python script
28+
run: python Selenium-Template.py
29+
30+
- name: Commit and Push The Results From Python Selenium Action
31+
run: |
32+
git config --global user.name "github-actions[bot]"
33+
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
34+
git add -A
35+
git commit -m "GitHub Actions Results added"
36+
git push

GitHub_Action_Results.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This was written with a GitHub action GitHub: Let’s build from here · GitHub-2023-04-01 12:31:42.932160

LICENSE.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2022 MarketingPipeline
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# Python-Selenium-Action
2+
3+
4+
5+
<div align="center">
6+
<img height="400" src="https://i.imgur.com/s0CDqF5.png" />
7+
8+
<br>
9+
<small> <b><i>Show your support!</i> </b></small>
10+
<br>
11+
<a href="https://github.com/MarketingPipeline/Python-Selenium-Action">
12+
<img title="Star on GitHub" src="https://img.shields.io/github/stars/MarketingPipeline/Python-Selenium-Action.svg?style=social&label=Star">
13+
</a>
14+
<a href="https://github.com/MarketingPipeline/Python-Selenium-Action/fork">
15+
<img title="Fork on GitHub" src="https://img.shields.io/github/forks/MarketingPipeline/Python-Selenium-Action.svg?style=social&label=Fork">
16+
</a>
17+
</p>
18+
19+
20+
21+
22+
23+
24+
No need to struggle to figure out how to run a Python Selenium script with a [GitHub Action](https://github.com/features/actions).
25+
This is a <b>ready to use</b> template for running Selenium with Python via [GitHub Actions](https://github.com/features/actions) either headless or non-headless. <br> Comes with support already provided for taking screenshot's & more via [PyVirtualDisplay](https://pypi.org/project/PyVirtualDisplay/)!
26+
</div>
27+
28+
29+
30+
## Example and usage
31+
32+
33+
To use <b><i>Github Action</b></i>:
34+
35+
- Use this
36+
[template](https://github.com/MarketingPipeline/Python-Selenium-Action/generate)
37+
38+
- Run the action "Run Selenium On GitHub Action" which will print GitHub site title.
39+
40+
- Make changes as needed to the Python script <code>Selenium-Template.py</code>.
41+
42+
- If you change the name Selenium-Template.py - reflect the changes in the GitHub Action <code>Selenium-Action_Template.yaml</code> file.
43+
44+
- Make changes as needed to the <code>Selenium-Action_Template.yaml</code> file.
45+
46+
47+
<br>
48+
49+
#### Demo(s)
50+
51+
<p align="center">
52+
<img alt="" src="https://i.imgur.com/qtzEibg.png" width="500" height="320" />
53+
</p>
54+
55+
<div align="center">
56+
This image was taken via a <a href="https://github.com/features/actions">GitHub Action</a>
57+
</div>
58+
59+
<br>
60+
An example of the template sucessfully running on GitHub:
61+
<br>
62+
63+
- [Results From Successful Python Selenium Action](https://github.com/MarketingPipeline/Python-Selenium-Action/blob/main/GitHub_Action_Results.txt)
64+
65+
- [Successful Action Run](https://github.com/MarketingPipeline/Python-Selenium-Action/actions/runs/2412796846)
66+
67+
68+
69+
70+
## Contributing ![GitHub](https://img.shields.io/github/contributors/MarketingPipeline/Python-Selenium-Action)
71+
72+
Want to improve this? Create a pull request with detailed changes / improvements! If approved you will be added to the list of contributors of this awesome project!
73+
74+
75+
76+
See also the list of
77+
[contributors](https://github.com/MarketingPipeline/Python-Selenium-Action/graphs/contributors) who
78+
participate in this project.
79+
80+
## License ![GitHub](https://img.shields.io/github/license/MarketingPipeline/Python-Selenium-Action)
81+
82+
This project is licensed under the MIT License - see the
83+
[LICENSE.md](https://github.com/MarketingPipeline/Python-Selenium-Action/blob/main/LICENSE) file for
84+
details.
85+
86+

Selenium-Template.py

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
from datetime import datetime
2+
from selenium import webdriver
3+
from selenium.webdriver.chrome.options import Options
4+
from selenium.webdriver.chrome.service import Service
5+
import chromedriver_autoinstaller
6+
from pyvirtualdisplay import Display
7+
display = Display(visible=0, size=(800, 800))
8+
display.start()
9+
10+
chromedriver_autoinstaller.install() # Check if the current version of chromedriver exists
11+
# and if it doesn't exist, download it automatically,
12+
# then add chromedriver to path
13+
14+
chrome_options = webdriver.ChromeOptions()
15+
# Add your options as needed
16+
options = [
17+
# Define window size here
18+
"--window-size=1200,1200",
19+
"--ignore-certificate-errors"
20+
21+
#"--headless",
22+
#"--disable-gpu",
23+
#"--window-size=1920,1200",
24+
#"--ignore-certificate-errors",
25+
#"--disable-extensions",
26+
#"--no-sandbox",
27+
#"--disable-dev-shm-usage",
28+
#'--remote-debugging-port=9222'
29+
]
30+
31+
for option in options:
32+
chrome_options.add_argument(option)
33+
34+
35+
driver = webdriver.Chrome(options = chrome_options)
36+
37+
driver.get('http://github.com')
38+
print(driver.title)
39+
with open('./GitHub_Action_Results.txt', 'w') as f:
40+
string = f"This was written with a GitHub action {driver.title}"+"-"+str(datetime.now())
41+
f.write(string)

0 commit comments

Comments
 (0)