I have a batch script which eventually runs two python file (one after another), but I am unable to handle the exit code from one workflow to another. Due to which my batch script is failing
batch file snippet:
@echo off
echo "Starting the automation Script"
cd "C:\Desktop\AutoImpement\"
echo "running the loging"
start python login.py
start python OrderTicket.py
pause
login script:
import time
from selenium import webdriver
browser = webdriver.Chrome(executable_path="C:\Desktop\AutoImpement\ChromeDriver")
browser.get('https://localhost:8080/login/#')
browser.find_element_by_id(“Login”).send_keys(“<userName>”)
browser.find_element_by_id (“Password”).send_keys(“password”)
browser.find_element_by_id(“submit”).click()
time.sleep(5)
browser.find_element_by_id(“ItemName”).send_keys(“test”)
browser.find_element_by_id (“Quantity”).send_keys(“5”)
browser.find_element_by_id(“Address”).send_keys(“Test”)
browser.find_element_by_id(“submitOrder”).click()
time.sleep(3)
browser.quit()
Verify the Order Script
import time
from selenium import webdriver
browser = webdriver.Chrome(executable_path="C:\Desktop\AutoImpement\ChromeDriver")
browser.get('https://localhost:8080/OrderDetails')
browser.find_element_by_id(“SreachOrder”).send_keys(“test”)
browser.find_element_by_id(“findOrder”).click()
time.sleep(3)
browser.quit()
When I run the batch file, only the login script is running successfully but the control is not shifting to the next script which verifies the order from the first file. I tried with sending the exit code from the python by changing the following but didn't work.
import time
from selenium import webdriver
try:
browser = webdriver.Chrome(executable_path="C:\Desktop\AutoImpement\ChromeDriver")
browser.get('https://localhost:8080/login/#')
browser.find_element_by_id(“Login”).send_keys(“<userName>”)
browser.find_element_by_id (“Password”).send_keys(“password”)
browser.find_element_by_id(“submit”).click()
time.sleep(5)
browser.find_element_by_id(“ItemName”).send_keys(“test”)
browser.find_element_by_id (“Quantity”).send_keys(“5”)
browser.find_element_by_id(“Address”).send_keys(“Test”)
browser.find_element_by_id(“submitOrder”).click()
time.sleep(3)
exit(0)
except:
print("Error Occured")
exit(1)
finally:
browser.quit()
start python ...bypython ..., becausestartjust starts the given command line but does not wait for it to finish. And replacecd ...bycd /D ...to also change the drive in case...