1

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()
2
  • 2
    this will answer your question I think: stackoverflow.com/questions/1013246/… Commented Nov 30, 2019 at 16:48
  • Try to replace start python ... by python ..., because start just starts the given command line but does not wait for it to finish. And replace cd ... by cd /D ... to also change the drive in case... Commented Dec 1, 2019 at 10:49

1 Answer 1

0

In the above case in your batch file. Both the Scripts will run simultaneously. Remove Start python login.py python OrderTicket.py

The Second will run only after first is complete.

Sign up to request clarification or add additional context in comments.

1 Comment

I suppose that adding at least the /Wait option to Start would also work for the first if not both of the python commands.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.