From 53dc5ec1085c921a5bbde2b02d8c8463c732b9b8 Mon Sep 17 00:00:00 2001 From: Hammad1007 Date: Wed, 17 Jan 2024 18:59:58 +0500 Subject: [PATCH 1/5] Install cypress and write tests --- theme-clock/cypress.config.js | 9 +++ theme-clock/cypress/e2e/test1.spec.cy.js | 93 +++++++++++++++++++++++ theme-clock/cypress/fixtures/example.json | 5 ++ theme-clock/cypress/support/commands.js | 25 ++++++ theme-clock/cypress/support/e2e.js | 20 +++++ 5 files changed, 152 insertions(+) create mode 100644 theme-clock/cypress.config.js create mode 100644 theme-clock/cypress/e2e/test1.spec.cy.js create mode 100644 theme-clock/cypress/fixtures/example.json create mode 100644 theme-clock/cypress/support/commands.js create mode 100644 theme-clock/cypress/support/e2e.js diff --git a/theme-clock/cypress.config.js b/theme-clock/cypress.config.js new file mode 100644 index 0000000..97f47c4 --- /dev/null +++ b/theme-clock/cypress.config.js @@ -0,0 +1,9 @@ +const { defineConfig } = require("cypress"); + +module.exports = defineConfig({ + e2e: { + setupNodeEvents(on, config) { + // implement node event listeners here + }, + }, +}); diff --git a/theme-clock/cypress/e2e/test1.spec.cy.js b/theme-clock/cypress/e2e/test1.spec.cy.js new file mode 100644 index 0000000..b74096a --- /dev/null +++ b/theme-clock/cypress/e2e/test1.spec.cy.js @@ -0,0 +1,93 @@ +describe('Project Theme Clock', () => { + beforeEach(() => { + cy.visit('http://127.0.0.1:5500/theme-clock/index.html') + }) + + it('Opens the homepage', () => { + + }) + + it('The screen is visible', () => { + cy.get('body').should('be.visible') + }) + + context('Body', () => { + context('Background', () => { + it('The background is visible', () => { + cy.get('body').should('be.visible') + }) + + it('The background has correct color', () => { + cy.get('body').should('be.visible').should('have.css', 'background-color', 'rgba(0, 0, 0, 0)') + }) + }) + + context('Content', () => { + it('The clock container is visible', () => { + cy.get('.clock-container').should('be.visible') + }) + + context('Clock', () => { + it('The clock container has the clock displayed', () => { + cy.get('.clock-container .clock').should('be.visible') + }) + + context('Needles', () => { + + it('The clock container has the hour needle', () => { + cy.get('.clock-container .clock .needle.hour').should('be.visible') + }) + + it('The clock container has the minute needle', () => { + cy.get('.clock-container .clock .needle.minute').should('be.visible') + }) + + it('The clock container has the second needle', () => { + cy.get('.clock-container .clock .needle.second').should('be.visible') + }) + + it('The clock container has the center point', () => { + cy.get('.center-point').should('be.visible') + }) + }) + + context('Text Time', () => { + it('The time is being displayed in text format as well', () => { + cy.get('.time').should('be.visible') + }) + + it('The current time is being displayed', () => { + const currentTime = new Date() + var hours = currentTime.getHours() + const minutes = currentTime.getMinutes() + const meridiem = hours >= 12 ? 'PM' : 'AM' + + hours = hours % 12 || 12; + + const formattedTime = `${hours}:${minutes} ${meridiem}`; + + cy.get('.time').should('have.text', formattedTime); + }) + }) + + context('Day, month, date', () => { + it('The date is visible', () => { + cy.get('.date').should('be.visible') + }) + + it('The date, month and day is visible', () => { + const currentDate = new Date(); + const day = currentDate.getDay(); + const month = currentDate.getMonth(); + const date = currentDate.getDate(); + + const days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]; + const months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]; + + cy.get('.date').should('have.text', `${days[day]}, ${months[month]} ${date}`); + }) + }) + }) + }) + }) +}) \ No newline at end of file diff --git a/theme-clock/cypress/fixtures/example.json b/theme-clock/cypress/fixtures/example.json new file mode 100644 index 0000000..02e4254 --- /dev/null +++ b/theme-clock/cypress/fixtures/example.json @@ -0,0 +1,5 @@ +{ + "name": "Using fixtures to represent data", + "email": "hello@cypress.io", + "body": "Fixtures are a great way to mock data for responses to routes" +} diff --git a/theme-clock/cypress/support/commands.js b/theme-clock/cypress/support/commands.js new file mode 100644 index 0000000..66ea16e --- /dev/null +++ b/theme-clock/cypress/support/commands.js @@ -0,0 +1,25 @@ +// *********************************************** +// This example commands.js shows you how to +// create various custom commands and overwrite +// existing commands. +// +// For more comprehensive examples of custom +// commands please read more here: +// https://on.cypress.io/custom-commands +// *********************************************** +// +// +// -- This is a parent command -- +// Cypress.Commands.add('login', (email, password) => { ... }) +// +// +// -- This is a child command -- +// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... }) +// +// +// -- This is a dual command -- +// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... }) +// +// +// -- This will overwrite an existing command -- +// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... }) \ No newline at end of file diff --git a/theme-clock/cypress/support/e2e.js b/theme-clock/cypress/support/e2e.js new file mode 100644 index 0000000..0e7290a --- /dev/null +++ b/theme-clock/cypress/support/e2e.js @@ -0,0 +1,20 @@ +// *********************************************************** +// This example support/e2e.js is processed and +// loaded automatically before your test files. +// +// This is a great place to put global configuration and +// behavior that modifies Cypress. +// +// You can change the location of this file or turn off +// automatically serving support files with the +// 'supportFile' configuration option. +// +// You can read more here: +// https://on.cypress.io/configuration +// *********************************************************** + +// Import commands.js using ES2015 syntax: +import './commands' + +// Alternatively you can use CommonJS syntax: +// require('./commands') \ No newline at end of file From f167f4315189069291d1945a7316be33a6050b6e Mon Sep 17 00:00:00 2001 From: Hammad1007 Date: Wed, 17 Jan 2024 19:21:18 +0500 Subject: [PATCH 2/5] Write tests using xpath and locator elements --- theme-clock/cypress/e2e/test1.spec.cy.js | 69 ++++++++++++++++++++++-- theme-clock/cypress/support/commands.js | 4 +- 2 files changed, 69 insertions(+), 4 deletions(-) diff --git a/theme-clock/cypress/e2e/test1.spec.cy.js b/theme-clock/cypress/e2e/test1.spec.cy.js index b74096a..7211971 100644 --- a/theme-clock/cypress/e2e/test1.spec.cy.js +++ b/theme-clock/cypress/e2e/test1.spec.cy.js @@ -27,6 +27,63 @@ describe('Project Theme Clock', () => { cy.get('.clock-container').should('be.visible') }) + context('Dark Mode button', () => { + it('The button is visible', () => { + cy.get('.toggle').should('be.visible') + }) + + it('The button has correct background color', () => { + cy.get('.toggle').should('be.visible').should('have.css', 'background-color', 'rgb(0, 0, 0)') + }) + + it('The button should have correct text', () => { + cy.get('.toggle').should('be.visible').should('have.text', 'Dark mode') + }) + + it('The button is clickable', () => { + cy.get('.toggle').should('be.visible').click() + }) + + context('Dark mode button toggle', () => { + it('The button is clickable', () => { + cy.get('.toggle').should('be.visible').click() + cy.get('.toggle').should('be.visible').should('have.text', 'Light mode') + }) + + it('When the button is clicked, the background color turns black', () => { + cy.get('.toggle').should('be.visible').click() + cy.xpath('//html[@class="dark"]').should('be.visible') + }) + + it('The color of the button is correct', () => { + cy.get('.toggle').should('be.visible').click() + cy.xpath('//html[@class="dark"]').should('be.visible') + cy.get('.toggle').should('have.css', 'background-color', 'rgb(255, 255, 255)') + }) + + it('The text time has white color', () => { + cy.get('.toggle').should('be.visible').click() + const currentTime = new Date() + var hours = currentTime.getHours() + const minutes = currentTime.getMinutes() + const meridiem = hours >= 12 ? 'PM' : 'AM' + + hours = hours % 12 || 12 + // Format minutes to have leading zero if less than 10 + const formattedMinutes = minutes < 10 ? `0${minutes}` : minutes + + const formattedTime = `${hours}:${formattedMinutes} ${meridiem}` + + cy.get('.time').should('have.text', formattedTime).should('have.css', 'color', 'rgb(255, 255, 255)') + }) + + it('The span circle color is white', () => { + cy.get('.toggle').should('be.visible').click() + cy.get('.circle').should('have.css', 'background-color', 'rgb(255, 255, 255)') + }) + }) + }) + context('Clock', () => { it('The clock container has the clock displayed', () => { cy.get('.clock-container .clock').should('be.visible') @@ -62,11 +119,13 @@ describe('Project Theme Clock', () => { const minutes = currentTime.getMinutes() const meridiem = hours >= 12 ? 'PM' : 'AM' - hours = hours % 12 || 12; + hours = hours % 12 || 12 + // Format minutes to have leading zero if less than 10 + const formattedMinutes = minutes < 10 ? `0${minutes}` : minutes - const formattedTime = `${hours}:${minutes} ${meridiem}`; + const formattedTime = `${hours}:${formattedMinutes} ${meridiem}` - cy.get('.time').should('have.text', formattedTime); + cy.get('.time').should('have.text', formattedTime) }) }) @@ -86,6 +145,10 @@ describe('Project Theme Clock', () => { cy.get('.date').should('have.text', `${days[day]}, ${months[month]} ${date}`); }) + + it('The span circle color is black', () => { + cy.get('.circle').should('have.css', 'background-color', 'rgb(0, 0, 0)') + }) }) }) }) diff --git a/theme-clock/cypress/support/commands.js b/theme-clock/cypress/support/commands.js index 66ea16e..cc02d1e 100644 --- a/theme-clock/cypress/support/commands.js +++ b/theme-clock/cypress/support/commands.js @@ -22,4 +22,6 @@ // // // -- This will overwrite an existing command -- -// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... }) \ No newline at end of file +// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... }) + +import 'cypress-xpath'; \ No newline at end of file From d92de05e86251e1389a63644724c67ee39c5c3ed Mon Sep 17 00:00:00 2001 From: Hammad1007 Date: Wed, 17 Jan 2024 19:58:58 +0500 Subject: [PATCH 3/5] Update the test code --- theme-clock/cypress/e2e/test1.spec.cy.js | 6 ------ 1 file changed, 6 deletions(-) diff --git a/theme-clock/cypress/e2e/test1.spec.cy.js b/theme-clock/cypress/e2e/test1.spec.cy.js index 7211971..098f114 100644 --- a/theme-clock/cypress/e2e/test1.spec.cy.js +++ b/theme-clock/cypress/e2e/test1.spec.cy.js @@ -67,13 +67,9 @@ describe('Project Theme Clock', () => { var hours = currentTime.getHours() const minutes = currentTime.getMinutes() const meridiem = hours >= 12 ? 'PM' : 'AM' - hours = hours % 12 || 12 - // Format minutes to have leading zero if less than 10 const formattedMinutes = minutes < 10 ? `0${minutes}` : minutes - const formattedTime = `${hours}:${formattedMinutes} ${meridiem}` - cy.get('.time').should('have.text', formattedTime).should('have.css', 'color', 'rgb(255, 255, 255)') }) @@ -118,9 +114,7 @@ describe('Project Theme Clock', () => { var hours = currentTime.getHours() const minutes = currentTime.getMinutes() const meridiem = hours >= 12 ? 'PM' : 'AM' - hours = hours % 12 || 12 - // Format minutes to have leading zero if less than 10 const formattedMinutes = minutes < 10 ? `0${minutes}` : minutes const formattedTime = `${hours}:${formattedMinutes} ${meridiem}` From 1eb3737e817c660aa56d0755e4bfc61110b1aa73 Mon Sep 17 00:00:00 2001 From: Hammad1007 Date: Thu, 18 Jan 2024 12:00:45 +0500 Subject: [PATCH 4/5] Install selenium and write tests for theme clock --- theme-clock/tests/body/button/test_button.py | 39 ++++++++++++++++ .../tests/body/button/test_darkmode.py | 37 ++++++++++++++++ .../tests/body/clock/date/test_date.py | 44 +++++++++++++++++++ theme-clock/tests/body/clock/test_clock.py | 27 ++++++++++++ .../tests/body/clock/time/test_time.py | 37 ++++++++++++++++ .../tests/body/clock/timepiece/test_hour.py | 31 +++++++++++++ .../tests/body/clock/timepiece/test_minute.py | 31 +++++++++++++ .../tests/body/clock/timepiece/test_second.py | 31 +++++++++++++ .../body/clock/timepiece/test_timepiece.py | 27 ++++++++++++ theme-clock/tests/body/test_body.py | 31 +++++++++++++ theme-clock/tests/test_body.py | 27 ++++++++++++ theme-clock/tests/test_browser.py | 20 +++++++++ 12 files changed, 382 insertions(+) create mode 100644 theme-clock/tests/body/button/test_button.py create mode 100644 theme-clock/tests/body/button/test_darkmode.py create mode 100644 theme-clock/tests/body/clock/date/test_date.py create mode 100644 theme-clock/tests/body/clock/test_clock.py create mode 100644 theme-clock/tests/body/clock/time/test_time.py create mode 100644 theme-clock/tests/body/clock/timepiece/test_hour.py create mode 100644 theme-clock/tests/body/clock/timepiece/test_minute.py create mode 100644 theme-clock/tests/body/clock/timepiece/test_second.py create mode 100644 theme-clock/tests/body/clock/timepiece/test_timepiece.py create mode 100644 theme-clock/tests/body/test_body.py create mode 100644 theme-clock/tests/test_body.py create mode 100644 theme-clock/tests/test_browser.py diff --git a/theme-clock/tests/body/button/test_button.py b/theme-clock/tests/body/button/test_button.py new file mode 100644 index 0000000..372cb7d --- /dev/null +++ b/theme-clock/tests/body/button/test_button.py @@ -0,0 +1,39 @@ +from selenium import webdriver +from selenium.webdriver.common.by import By +from selenium.webdriver.chrome.service import Service +from selenium.webdriver.chrome.options import Options +from selenium.webdriver.support.ui import WebDriverWait +from selenium.webdriver.support import expected_conditions as EC + +# Define Chrome WebDriver options +chrome_options = Options() +service = Service('/Users/mac005/Downloads/chromedriver-mac-arm64/chromedriver') + +# Initialize Chrome WebDriver +driver = webdriver.Chrome(service=service, options=chrome_options) +# Open the Flask application +driver.get('http://127.0.0.1:5500/theme-clock/index.html') + +# Find and click the button +button = driver.find_element(By.XPATH, '/html/body/button') +button.click() + +# Wait for the changes to take effect (adjust wait time as needed) +try: + # Find the new button after the changes + button = driver.find_element(By.XPATH, '/html/body/button') + + # Retrieve properties + text = button.text + background_color = button.value_of_css_property('background-color') + text_color = button.value_of_css_property('color') + + print(f'The text in the button is {text}') + print(f'The button background color is {background_color}') + print(f'The text color is {text_color}') + +except Exception as e: + print(f"An error occurred: {e}") + +# Close the browser window +driver.quit() diff --git a/theme-clock/tests/body/button/test_darkmode.py b/theme-clock/tests/body/button/test_darkmode.py new file mode 100644 index 0000000..3470d1e --- /dev/null +++ b/theme-clock/tests/body/button/test_darkmode.py @@ -0,0 +1,37 @@ +from selenium import webdriver +import time +from selenium.webdriver.chrome.service import Service +from selenium.webdriver.common.by import By +from selenium.webdriver.common.keys import Keys +from selenium.webdriver.chrome.options import Options + +# Define Chrome WebDriver options +chrome_options = Options() +service = Service('/Users/mac005/Downloads/chromedriver-mac-arm64/chromedriver') + +# Initialize Chrome WebDriver +driver = webdriver.Chrome(service=service, options=chrome_options) +# Open the Flask application +driver.get('http://127.0.0.1:5500/theme-clock/index.html') + +element = driver.find_element(By.XPATH, '/html/body/button') + +text = element.text + +background_color = element.value_of_css_property('background-color') + +text_color = element.value_of_css_property('color') + +if element: + print('The button is found') +else: + print('The button has not been found') + +print(f'The text in buton is {text}') + +print(f'The button background color is {background_color}') + +print(f'The text color is {text_color}') + +# Close the browser window +driver.quit() \ No newline at end of file diff --git a/theme-clock/tests/body/clock/date/test_date.py b/theme-clock/tests/body/clock/date/test_date.py new file mode 100644 index 0000000..4716d09 --- /dev/null +++ b/theme-clock/tests/body/clock/date/test_date.py @@ -0,0 +1,44 @@ +from selenium import webdriver +import time +from selenium.webdriver.chrome.service import Service +from selenium.webdriver.common.by import By +from selenium.webdriver.common.keys import Keys +from selenium.webdriver.chrome.options import Options + +# Define Chrome WebDriver options +chrome_options = Options() +service = Service('/Users/mac005/Downloads/chromedriver-mac-arm64/chromedriver') + +# Initialize Chrome WebDriver +driver = webdriver.Chrome(service=service, options=chrome_options) +# Open the Flask application +driver.get('http://127.0.0.1:5500/theme-clock/index.html') + +element = driver.find_element(By.XPATH, '/html/body/div[1]/div[3]') + +date_element = driver.find_element(By.XPATH, '/html/body/div[1]/div[3]/span') + +text = element.text + +background_color = element.value_of_css_property('background-color') + +color = element.value_of_css_property('color') + +time.sleep(3) + +if element: + print('The complete date is found') +else: + print('The complete date is not found') + +if date_element: + print('The date has been found') +else: + print('The date hasn\'t been found') + +print(f'Date is {text}') +print(f'Background Color is {background_color}') +print(f'Text color is {color}') + +# Close the browser window +driver.quit() \ No newline at end of file diff --git a/theme-clock/tests/body/clock/test_clock.py b/theme-clock/tests/body/clock/test_clock.py new file mode 100644 index 0000000..d72cd09 --- /dev/null +++ b/theme-clock/tests/body/clock/test_clock.py @@ -0,0 +1,27 @@ +from selenium import webdriver +import time +from selenium.webdriver.chrome.service import Service +from selenium.webdriver.common.by import By +from selenium.webdriver.common.keys import Keys +from selenium.webdriver.chrome.options import Options + +# Define Chrome WebDriver options +chrome_options = Options() +service = Service('/Users/mac005/Downloads/chromedriver-mac-arm64/chromedriver') + +# Initialize Chrome WebDriver +driver = webdriver.Chrome(service=service, options=chrome_options) +# Open the Flask application +driver.get('http://127.0.0.1:5500/theme-clock/index.html') + +element = driver.find_element(By.XPATH, '//div[@class="clock-container"]') + +time.sleep(3) + +if element: + print('The clock is found.') +else: + print('The clock is not found.') + +# Close the browser window +driver.quit() \ No newline at end of file diff --git a/theme-clock/tests/body/clock/time/test_time.py b/theme-clock/tests/body/clock/time/test_time.py new file mode 100644 index 0000000..30001e8 --- /dev/null +++ b/theme-clock/tests/body/clock/time/test_time.py @@ -0,0 +1,37 @@ +from selenium import webdriver +import time +from selenium.webdriver.chrome.service import Service +from selenium.webdriver.common.by import By +from selenium.webdriver.common.keys import Keys +from selenium.webdriver.chrome.options import Options + +# Define Chrome WebDriver options +chrome_options = Options() +service = Service('/Users/mac005/Downloads/chromedriver-mac-arm64/chromedriver') + +# Initialize Chrome WebDriver +driver = webdriver.Chrome(service=service, options=chrome_options) +# Open the Flask application +driver.get('http://127.0.0.1:5500/theme-clock/index.html') + +element = driver.find_element(By.XPATH, '/html/body/div[1]/div[2]') + +text = element.text + +background_color = element.value_of_css_property('background-color') + +color = element.value_of_css_property('color') + +time.sleep(3) + +if element: + print('The time is found') +else: + print('The time is not found') + +print(f'Time is {text}') +print(f'Color is {background_color}') +print(f'Text color is {color}') + +# Close the browser window +driver.quit() \ No newline at end of file diff --git a/theme-clock/tests/body/clock/timepiece/test_hour.py b/theme-clock/tests/body/clock/timepiece/test_hour.py new file mode 100644 index 0000000..7c9d914 --- /dev/null +++ b/theme-clock/tests/body/clock/timepiece/test_hour.py @@ -0,0 +1,31 @@ +from selenium import webdriver +import time +from selenium.webdriver.chrome.service import Service +from selenium.webdriver.common.by import By +from selenium.webdriver.common.keys import Keys +from selenium.webdriver.chrome.options import Options + +# Define Chrome WebDriver options +chrome_options = Options() +service = Service('/Users/mac005/Downloads/chromedriver-mac-arm64/chromedriver') + +# Initialize Chrome WebDriver +driver = webdriver.Chrome(service=service, options=chrome_options) +# Open the Flask application +driver.get('http://127.0.0.1:5500/theme-clock/index.html') + +element = driver.find_element(By.XPATH, '/html/body/div[1]/div[1]/div[1]') + +color = element.value_of_css_property('background-color') + +time.sleep(3) + +if element: + print('The hour needle is found.') +else: + print('The hour needle is not found.') + +print(f'The color of hour needle is: {color}') + +# Close the browser window +driver.quit() \ No newline at end of file diff --git a/theme-clock/tests/body/clock/timepiece/test_minute.py b/theme-clock/tests/body/clock/timepiece/test_minute.py new file mode 100644 index 0000000..97c4859 --- /dev/null +++ b/theme-clock/tests/body/clock/timepiece/test_minute.py @@ -0,0 +1,31 @@ +from selenium import webdriver +import time +from selenium.webdriver.chrome.service import Service +from selenium.webdriver.common.by import By +from selenium.webdriver.common.keys import Keys +from selenium.webdriver.chrome.options import Options + +# Define Chrome WebDriver options +chrome_options = Options() +service = Service('/Users/mac005/Downloads/chromedriver-mac-arm64/chromedriver') + +# Initialize Chrome WebDriver +driver = webdriver.Chrome(service=service, options=chrome_options) +# Open the Flask application +driver.get('http://127.0.0.1:5500/theme-clock/index.html') + +element = driver.find_element(By.XPATH, '/html/body/div[1]/div[1]/div[2]') + +color = element.value_of_css_property('background-color') + +time.sleep(3) + +if element: + print('The minute needle is found.') +else: + print('The minute needle is not found.') + +print(f'The color of minute needle is: {color}') + +# Close the browser window +driver.quit() \ No newline at end of file diff --git a/theme-clock/tests/body/clock/timepiece/test_second.py b/theme-clock/tests/body/clock/timepiece/test_second.py new file mode 100644 index 0000000..861a204 --- /dev/null +++ b/theme-clock/tests/body/clock/timepiece/test_second.py @@ -0,0 +1,31 @@ +from selenium import webdriver +import time +from selenium.webdriver.chrome.service import Service +from selenium.webdriver.common.by import By +from selenium.webdriver.common.keys import Keys +from selenium.webdriver.chrome.options import Options + +# Define Chrome WebDriver options +chrome_options = Options() +service = Service('/Users/mac005/Downloads/chromedriver-mac-arm64/chromedriver') + +# Initialize Chrome WebDriver +driver = webdriver.Chrome(service=service, options=chrome_options) +# Open the Flask application +driver.get('http://127.0.0.1:5500/theme-clock/index.html') + +element = driver.find_element(By.XPATH, '/html/body/div[1]/div[1]/div[3]') + +color = element.value_of_css_property('background-color') + +time.sleep(3) + +if element: + print('The second needle is found.') +else: + print('The second needle is not found.') + +print(f'The color of second needle is: {color}') + +# Close the browser window +driver.quit() \ No newline at end of file diff --git a/theme-clock/tests/body/clock/timepiece/test_timepiece.py b/theme-clock/tests/body/clock/timepiece/test_timepiece.py new file mode 100644 index 0000000..78ba6f2 --- /dev/null +++ b/theme-clock/tests/body/clock/timepiece/test_timepiece.py @@ -0,0 +1,27 @@ +from selenium import webdriver +import time +from selenium.webdriver.chrome.service import Service +from selenium.webdriver.common.by import By +from selenium.webdriver.common.keys import Keys +from selenium.webdriver.chrome.options import Options + +# Define Chrome WebDriver options +chrome_options = Options() +service = Service('/Users/mac005/Downloads/chromedriver-mac-arm64/chromedriver') + +# Initialize Chrome WebDriver +driver = webdriver.Chrome(service=service, options=chrome_options) +# Open the Flask application +driver.get('http://127.0.0.1:5500/theme-clock/index.html') + +element = driver.find_element(By.XPATH, '//div[@class="clock"]') + +time.sleep(3) + +if element: + print('The clock is found.') +else: + print('The clock is not found.') + +# Close the browser window +driver.quit() \ No newline at end of file diff --git a/theme-clock/tests/body/test_body.py b/theme-clock/tests/body/test_body.py new file mode 100644 index 0000000..5d72bc4 --- /dev/null +++ b/theme-clock/tests/body/test_body.py @@ -0,0 +1,31 @@ +from selenium import webdriver +import time +from selenium.webdriver.chrome.service import Service +from selenium.webdriver.common.by import By +from selenium.webdriver.common.keys import Keys +from selenium.webdriver.chrome.options import Options + +# Define Chrome WebDriver options +chrome_options = Options() +service = Service('/Users/mac005/Downloads/chromedriver-mac-arm64/chromedriver') + +# Initialize Chrome WebDriver +driver = webdriver.Chrome(service=service, options=chrome_options) +# Open the Flask application +driver.get('http://127.0.0.1:5500/theme-clock/index.html') + +element = driver.find_element(By.TAG_NAME, 'body') + +background_color = element.value_of_css_property('background-color') + +time.sleep(3) + +if element: + print('The body is found.') +else: + print('The body is not found.') + +print(f'The background color is {background_color}') + +# Close the browser window +driver.quit() \ No newline at end of file diff --git a/theme-clock/tests/test_body.py b/theme-clock/tests/test_body.py new file mode 100644 index 0000000..7396bfb --- /dev/null +++ b/theme-clock/tests/test_body.py @@ -0,0 +1,27 @@ +from selenium import webdriver +import time +from selenium.webdriver.chrome.service import Service +from selenium.webdriver.common.by import By +from selenium.webdriver.common.keys import Keys +from selenium.webdriver.chrome.options import Options + +# Define Chrome WebDriver options +chrome_options = Options() +service = Service('/Users/mac005/Downloads/chromedriver-mac-arm64/chromedriver') + +# Initialize Chrome WebDriver +driver = webdriver.Chrome(service=service, options=chrome_options) +# Open the Flask application +driver.get('http://127.0.0.1:5500/theme-clock/index.html') + +element = driver.find_element(By.TAG_NAME, 'body') + +time.sleep(3) + +if element: + print('The body is found.') +else: + print('The body is not found.') + +# Close the browser window +driver.quit() \ No newline at end of file diff --git a/theme-clock/tests/test_browser.py b/theme-clock/tests/test_browser.py new file mode 100644 index 0000000..19ef206 --- /dev/null +++ b/theme-clock/tests/test_browser.py @@ -0,0 +1,20 @@ +from selenium import webdriver +import time +from selenium.webdriver.chrome.service import Service +from selenium.webdriver.common.by import By +from selenium.webdriver.common.keys import Keys +from selenium.webdriver.chrome.options import Options + +# Define Chrome WebDriver options +chrome_options = Options() +service = Service('/Users/mac005/Downloads/chromedriver-mac-arm64/chromedriver') + +# Initialize Chrome WebDriver +driver = webdriver.Chrome(service=service, options=chrome_options) +# Open the Flask application +driver.get('http://127.0.0.1:5500/theme-clock/index.html') + +time.sleep(3) + +# Close the browser window +driver.quit() \ No newline at end of file From 9ab40486f4e316e04d0fd7a47a53b3c5e7c200fd Mon Sep 17 00:00:00 2001 From: Hammad1007 Date: Thu, 18 Jan 2024 12:28:19 +0500 Subject: [PATCH 5/5] Update the code for button changing color --- theme-clock/tests/body/button/test_button.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/theme-clock/tests/body/button/test_button.py b/theme-clock/tests/body/button/test_button.py index 372cb7d..364b980 100644 --- a/theme-clock/tests/body/button/test_button.py +++ b/theme-clock/tests/body/button/test_button.py @@ -18,11 +18,10 @@ driver.get('http://127.0.0.1:5500/theme-clock/index.html') button = driver.find_element(By.XPATH, '/html/body/button') button.click() -# Wait for the changes to take effect (adjust wait time as needed) try: - # Find the new button after the changes + button = driver.find_element(By.XPATH, '/html/body/button') - + # Retrieve properties text = button.text background_color = button.value_of_css_property('background-color')