I made a program that alerts me if there is any seats available
using python, selenium, chromedriver.
Then I made it excutable using pyinstaller with --onefile, -w options since I do not need and I do not want to see any console windows.
But then when I execute my program, chromedriver's console, not sure to call this as a console, shows up.
Is there any way to not see this?
If I understood your question properly, it would mean that you do not wanna see any browser being open up when you run your script.
If that is the case, I would advise headless mode.
options = webdriver.ChromeOptions()
options.add_argument('--window-size=1920,1080')
options.add_argument("--headless")
and then pass the options to driver object like this:
driver = webdriver.Chrome(executable_path = driver_path, options = options)
Using headless mode, you would not see any browser window or console.Your script will run in background.
Related
Currently, I have a .ini file called testcase.ini which looks something like this:
[TEST]
DRIVER_PATH = C:\Python\
BROWSER = CHROME
; BROWSER = EDGE
; BROWSER = FIREFOX
CHROME_PATH = C:\Program Files\Google\Chrome\Application\chrome.exe
; EDGE_PATH = C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe
; FIREFOX_PATH = C:\Program Files\Mozilla Firefox\firefox.exe
To run my automated tests, I open a command prompt in my Test Plan folder and enter a command like this:
python TestPlan_LoginTest.py
Instead of going in to the testcase config file and commenting out which browsers I don't wish to use when running my automated tests, I'd like to be able to choose the browser when I invoke the test in the command prompt, i.e. something like this:
python TestPlan_LoginTest.py Firefox
or
python TestPlan_LoginTest.py Edge
If I don't include a browser in the invocation, it defaults to Chrome.
Is this possible with unittest? What changes would I need to make and where?
If you're using a pytest plugin called SeleniumBase, you can set the browser from the command-line. (It defaults to "chrome" if not specified.) Example:
pytest test_demo_site.py --edge
pytest my_first_test.py --firefox
Or if you prefer to use your own framework, you can find the necessary code for setting pytest command-line options here in SeleniumBase: pytest_plugin.py
That link shows you about using pytest_addoption(parser): as well as code such as:
parser.addoption(
"--edge",
action="store_true",
dest="use_edge",
default=False""",
)
which lets you customize command-line options for use in tests.
I'm currently working with 2 monitors, and I've noticed that Robot Framework (using SeleniumLibrary) always open the test execution in the main display that is selected in windows display settings.
Is there any way to choose which monitor will be used to display test execution?
This is how I'm starting the browser. I'm currently using Chrome
Start Browser
Open Browser ${url} ${BROWSER}
... options=add_experimental_option("excludeSwitches", ["enable-logging"])
Maximize Browser Window
Ragnoroct's answer here seems to be a solution: https://stackoverflow.com/a/57545639/16635196.
Chrome has a command-line switch for window position
--window-position=x,y
https://peter.sh/experiments/chromium-command-line-switches/#window-position
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument('window-position=2000,0') # opens at x=2000,y=0 from the start
driver = webdriver.Chrome(options=options)
Since I was not using Python directly in the Robot tests, I resorted to directly modifying the Python package source where these options are set. For example, AppData\Local\Programs\Python\Python310\lib\site-packages\QWeb\internal\browser\chrome.py for combination of QWeb and Windows10. Obviously not a good way of doing things in the long run, but virtual environment could be of help here.
Start-maximized didn't work in conjunction with window-position, so I had to additionally use window-size=2560,1440.
How can we use protractor with an existing selenium browser session rather than always create a new one. If I have started up a selenium browser session, run some tests in there, and exported the session ID into the environment conf file in protractor or in some other way made it available, it would be nice to be able to configure protractor in the normal way (e.g. using an option in the protractor configuration file) to access this session.
I would need to start a protractor execution in the middle of a selenium execution, do some test, and come back to selenium execution. Something like pseudo-code snippet would really help.
You'll need to session id from the launched browser. You should be able to get it from the http://localhost:4444/wd/hub/static/resource/hub.html. So let's say this session id is '12345', you have two options, you could pass it as a command line or via the configuration file.
command line
protractor protractor.conf.js --seleniumSessionId=12345
configuration file
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',
seleniumSessionId: '12345',
...
}
After you have set the selenium session id, you should be able to use the browser session. An example of this being exercised is: https://github.com/angular/protractor/blob/master/scripts/driverProviderAttachSession.js
If you would like to read more about it, I also have a medium post about this feature that I might have worked on: https://medium.com/#cnishina/attaching-a-protractor-test-to-an-existing-selenium-session-931196936ae2
I am running Jmeter with the Webdriver plugin installed on Windows 7. My current test plan contains the Webdriver sampler and Firefox driver config. When I try to run the test plan, nothing happens. There is nothing recorded in the View Results Tree window, and the remaining test indicator in the top right hand corner counts down to 0 without anything happening.
When I deactivate the Webdriver Sampler and Firefox driver config elements, the remaining tests run without a problem.
Is there a bug with this software, or am I missing something? My code is below, if that helps.
var pkg = JavaImporter(org.openqa.selenium)
WDS.sampleResult.sampleStart()
WDS.browser.get('https://test.test.test.test') var username =
WDS.browser.findElement(pkg.By.id('USERNAME')).sendKeys([WDS.args[0]])
var password =
WDS.browser.findElement(pkg.By.id('PASSWORD')).sendKeys([WDS.args[1])
WDS.sampleResult.sampleEnd()
I have installed firefox 26, as this is the recommended supported browser, so it's not that there's no compatible browser.
My main question is this - Why doesn't the browser window open? Why do the other tests in the test plan fail to run when the config elements are active?
In 99% of cases the answer should be in jmeter.log file. In the meantime a couple of recommendations:
add the following line to system.properties file (lives in the /bin folder of your JMeter installation)
webdriver.firefox.bin=/path/to/your/firefox.exe
See https://code.google.com/p/selenium/wiki/FirefoxDriver page for other Firefox-related properties
locate all duplicate http* libraries like httpcore*.jar httpmime.jar etc. and remove the ones with lesser version
restart JMeter to pick the property and the changes up
Check out The WebDriver Sampler: Your Top 10 Questions Answered guide for other tips and tricks
You need to make sure you provided the full path of the Firefox driver in the jp#gc config element.
I have installed firebug for FF. But when i start firefox it always starts some default ff version, i dont' know where selenium finds it.
I already googled alot, tried to use different firefoxbinary:
System.setProperty("webdriver.firefox.bin", "C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe");
final File firefoxPath = new File(System.getProperty("webdriver.firefox.bin")) ;
FirefoxBinary firefoxBinary= new FirefoxBinary(firefoxPath);
firefox = new FirefoxDriver(firefoxBinary,null);
I tried to use different ff profile:
FirefoxProfile firefoxProfile = new FirefoxProfile();
firefoxProfile.addExtension(file);
firefoxProfile.setPreference("extensions.firebug.currentVersion", "1.9.1");
Alas, it does not work!
1. I don't know where to change/find webdriver.firefox.bin
2. I have tried changing path as environment variable,still no progress
maybe I m doing something wrong?
By default, Selenium will open a "vanilla" Firefox profile. If you want to have it launch with your profile, you can do that, but you have to select which profile you want to use. I will warn you that you often don't want to have your regular profile used because you'd like a clean, consistent working environment.
But you could certainly:
set up a profile (call it, for instance, selenium-profile using
Firefox's profile manager
run Firefox choosing that profile--from
Windows's Run dialog run "c:\Program Files(x86)\Mozilla
Firefox\firefox.exe" - P" or the equivalent path to FF if you are
32-but.
install Firebug using that profile.
then choose that profile when you launch your tests.
For information about how to do all this, look at this article.
Then, in your code, you can just call that profile. Step 3 in the article linked above shows how to do this.
Firefoxdriver starts a new default profile on each instance and this profile will be created in your temp folder and will be deleted after you quit the driver. There might be some old instances of ff profile which contains older version of firebug in your temp folder which might be not be deleted as webdriver quited unexpectedly.Try clearing your temp. It might help you as it did for me.