<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>The Ops Community ⚙️: Ricardo Del Rayo</title>
    <description>The latest articles on The Ops Community ⚙️ by Ricardo Del Rayo (@ricardo_delrayo).</description>
    <link>https://community.ops.io/ricardo_delrayo</link>
    <image>
      <url>https://community.ops.io/images/I-4Ey-Bbdk0cttt1i7mATdtz9Yzc8T-l5Lu-nRXbpyk/rs:fill:90:90/g:sm/mb:500000/ar:1/aHR0cHM6Ly9jb21t/dW5pdHkub3BzLmlv/L3JlbW90ZWltYWdl/cy91cGxvYWRzL3Vz/ZXIvcHJvZmlsZV9p/bWFnZS8xNjcvZTdh/MGJjYjQtNGQzZS00/MmM5LWI2NjUtMDM0/NGQxNTYwMzJiLmpw/Zw</url>
      <title>The Ops Community ⚙️: Ricardo Del Rayo</title>
      <link>https://community.ops.io/ricardo_delrayo</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://community.ops.io/feed/ricardo_delrayo"/>
    <language>en</language>
    <item>
      <title>Executing Selenium test with python(pytest) using GitHub Actions</title>
      <dc:creator>Ricardo Del Rayo</dc:creator>
      <pubDate>Thu, 26 May 2022 02:07:40 +0000</pubDate>
      <link>https://community.ops.io/ricardo_delrayo/executing-selenium-test-with-pythonpytest-using-github-actions-28l6</link>
      <guid>https://community.ops.io/ricardo_delrayo/executing-selenium-test-with-pythonpytest-using-github-actions-28l6</guid>
      <description>&lt;p&gt;&lt;a href="//delrayo.tech"&gt;&lt;img src="https://community.ops.io/images/HIHv2SdtXq6-KHUHMctZIEwKHdndvMrJcqGKBe4ERaw/w:880/mb:500000/ar:1/aHR0cHM6Ly9kZXYt/dG8tdXBsb2Fkcy5z/My5hbWF6b25hd3Mu/Y29tL3VwbG9hZHMv/YXJ0aWNsZXMvY21l/dWQ2YzVvZzFkaDN4/dmJlYnAucG5n" alt="DelRayo.tech" width="880" height="445"&gt;&lt;/a&gt;&lt;br&gt;
You can find the working project &lt;a href="https://github.com/delrayo/Pytest-Selenium-GitHubActions"&gt;Here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;First we are going to create some example tests.&lt;br&gt;
I'll be using selenium with python(pytest).&lt;/p&gt;

&lt;p&gt;So for this example ill be creating 2 files one will be called &lt;strong&gt;conftest.py&lt;/strong&gt; and the second one will be &lt;strong&gt;test_web01.py&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/delrayo/Pytest-Selenium-GitHubActions/blob/main/conftest.py"&gt;conftest.py in GitHub&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import pytest
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from webdriver_manager.utils import ChromeType
from selenium import webdriver


@pytest.fixture()
def setup(request):
    chrome_service = Service(ChromeDriverManager(chrome_type=ChromeType.GOOGLE).install())

    chrome_options = Options()
    options = [
    "--headless",
    "--disable-gpu",
    "--window-size=1920,1200",
    "--ignore-certificate-errors",
    "--disable-extensions",
    "--no-sandbox",
    "--disable-dev-shm-usage"
]
    for option in options:
        chrome_options.add_argument(option)

    request.cls.driver = webdriver.Chrome(service=chrome_service, options=chrome_options)


    yield request.cls.driver
    request.cls.driver.close()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now lets create the second file where the actual tests are. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/delrayo/Pytest-Selenium-GitHubActions/blob/main/test_web01.py"&gt;test_web01.py in GitHub&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import pytest


@pytest.mark.usefixtures("setup")
class TestExampleOne:
    def test_title(self):
        self.driver.get('https://www.delrayo.tech')
        assert self.driver.title == "DelRayo.tech - Delrayo Tech"

    def test_title_blog(self):
        self.driver.get('https://www.delrayo.tech/blog')
        print(self.driver.title)

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For running with GithubActions we have to create the following file structure on the repo.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;-.github&lt;/li&gt;
&lt;li&gt;--workflows&lt;/li&gt;
&lt;li&gt;---test01.yaml&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://github.com/delrayo/Pytest-Selenium-GitHubActions/blob/main/.github/workflows/test01.yml"&gt;test01.yaml in GitHub&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# .github/workflows/test01.yaml
name: test01
on:
  workflow_dispatch:  
jobs:
  test01:
    runs-on: ubuntu-latest
    steps:
      - name: Check out this repo
        uses: actions/checkout@v2
     #Setup Python   
      - name: Set up Python
        uses: actions/setup-python@v2
        with:
          python-version: '3.9'
      - name: Install software
        run: sudo apt-get install -y chromium-browser
      - name: Install the necessary packages
        run: pip install requests webdriver-manager selenium pytest
      - name: Run the PytTest script
        run: pytest -rA
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we just have to go to the actions section on github, select the workflow named test01 and click on the button run workflow.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://community.ops.io/images/FRMpzhNqLdq9NjvassyVniAyO30kZR4ovCuAockG8Po/w:880/mb:500000/ar:1/aHR0cHM6Ly9kZXYt/dG8tdXBsb2Fkcy5z/My5hbWF6b25hd3Mu/Y29tL3VwbG9hZHMv/YXJ0aWNsZXMvcWpn/dXI2MW5yZXVjZW5k/cm1xcnYucG5n" class="article-body-image-wrapper"&gt;&lt;img src="https://community.ops.io/images/FRMpzhNqLdq9NjvassyVniAyO30kZR4ovCuAockG8Po/w:880/mb:500000/ar:1/aHR0cHM6Ly9kZXYt/dG8tdXBsb2Fkcy5z/My5hbWF6b25hd3Mu/Y29tL3VwbG9hZHMv/YXJ0aWNsZXMvcWpn/dXI2MW5yZXVjZW5k/cm1xcnYucG5n" alt="GitHub Actions" width="880" height="353"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can configure this workflow to execute on different triggers modifying&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
on:
  workflow_dispatch:  

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With any of these &lt;a href="https://docs.github.com/es/actions/learn-github-actions/events-that-trigger-workflows"&gt;options&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://community.ops.io/images/COh8ijw0xTV-D8Zdwg96ldiG5ZbvfvikBkmcek929qc/w:880/mb:500000/ar:1/aHR0cHM6Ly9kZXYt/dG8tdXBsb2Fkcy5z/My5hbWF6b25hd3Mu/Y29tL3VwbG9hZHMv/YXJ0aWNsZXMvdzdq/YXAxdHdrZXFwaGU2/bDdyem4ucG5n" class="article-body-image-wrapper"&gt;&lt;img src="https://community.ops.io/images/COh8ijw0xTV-D8Zdwg96ldiG5ZbvfvikBkmcek929qc/w:880/mb:500000/ar:1/aHR0cHM6Ly9kZXYt/dG8tdXBsb2Fkcy5z/My5hbWF6b25hd3Mu/Y29tL3VwbG9hZHMv/YXJ0aWNsZXMvdzdq/YXAxdHdrZXFwaGU2/bDdyem4ucG5n" alt="Test Pass with GitHub Actions" width="880" height="334"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can find the working project &lt;a href="https://github.com/delrayo/Pytest-Selenium-GitHubActions"&gt;Here&lt;/a&gt;.&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
