Running a external Selenium Python script from Grrovy script using SOAPUI
SOLVED- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Running a external Selenium Python script from Grrovy script using SOAPUI
I would like to run external python selenium scripts located in my project folder. Is it possible to do so? My goal is to run something on the UI before running the API test on SOAPUI. If yes, How can i achieve this?
Solved! Go to Solution.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If required, you may run it execute command from groovy.
"cmd /c echo hello".execute()
Similarly you can call python with the script name as argument. Give it a shot.
Regards,
Rao.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@nmrao, I am looking for more options since I am struggling with (selenium + SOAPUI.) Please see here - https://community.smartbear.com/t5/SoapUI-Open-Source/Unable-to-run-selenium-code-from-grrovy-script...
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Either of these two approaches might help:
def cmdArray1 = ["python", "-c", "print('hello')"] def cmd1 = cmdArray1.execute() cmd1.waitForOrKill(1000) log.info cmd1.text def cmdArray2 = ["python", "/Users/test/temp/hello.py"] def cmd2 = cmdArray2.execute() cmd2.waitForOrKill(1000) log.info cmd2.text
Where hello.py is:
print "Hello World!"
Let me know how you get on.
Regards,
Rupert
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you so much for your post. Just one more thing I wanted to know about this.
When I run your code with only print "Hello" it works fine. But when I have the selenium code in it(which opens the browser and configure things on the UI) it does not work. It is strange to me. Do you think I am missing anything here?
Same with the SOAP PRO version, it does not work there either.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Ok, are you able to share your Python script please?
I take it it runs OK if you execute it from a shell outside of SoapUI?
Possibly the way the chrome browser is executed under the shell process is an issue, perhaps a headless browser driver like the PhantomJS one might work better. I am not a Selenium expert, but can take a look.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes when I run it from shell outside SOAPUI, it works fine. Here is the code below:
from selenium import webdriver
driver = webdriver.Chrome()
driver.maximize_window()
driver.get('https://google.Companydata')
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Tried using PhantomJS but no luck. Same error, does not run anything
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This problem is now resolved. Using the following script:
def cmdArray2 = ["python", "C:/Users/Desktop/SOAPProject/test.py"]
def process = new ProcessBuilder(cmdArray2).redirectErrorStream(true).start()
process.inputStream.eachLine {
log.warn(it)
}
process.waitFor()
return process.exitValue()
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Nice one! 🙂
