from selenium.webdriver.chrome.service import Service as chromeService
from webdriver_manager.chrome import ChromeDriverManager
chromeServiceObj = chromeService(ChromeDriverManager().install())
this is my "test_install_driver.py" file.
and when i use "python" in a terminal(or command window), it works.
but using "pythonw", it doesn't.
I made a test code file.
And I was using the command below.
pythonw c:\test_install_driver.py
it seems like that the code doesn't install the web driver file.
Related
I'm facing an issue in a ROS (Python 2.7) project.
Strucure
I'm working on a ROS project. The structure is the following:
probable-adventure
|
|-catkin_ws
|-src
|-ros_rover
|-include
|-launch
|-msg
|-__init__.py
|-Commands.msg
|-Teleoperation.msg
|-scripts
|-__init__.py
|-keyboard.py
|-test
|-__init__.py
|-testing.py
|-__init__.py
|-CMakeLists.txt
|-package.xml
Keyboard node (secondary problem)
keyboard.py starts as follows:
#!/usr/bin/env python
import rospy
from ros_rover.msg import Teleoperation
I describe it as a secondary problem because if I compile the project from catkin_ws directory using catkin_make command, everything works well and I can run the keyboard ROS node perfectly even though I get a pylint error in the from ros_rover.msg ... line.
Unable to import 'ros_rover.msg'
Main Problem
I just wrote the previous as context. The point is that I have to test the code within the scripts directory. I'm using unittest and I create python files in test directory.
I have create the following simple test (testing.py):
#!/usr/bin/env python
import unittest
from scripts.keyboard import GetKey
class TestBareBones(unittest.TestCase):
def test_one_equals_one(self):
self.assertEquals(1, 1, "1!=1")
if __name__ == '__main__':
unittest.main()
I think I have a problem with the imports because if I run the following python commands (from the ros_rover directory):
user#dubuntu:~/probable-adventure/catkin_ws/src/ros_rover$ python testing.py
user#dubuntu:~/probable-adventure/catkin_ws/src/ros_rover$ python -m testing
I get the following error:
File "/home/diego/Documents/probable-adventure/catkin_ws/src/ros_rover/test/prueba.py", line 5, in <module>
from scripts.keyboard import GetKey
File "scripts/keyboard.py", line 14, in <module>
from ros_rover.msg import Teleoperation
ImportError: No module named ros_rover.msg
My thought
I think the problem is related with imports because I have read that python imports depends on the directory from where you run the python command.
I run the test from ros_rover directory because the test's import is scripts.keyboard so it can found it (scripts is in ros_rover). But when the keyboard.py tries to import ros_rover.msg fails because I'm already in ros_rover directory and cannot find ros_rover.
I have read a lot here in StackOverflow and out of it but I didn't find a solution (I have added a empty __init__.py file to ros_rover, scripts and test directories).
I am trying to create a very simple Katalon test case that opens Firefox, goes to given URL and clicks a button to download a file. I have set up Desired Capabilities according to the Katalon documentation (https://github.com/katalon-studio/docs/blob/master/pages/katalon-studio/docs/introduction-to-desired-capabilities.md) but with no luck. When I try to download a file prompt shows up and file is not downloaded. How can I disable the prompt and download the file immediately instead?
Software versions, source code and screenshots below.
Windows 10, Katalon Studio 7.2.1, Mozilla Firefox 72.0.2, Selenium 3.141.59
import static com.kms.katalon.core.checkpoint.CheckpointFactory.findCheckpoint
import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase
import static com.kms.katalon.core.testdata.TestDataFactory.findTestData
import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import static com.kms.katalon.core.testobject.ObjectRepository.findWindowsObject
import com.kms.katalon.core.checkpoint.Checkpoint as Checkpoint
import com.kms.katalon.core.cucumber.keyword.CucumberBuiltinKeywords as CucumberKW
import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile
import com.kms.katalon.core.model.FailureHandling as FailureHandling
import com.kms.katalon.core.testcase.TestCase as TestCase
import com.kms.katalon.core.testdata.TestData as TestData
import com.kms.katalon.core.testobject.TestObject as TestObject
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import com.kms.katalon.core.windows.keyword.WindowsBuiltinKeywords as Windows
import internal.GlobalVariable as GlobalVariable
import org.openqa.selenium.Keys as Keys
WebUI.openBrowser('https://file-examples.com/index.php/text-files-and-archives-download/')
WebUI.click(findTestObject('downloadCsvFileButton'))
For Chrome the default setup of Desired Capabilities in Project Settings works fine, but for Firefox I had to do some workaround to make it work.
So, I found this topic https://forum.katalon.com/t/opening-firefox-with-a-specific-non-anonymous-profile/12012/15 and #kazurayam 's reply helped me to create a script that initializes WebDriver which I call before each test case:
import org.openqa.selenium.WebDriver
import org.openqa.selenium.firefox.FirefoxDriver
import org.openqa.selenium.firefox.FirefoxOptions
import org.openqa.selenium.firefox.FirefoxProfile
import org.openqa.selenium.firefox.ProfilesIni
import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import com.kms.katalon.core.webui.driver.DriverFactory
import com.kms.katalon.core.webui.driver.WebUIDriverType
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import internal.GlobalVariable as GlobalVariable
WebUIDriverType executedBrowser = DriverFactory.getExecutedBrowser()
switch(executedBrowser) {
case WebUIDriverType.FIREFOX_DRIVER: // "Firefox"
System.setProperty('webdriver.gecko.driver', DriverFactory.getGeckoDriverPath())
FirefoxOptions options = new FirefoxOptions()
options.addPreference('marionette', true)
options.addPreference('browser.download.folderList', 2)
options.addPreference('browser.helperApps.alwaysAsk.force', false)
options.addPreference('browser.download.manager.showWhenStarting', false)
options.addPreference('browser.download.dir', GlobalVariable.downloadPath)
options.addPreference('browser.download.downloadDir', GlobalVariable.downloadPath)
options.addPreference('browser.download.defaultFolder', GlobalVariable.downloadPath)
options.addPreference('browser.helperApps.neverAsk.saveToDisk', 'application/download, application/octet-stream, text/csv')
WebDriver driver = new FirefoxDriver(options);
// let Katalon Studio to use the WebDriver created here
DriverFactory.changeWebDriver(driver)
break
default:
WebUI.openBrowser('')
}
Note to others, if you want to download different file types you have to specify all the required the MIME types in ‘browser.helperApps.neverAsk.saveToDisk’ preference. A list of MIME types can be found here:
https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Complete_list_of_MIME_types
Additionally, if the file is PDF you have to add one more preference:
options.addPreference('pdfjs.disabled', true)
I have a .exe (PyQt5 + python3), the issue is that when I start the application, the cmd window is always initialized in the background.
I want that the cmd window is not initialized.
This is the code that I used to convert to .exe:
import cx_Freeze
from cx_Freeze import *
setup(
name = "interfaz",
options = {'build_exe': {'packages': ['cv2', 'numpy']}},
executables=[
Executable(
"interfaz.py",
)
]
)
This is an image showing the app:
According to the cx_Freeze documentation, in order to avoid that the command prompt appears briefly under Windows, you need to:
Freeze your application with the Win32GUI base [...]. This doesn’t use a console window, and reports errors in a dialog box.
Try thus to modify your setup script as follows:
import sys
from cx_Freeze import setup, Executable
# GUI applications require a different base on Windows (the default is for a console application).
base = None
if sys.platform == "win32":
base = "Win32GUI"
setup(name="interfaz",
options={'build_exe': {'packages': ['cv2', 'numpy']}},
executables=[Executable("interfaz.py", base=base)])
I'm trying to run the following code:
# To use interactive plots (mouse clicks, zooming, panning) we use the nbagg back end. We want our graphs
# to be embedded in the notebook, inline mode, this combination is defined by the magic "%matplotlib notebook".
%matplotlib notebook
import SimpleITK as sitk
%run update_path_to_download_script
from downloaddata import fetch_data as fdata
import gui
# Using an external viewer (ITK-SNAP or 3D Slicer) we identified a visually appealing window-level setting
T1_WINDOW_LEVEL = (1050,500)
When I run it in spider 3.2.6 I get:
ModuleNotFoundError: No module named 'gui'
Any help would be appreciated.
Code source: http://insightsoftwareconsortium.github.io/SimpleITK-Notebooks/Python_html/30_Segmentation_Region_Growing.html
This isn't a spyder issue.
The gui module is part of the notebooks repository. Either clone the repository or just download this file. Same goes for the downloaddata module.
I'm stuck on running the BeeGO app using "bee run" it says
The thing is I've already have setup properly my GOPATH to D:/Web Dev/GO/BeeGO/test-project/
and also routers path does exist and I've tried to manual build the file but it doesn't generate an .exe file.
Anyone knows how to fix this?
I'm using Windows 8.1 Pro (64-bit)
Thanks
GO expects the directory structure under $GOPATH in following ways as described in code organization:
$GOPATH/src <--- where your source code goes
/pkg
/bin
Instead of placing your source files directly under $GOPATH (D:/Web Dev/GO/BeeGO/test-project/ for your case), you want to move your code under $GOPATH/src.
D:/Web Dev/GO/BeeGO/test-project/src/main.go
D:/Web Dev/GO/BeeGO/test-project/src/quickstart/routers/routers.go
D:/Web Dev/GO/BeeGO/test-project/src/quickstart/controllers/controllers.go
import path should be always starting from $GOPATH/src. routers.go can be always imported as import "quickstart/routers" and controllers.go can be imported as import "quickstart/controllers".
That's not how you import a package.
The import path is relative to $GOPATH/src. use:
import "quickstart/routers"
Finally fixed the bug from the framework,
What I did:
in main.go import from
"D:/Web Dev/GO/BeeGO/test-project/quickstart/routers"
I changed it to _"../quickstart/routers" make sure to include _ this means to import the library even if it is not used,
Then in the routers/router.go I changed the import path
"D:/Web Dev/GO/BeeGO/test-project/quickstart/controllers" to "../controllers"
It seems BeeGO doesn't generate the template properly and caused the build to fail.
Another possiblity for this error, is when you copy-paste code from the internet,
and
import "quickstart/routers"
became
import "quickstart/routers "
due to bugs in some CMS/Blog systems (notice the space at the end before the closing quote...).