Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
49 views15 pages

FYI Scripts

The document outlines the creation of Selenium tests for the FyiDoctors glasses collection page using pytest, detailing the directory structure, sample test scripts, and explanations for each test method. It also includes instructions for setting up a Bitbucket Pipeline to automate the testing process, ensuring continuous integration and deployment. Additionally, it describes the responsibilities and qualifications for a QA Software Engineer position in Calgary.

Uploaded by

waseemimran401
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views15 pages

FYI Scripts

The document outlines the creation of Selenium tests for the FyiDoctors glasses collection page using pytest, detailing the directory structure, sample test scripts, and explanations for each test method. It also includes instructions for setting up a Bitbucket Pipeline to automate the testing process, ensuring continuous integration and deployment. Additionally, it describes the responsibilities and qualifications for a QA Software Engineer position in Calgary.

Uploaded by

waseemimran401
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 15

Using this webpage https://fyidoctors.

com/ create some pratcicle navigation paths using


selenium and pytest write some testing scripts with explanation
ChatGPT

To create practical navigation paths using Selenium and pytest for the FyiDoctors website, we'll
write a set of test scripts that automate interactions with the site. The tests will cover basic
navigation paths like accessing the homepage, searching for services, and checking locations.

Prerequisites

Make sure you have the following installed:

 Python
 Selenium
 Pytest
 A web driver (like ChromeDriver) corresponding to your browser version

You can install Selenium and Pytest using pip:

bash
Copy code
pip install selenium pytest

Directory Structure

Create a directory structure like this:

bash
Copy code
/your_project_directory

├── tests/
│ └── test_navigation.py
└── requirements.txt

Sample Test Script: test_navigation.py

Here’s a sample test script that navigates the FyiDoctors website:

python
Copy code
import pytest
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
import time

class TestFyiDoctorsNavigation:
@pytest.fixture(scope="class")
def setup(self):
# Set up the Chrome driver
self.driver = webdriver.Chrome()
self.driver.get("https://fyidoctors.com")
self.driver.maximize_window()
yield
self.driver.quit()

def test_homepage_title(self, setup):


""" Test to verify the homepage title """
assert "FYidoctors" in self.driver.title

def test_search_services(self, setup):


""" Test to search for services on the homepage """
# Locate the search input field
search_box = self.driver.find_element(By.NAME, "search")
search_box.send_keys("Eye exam")
search_box.send_keys(Keys.RETURN)

time.sleep(2) # Wait for results to load

# Verify the results page title


assert "Search Results" in self.driver.title

def test_check_locations(self, setup):


""" Test to check the locations page """
# Click on the locations link
locations_link = self.driver.find_element(By.LINK_TEXT, "Locations")
locations_link.click()

time.sleep(2) # Wait for the page to load

# Verify the locations page title


assert "Locations" in self.driver.title

def test_navigate_to_services(self, setup):


""" Test to navigate to the services page """
services_link = self.driver.find_element(By.LINK_TEXT, "Services")
services_link.click()

time.sleep(2) # Wait for the page to load

# Verify the services page title


assert "Services" in self.driver.title

Explanation of the Test Script

1. Imports: We import necessary libraries from Selenium and Pytest.


2. Test Class: We define a class TestFyiDoctorsNavigation that contains our test
methods.
3. Fixture:
o The setup method initializes the Chrome WebDriver, opens the FyiDoctors
homepage, maximizes the browser window, and yields control to the test
methods.
o After the tests are completed, it closes the browser.
4. Test Methods:
o test_homepage_title: This method checks if the homepage title contains
"FYidoctors".
o test_search_services: This method simulates a search for "Eye exam". It
locates the search box, inputs the query, and checks if the resulting page title
contains "Search Results".
o test_check_locations: This method clicks on the "Locations" link and verifies
that the resulting page title contains "Locations".
o test_navigate_to_services: This method clicks on the "Services" link and
checks if the services page title contains "Services".

Running the Tests

