Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: LambdaTest/python-selenium-sample
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: JeeveshJ7/python-selenium-sample
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Can’t automatically merge. Don’t worry, you can still create the pull request.
  • 10 commits
  • 3 files changed
  • 2 contributors

Commits on Jul 6, 2023

  1. yay

    JeeveshJ7 committed Jul 6, 2023

    Verified

    This commit was signed with the committer’s verified signature.
    haoqunjiang Haoqun Jiang
    Copy the full SHA
    64818a3 View commit details
  2. yay

    JeeveshJ7 committed Jul 6, 2023
    Copy the full SHA
    f554991 View commit details
  3. Adds requirements.txt

    JeeveshJ7 committed Jul 6, 2023
    Copy the full SHA
    db285d3 View commit details
  4. Updates the YML

    JeeveshJ7 committed Jul 6, 2023
    Copy the full SHA
    344f1e6 View commit details
  5. Copy the full SHA
    8d8a2ce View commit details

Commits on Jul 7, 2023

  1. Updates Capabilities

    JeeveshJ7 authored Jul 7, 2023
    Copy the full SHA
    eb4bf0e View commit details
  2. Copy the full SHA
    5b50d0e View commit details
  3. Copy the full SHA
    eedd69a View commit details
  4. Copy the full SHA
    79b733b View commit details
  5. Copy the full SHA
    c4f872f View commit details
Showing with 77 additions and 76 deletions.
  1. +30 −0 .github/workflows/checking.yml
  2. +47 −76 lambdatest.py
  3. BIN requirements.txt
30 changes: 30 additions & 0 deletions .github/workflows/checking.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Python Selenium Tests

on:
push:
branches:
- main
- master

jobs:
test:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.9

- name: Install dependencies
run: pip install -r requirements.txt

- name: Run Selenium tests
env:
LT_USERNAME: ${{ secrets.LT_USERNAME }}
LT_ACCESS_KEY: ${{ secrets.LT_ACCESS_KEY }}
run: |
python lambdatest.py
123 changes: 47 additions & 76 deletions lambdatest.py
Original file line number Diff line number Diff line change
@@ -1,93 +1,64 @@

import unittest
import os
import threading

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities


username = os.getenv("LT_USERNAME") # Replace the username
access_key = os.getenv("LT_ACCESS_KEY") # Replace the access key


class FirstSampleTest(unittest.TestCase):
# Generate capabilites from here: https://www.lambdatest.com/capabilities-generator/
# setUp runs before each test case and
def setUp(self):
desired_caps = {
'LT:Options': {
"build": "Python Demo", # Change your build name here
"name": "Python Demo Test", # Change your test name here
"platformName": "Windows 11",
"selenium_version": "4.0.0",
"console": 'true', # Enable or disable console logs
"network": 'true', # Enable or disable network logs
#Enable Smart UI Project
#"smartUI.project": "<Project Name>"
},
"browserName": "firefox",
"browserVersion": "latest",
}

# Steps to run Smart UI project (https://beta-smartui.lambdatest.com/)
# Step - 1 : Change the hub URL to @beta-smartui-hub.lambdatest.com/wd/hub
# Step - 2 : Add "smartUI.project": "<Project Name>" as a capability above
# Step - 3 : Run "driver.execute_script("smartui.takeScreenshot")" command wherever you need to take a screenshot
# Note: for additional capabilities navigate to https://www.lambdatest.com/support/docs/test-settings-options/

options = webdriver.ChromeOptions()
options.browser_version = "114.0"
options.platform_name = "Windows 11"
lt_options = {};
lt_options["project"] = "SmartUI-CI-Coupa2-viewport";
lt_options["w3c"] = True;
lt_options["plugin"] = "python-python";
lt_options["smartUI.project"] = "Layout_Shift_Test11-CI-Coupa2"
lt_options["console"] = True
lt_options["network"] = True
lt_options["build"] = "Python CI-SmartUI-Coupa2"
lt_options["name"] = "Python-CI-SmartUI-Coupa2"
lt_options["selenium_version"] = "4.0.0"
options.set_capability('LT:Options', lt_options);
self.driver = webdriver.Remote(
command_executor="http://{}:{}@hub.lambdatest.com/wd/hub".format(
username, access_key),
desired_capabilities=desired_caps)

# tearDown runs after each test case


"jeeveshiitj", "mtPSfImA94UZNUj92fOctXE1VrKR4uDAoYrVU1kKJlqzclR6xU"),
options=options
)
def tearDown(self):
self.driver.quit()

# """ You can write the test cases here """
def test_demo_site(self):

# try:
driver = self.driver
driver.implicitly_wait(10)
driver.set_page_load_timeout(30)
driver.set_window_size(1920, 1080)

# Url
print('Loading URL')
driver.get("https://stage-lambda-devops-use-only.lambdatestinternal.com/To-do-app/index.html")

# Let's click on a element
driver.find_element(By.NAME, "li1").click()
location = driver.find_element(By.NAME, "li2")
location.click()
print("Clicked on the second element")

#Take Smart UI screenshot
#driver.execute_script("smartui.takeScreenshot")

# Let's add a checkbox
driver.find_element(By.ID, "sampletodotext").send_keys("LambdaTest")
add_button = driver.find_element(By.ID, "addbutton")
add_button.click()
print("Added LambdaTest checkbox")

# print the heading
search = driver.find_element(By.CSS_SELECTOR, ".container h2")
assert search.is_displayed(), "heading is not displayed"
print(search.text)
search.click()
driver.implicitly_wait(3)

# Let's download the invoice
heading = driver.find_element(By.CSS_SELECTOR, ".container h2")
if heading.is_displayed():
heading.click()
try:
driver = self.driver
driver.implicitly_wait(10)
driver.set_page_load_timeout(30)
print('Loading URL')
driver.get("https://www.coupa.com/partners/partner-connect-program")
element = driver.find_element(By.XPATH, "//button[@id='truste-consent-button']")
element.click()
driver.execute_script('smartui.takeScreenshot="Screen 1"')
print("1st screenshot")
driver.implicitly_wait(10)
driver.execute_script('smartui.takeScreenshot="Screen 2"')
#FullPage
print("2nd screenshot")
driver.execute_script("lambda-status=passed")
print("Tests are run successfully!")
else:

except:
driver.execute_script("lambda-status=failed")


print("Failed")
if __name__ == "__main__":
unittest.main()
threads = []
for _ in range(5): # specify the number of threads you want to spawn
thread = threading.Thread(target=unittest.main)
thread.start()
threads.append(thread)

for thread in threads:
thread.join()
Binary file added requirements.txt
Binary file not shown.