To run the tests, navigate to the project directory in your terminal and execute:

bash
Copy code
pytest tests/test_navigation.py

Conclusion

This example demonstrates how to navigate the FyiDoctors website using Selenium and pytest.
You can expand upon this by adding more tests, improving assertions, handling exceptions, and
using more sophisticated wait strategies (like WebDriverWait) instead of time.sleep(). This
will make your tests more robust and efficient.

integrate using ci/cd bitbucket pipeline with explanation


ChatGPT

To integrate your Selenium and pytest tests with a Bitbucket Pipeline, you'll need to set up a
Bitbucket repository for your project and create a pipeline configuration file that defines how
your tests should be run in a CI/CD environment. Here's a step-by-step guide to help you do this:

Step 1: Set Up Your Bitbucket Repository

1. Create a Bitbucket Account: If you don't have one, sign up at Bitbucket.


2. Create a New Repository: Go to your Bitbucket dashboard and create a new repository
for your project.

Step 2: Add Your Project Files

1. Clone your Bitbucket repository to your local machine:

bash
Copy code
git clone
https://<your_username>@bitbucket.org/<your_username>/<your_repo_name>.g
it
cd <your_repo_name>

2. Add your existing project files (test_navigation.py and any other necessary files) to
this directory.
3. Create a requirements.txt file that lists the required packages:

plaintext
Copy code
selenium
pytest

4. Stage and commit your changes:

bash
Copy code
git add .
git commit -m "Initial commit with test scripts"
git push origin master

Step 3: Create the Bitbucket Pipeline Configuration

1. In the root of your repository, create a file named bitbucket-pipelines.yml.


2. Add the following configuration to the bitbucket-pipelines.yml file:

yaml
Copy code
image: python:3.9 # Use the official Python image

pipelines:
default:
- step:
name: Run Selenium Tests
services:
- chrome # Use the Chrome service
script:
- apt-get update && apt-get install -y wget unzip # Install
required packages
- wget
https://chromedriver.storage.googleapis.com/114.0.5735.90/chromedriver_l
inux64.zip # Download ChromeDriver
- unzip chromedriver_linux64.zip # Unzip ChromeDriver
- mv chromedriver /usr/local/bin/ # Move it to the local bin
- pip install -r requirements.txt # Install Python
dependencies
- pytest tests/test_navigation.py # Run the tests

definitions:
services:
chrome:
image: selenium/standalone-chrome # Use the Selenium standalone
Chrome service

Explanation of the Pipeline Configuration

1. Image: We specify the base image for the pipeline as python:3.9, which contains
Python and pip.
2. Pipelines Section:
o We define a default pipeline that will run on every push to the master branch.
o Inside the pipeline, we define a step which contains the following:
 Name: A descriptive name for the step.
 Services: We specify that we want to use the chrome service, which
allows us to run tests that require a browser.
3. Script Section:
o apt-get update && apt-get install -y wget unzip: We update the
package list and install wget and unzip to download and extract the
ChromeDriver.
o wget https://chromedriver.storage.googleapis.com/...: We download
the ChromeDriver matching the version of Chrome in the Selenium image. (Make
sure to check the latest version of ChromeDriver here).
o unzip chromedriver_linux64.zip: We extract the downloaded ChromeDriver.
o mv chromedriver /usr/local/bin/: We move the ChromeDriver to the
appropriate location.
o pip install -r requirements.txt: We install the required Python packages
listed in requirements.txt.
o pytest tests/test_navigation.py: Finally, we run the pytest command to
execute the tests.
4. Definitions Section:
o We define services used in the pipeline. Here, we specify the
selenium/standalone-chrome image, which provides a pre-configured
environment to run Selenium tests with Chrome.

Step 4: Push Your Changes and Trigger the Pipeline

1. After creating the bitbucket-pipelines.yml file, stage and commit your changes:

bash
Copy code
git add bitbucket-pipelines.yml
git commit -m "Add Bitbucket Pipeline configuration"
git push origin master

2. Go to your Bitbucket repository in a web browser. Navigate to Pipelines in the left


sidebar, and you should see the pipeline triggered automatically.
3. Monitor the output logs to see if your tests pass or fail. You can click on each step to get
detailed logs.
Conclusion

You have successfully integrated your Selenium and pytest tests with a Bitbucket Pipeline. This
setup will allow you to run your tests automatically every time you push changes to your
repository, ensuring that your code remains functional and reliable. You can further customize
your pipeline by adding more steps, notifications, or deploying to your environment based on the
success or failure of the tests.

Repeat the same for this webpage from the beginning https://fyidoctors.com/collections/glasses
ChatGPT

Sure! Let's create practical navigation paths for the FyiDoctors glasses collection page using
Selenium and pytest, and then integrate it into a Bitbucket Pipeline for CI/CD. Below are the
detailed steps for each part of the process.

Step 1: Create Selenium Tests for Glasses Collection

Directory Structure

Ensure your project directory has the following structure:

bash
Copy code
/your_project_directory

├── tests/
│ └── test_glasses_navigation.py
└── requirements.txt

Sample Test Script: test_glasses_navigation.py

Here's how to create a test script that interacts with the FyiDoctors glasses collection page:

python
Copy code
import pytest
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
import time

class TestFyiDoctorsGlasses:
@pytest.fixture(scope="class")
def setup(self):
# Set up the Chrome driver
self.driver = webdriver.Chrome()
self.driver.get("https://fyidoctors.com/collections/glasses")
self.driver.maximize_window()
yield
self.driver.quit()
def test_glasses_page_title(self, setup):
""" Test to verify the glasses collection page title """
assert "Glasses" in self.driver.title

def test_search_for_specific_glasses(self, setup):


""" Test to search for specific glasses on the collection page """
search_box = self.driver.find_element(By.NAME, "search")
search_box.send_keys("Ray-Ban")
search_box.send_keys(Keys.RETURN)

time.sleep(2) # Wait for results to load

# Verify the results contain the searched term


results = self.driver.find_elements(By.CLASS_NAME, "product-title")
assert any("Ray-Ban" in result.text for result in results)

def test_check_filters(self, setup):


""" Test to check filters for glasses collection """
# Example: Click on a specific filter (like "Men" or "Women")
men_filter = self.driver.find_element(By.XPATH,
"//label[contains(text(),'Men')]")
men_filter.click()

time.sleep(2) # Wait for the filtered results to load

# Verify that the results contain 'Men' in the product titles


results = self.driver.find_elements(By.CLASS_NAME, "product-title")
assert all("Men" in result.text for result in results)

def test_navigate_to_glasses_details(self, setup):


""" Test to navigate to a specific glasses product details page """
first_product = self.driver.find_element(By.CLASS_NAME, "product-
title")
first_product.click()

time.sleep(2) # Wait for the product page to load

# Verify that the product page is displayed


assert "Glasses" in self.driver.title

Explanation of the Test Script

1. Imports: Import necessary libraries from Selenium and Pytest.


2. Test Class: Define a class TestFyiDoctorsGlasses for our test methods.
3. Fixture:
o The setup method initializes the Chrome WebDriver, opens the FyiDoctors
glasses collection page, maximizes the window, and yields control to the test
methods. It closes the browser after tests.
4. Test Methods:
o test_glasses_page_title: Checks if the glasses collection page title contains
"Glasses".
o test_search_for_specific_glasses: Searches for "Ray-Ban" in the search
box and verifies that the results contain the term "Ray-Ban".
o test_check_filters: Clicks on the "Men" filter and verifies that all displayed
products include "Men" in their titles.
o test_navigate_to_glasses_details: Clicks on the first product and verifies
that the product details page is displayed.

Step 2: Create requirements.txt

Create a requirements.txt file with the following content:

plaintext
Copy code
selenium
pytest

Step 3: Set Up Bitbucket Pipeline

1. Create the Bitbucket Pipeline Configuration File: In the root of your repository, create
a file named bitbucket-pipelines.yml.
2. Add the following configuration to the bitbucket-pipelines.yml file:

yaml
Copy code
image: python:3.9 # Use the official Python image

pipelines:
default:
- step:
name: Run Selenium Tests for Glasses
services:
- chrome # Use the Chrome service
script:
- apt-get update && apt-get install -y wget unzip # Install
required packages
- wget
https://chromedriver.storage.googleapis.com/114.0.5735.90/chromedriver_l
inux64.zip # Download ChromeDriver
- unzip chromedriver_linux64.zip # Unzip ChromeDriver
- mv chromedriver /usr/local/bin/ # Move it to the local bin
- pip install -r requirements.txt # Install Python
dependencies
- pytest tests/test_glasses_navigation.py # Run the tests

definitions:
services:
chrome:
image: selenium/standalone-chrome # Use the Selenium standalone
Chrome service

Explanation of the Pipeline Configuration


1. Image: Specifies the base image as python:3.9.
2. Pipelines Section:
o Defines a default pipeline that runs on every push to the master branch.
o The step includes a service for Chrome.
3. Script Section:
o Updates package lists and installs wget and unzip.
o Downloads and unzips the appropriate version of ChromeDriver.
o Moves the ChromeDriver to the local bin.
o Installs Python dependencies.
o Runs the pytest command for the glasses navigation tests.
4. Definitions Section:
o Defines the chrome service using the selenium/standalone-chrome image.

Step 4: Push Your Changes to Bitbucket

1. After creating the test script and the pipeline configuration, stage and commit your
changes:

bash
Copy code
git add .
git commit -m "Add Selenium tests for glasses collection and Bitbucket
Pipeline"
git push origin master

2. Navigate to your Bitbucket repository in a web browser. Go to Pipelines in the left


sidebar, and you should see the pipeline triggered automatically.
3. Monitor the output logs to see if your tests pass or fail.

Conclusion

You have successfully created Selenium tests for the FyiDoctors glasses collection page,
integrated them with pytest, and set up a Bitbucket Pipeline for CI/CD. This configuration
ensures that your tests are run automatically whenever you push changes to the repository,
helping maintain the reliability of your application. You can enhance this setup by adding more
tests, adjusting the pipeline to include notifications, or deploying your application based on test
results.

Quality Assurance Software Engineer


Calgary

Join our dynamic team as a QA Software Engineer! In this role you’ll be developing and
executing comprehensive automated test plans and cases for all software projects.
You’ll increase automated testing coverage and ensure continuity of features through
new releases and code changes. You’ll increase the availability and reliability of
automated test suites, ensuring comprehensive validation of new code.
What Will We You Be Doing?

 Creating, building and integrating automated test suites across all proprietary
software, ensuring comprehensive coverage and validation of all functionalities.
 Identifying, recording, and managing software defects, ensuring timely resolution
of fixed issues.
 Actively participating in code reviews to provide insights on testing capabilities
and ensuring code quality.
 Maintaining and updating automated testing scripts using tools like PyTest or
NUnit to enhance testing efficiency.
 Collaborating with DevOps engineers to integrate automated tests into the
continuous integration/continuous deployment (CI/CD) pipeline.
 Providing regular updates on testing progress, issues, and risks to the QA Team
Lead and other stakeholders.

As The Successful Candidate You Have:

 A minimum of 3 years of experience in software quality assurance and


automated testing.
 A Bachelor’s degree in Computer Science, Information Technology, or a related
field.
 Experience with automated testing tools and frameworks (e.g., PyTest, NUnit).
 Solid programming skills in languages such as C#, Python, or similar.
 Familiarity with CI/CD tools and processes (e.g., TeamCity, Bitbucket Pipelines).
 Ability to review code and provide insights on testing capabilities of new code
blocks.
 Certifications in software testing (e.g., ISTQB, CSTE) is considered an asset.
 Bilingualism French/English is considered an asset.

How You'll Benefit working at our Home Office:

 A comprehensive total rewards package, including two free pairs of glasses and
lenses per year
 A coaching culture that fosters ongoing growth and development opportunities
 A people-first culture, (but dogs are also welcome)
 An organization that gives back locally and nationally, and supports you in doing
so as well

Why You Should Join Us:


Our purpose is to enhance the lives of our patients. If you get excited by the opportunity
to be part of a team that strives to put the patients at the center of everything we do,
and have fun while doing it, then you belong with us! Our doctor-led, patient first,
approach has helped us rapidly grow from 30 locations to over 300!
We could not have gotten here without our fantastic people, who now number more
than 3,000 and serve patients across the country. We are committed to FYihealth group
being more than just a place to work and are intentional about our values of
opportunity, diversity, equity and inclusion in the environment we create for our team
members to thrive.
At FYi, we hope you'll grow as a professional and as an individual, knowing you can
come to work each day, have a meaningful impact on people's lives and have fun doing
it.
Thank you so much for your interest in this role and FYihealth group. We appreciate the
time it takes to read and apply, and we don't take your application lightly. Hopefully,
you're a fit, and if so, we look forward to chatting with you in person and telling you
more about us and this opportunity.

use the below webpage and create an automation script using selenium with python and navigate
the actions and Test it with results https://fyidoctors.com/pages/children-s-eye-exam
ChatGPT

To create an automation script using Selenium in Python that interacts with the provided
webpage, you can follow the steps below. This script will navigate to the specified URL, perform
actions on the webpage, and print the results.

Prerequisites

1. Install Python: Make sure you have Python installed on your system.
2. Install Selenium: You can install Selenium using pip:

bash
Copy code
pip install selenium

3. WebDriver: Download the appropriate WebDriver for your browser (e.g., ChromeDriver
for Chrome) and make sure it is accessible from your system's PATH.

Sample Automation Script

Here is a basic script that navigates to the specified URL, extracts some relevant information,
and prints it. The actions can be customized based on what you want to test.

python
Copy code
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time
# Set up the WebDriver (ensure you have the correct path for your WebDriver)
driver = webdriver.Chrome() # or webdriver.Firefox(), etc.

try:
# Navigate to the webpage
driver.get("https://fyidoctors.com/pages/children-s-eye-exam")

# Wait for the page to load completely


WebDriverWait(driver,
10).until(EC.presence_of_element_located((By.TAG_NAME, "h1")))

# Example of extracting the title of the page


title = driver.title
print(f"Page Title: {title}")

# Example: Locate and print the content of the first paragraph


first_paragraph = WebDriverWait(driver,
10).until(EC.presence_of_element_located((By.CSS_SELECTOR, "p")))
print(f"First Paragraph: {first_paragraph.text}")

# Example: Click on a button or link if exists (adjust selector as needed)


# Uncomment and modify the line below if there's a specific button to
click
# button = driver.find_element(By.XPATH, "//a[contains(text(),'Learn
More')]")
# button.click()

# Wait and gather some results or details based on navigation


time.sleep(5) # Wait for a few seconds to observe the actions (if any)

# Example: Find all the sections about eye exams and print them
sections = driver.find_elements(By.CSS_SELECTOR, ".section-content h3")
print("Sections about Eye Exams:")
for section in sections:
print(section.text)

finally:
# Close the WebDriver
driver.quit()

Explanation

1. Setup: The script initializes a Selenium WebDriver (in this case, Chrome).
2. Navigation: It navigates to the given URL and waits for the page to load.
3. Extracting Information: It retrieves and prints the title of the page and the text of the
first paragraph.
4. Interaction: If there’s a button or link you want to interact with, you can uncomment and
modify the relevant part of the script.
5. Gathering Additional Data: It extracts all sections related to eye exams and prints their
headers.
6. Cleanup: Finally, it ensures that the WebDriver is closed properly.

Testing the Script


1. Make sure your WebDriver is compatible with your browser version.
2. Run the script in your Python environment.
3. Observe the printed outputs in your console for the results.

Feel free to modify the script based on your specific needs, such as interacting with different
elements or extracting more data.

now create a ci/cd pipeline and store the test in that pipeline using bitbucket
ChatGPT

Creating a CI/CD pipeline to automate the testing of a Selenium script using Bitbucket involves
several steps. Here's a comprehensive guide to set up the pipeline with Bitbucket Pipelines.

Step 1: Prepare Your Project Structure

1. Create a New Repository: If you haven’t already, create a new repository in Bitbucket.
2. Clone the Repository: Clone it to your local machine.

bash
Copy code
git clone https://bitbucket.org/username/repository-name.git
cd repository-name

3. Create the Project Structure: Inside your repository, create a directory for your
Selenium tests.

bash
Copy code
mkdir selenium_tests
cd selenium_tests
touch test_script.py

4. Write Your Selenium Test: Place your Selenium test script in test_script.py. Here’s
a sample:

python
Copy code
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import unittest

class TestChildrenEyeExamPage(unittest.TestCase):

def setUp(self):
self.driver = webdriver.Chrome() # Use headless mode if
necessary for CI/CD
self.driver.implicitly_wait(10) # Wait for elements to load

def test_page_title(self):
self.driver.get("https://fyidoctors.com/pages/children-s-eye-
exam")
self.assertIn("Children's Eye Exam", self.driver.title)

def test_first_paragraph(self):
self.driver.get("https://fyidoctors.com/pages/children-s-eye-
exam")
first_paragraph = WebDriverWait(self.driver, 10).until(
EC.presence_of_element_located((By.CSS_SELECTOR, "p"))
)
self.assertTrue(len(first_paragraph.text) > 0)

def tearDown(self):
self.driver.quit()

if __name__ == "__main__":
unittest.main()

Step 2: Configure Bitbucket Pipelines

1. Create a bitbucket-pipelines.yml File: In the root of your repository, create a file


named bitbucket-pipelines.yml.

bash
Copy code
touch bitbucket-pipelines.yml

2. Define Your Pipeline: Add the following configuration to the bitbucket-


pipelines.yml file:

yaml
Copy code
image: python:3.8 # Use the Python version of your choice

pipelines:
default:
- step:
name: Install dependencies
script:
- pip install selenium
- apt-get update
- apt-get install -y chromium-driver
- pip install webdriver-manager

- step:
name: Run Selenium Tests
script:
- python -m unittest discover -s selenium_tests

Step 3: Adjust WebDriver Configuration for CI/CD

To run the tests in a CI/CD environment, you'll need to use a headless browser. You can modify
your test_script.py to configure Chrome to run in headless mode.
Update the setUp method in your test script like this:

python
Copy code
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager

class TestChildrenEyeExamPage(unittest.TestCase):

def setUp(self):
options = webdriver.ChromeOptions()
options.add_argument('--headless') # Run in headless mode
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')

self.driver =
webdriver.Chrome(service=Service(ChromeDriverManager().install()),
options=options)
self.driver.implicitly_wait(10)

Step 4: Push Changes to Bitbucket

1. Add, Commit, and Push Your Changes:

bash
Copy code
git add .
git commit -m "Add Selenium tests and pipeline configuration"
git push origin master

Step 5: View Pipeline Results

1. Access Your Bitbucket Repository: Go to your Bitbucket repository in a web browser.


2. Navigate to the Pipelines Section: You should see a Pipelines tab on the left. Click on it
to view the status of your pipeline.
3. Check the Logs: Click on the latest pipeline run to see the logs and ensure that your tests
executed correctly.

Summary

By following these steps, you’ve created a CI/CD pipeline in Bitbucket that automatically runs
your Selenium tests every time you push changes to your repository. This setup ensures that your
tests are consistently run and helps maintain code quality.

Feel free to customize the pipeline further based on your project’s requirements, such as adding
more test cases, different environments, or notifications.

You might also like