so I'm trying to create a custom webdriver (as in (down)load the normal driver but use custom profile settings) to get it to open any tab with a popped-out DevTools window (set to "Console").
I figured I could do that by setting up such a preference file by just interacting with my own installed Chrome version and copying my preferences to another folder, then let the Selenium WebDriver load its preferences from that folder.
But when I tried starting the WebDriver using this:
options.addArguments("--profile-directory=\"Default\"");
options.addArguments("--user-data-dir=./temp-selenium");
... it always shows an error (in german, roughly translated to):
Google Chrome can't read or write in the following directory: ./temp-selenium
Removing the second line completely just starts a Chome window with a user profile selection prompt. Setting up a file path to something like AppData doesn't work because then I get the following error:
Could not remove old devtools port file. Perhaps the given user-data-dir at "myFilePath\User Data" is still attached to a running Chrome ...
By the way, why I'm doing this: I just want to SEE the console logs while testing stuff. Can't imagine it's actually THIS difficult to get to it. My tests are way too fast to manually open the console in time and I need to find a bug that happens every 100 tries. Opening the console 100 times is just way too tedious.
Anyone have an idea?
Related
I have a critical issue over here.
Please find my scenario below:
login
click on a link
after the click, a new tab opens
I have switched the focus to the new opened tab with the following code
ArrayList<String> newTab = new ArrayList<String>(driver.getWindowHandles());
driver.switchTo().window(newTab.get(1));
The issue is that when I try to click on an excel download link on the newly opened tab, the "Open with" popup is appearing and my automation fails. Even after adding the following preference
firefoxProfile.setPreference("browser.helperApps.neverAsk.openFile",
"text/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
firefoxProfile.setPreference("browser.helperApps.neverAsk.saveToDisk",
"text/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
Please, can you suggest a feasible solution as soon as possible?
Thank you
Please manually set these preferences in your firefox's(about:config) section, visit the application, click the link and see if the file gets downloaded without any prompt. This will help you to identify the issues with automation.
I tried setting these preferences in my firefox, but it still prompts download window. I can download without prompt only after checking "Do this automatically for files like this from now on" which updates mimeTypes.rdf file in the profile directory. So to make this work through automation, you may need to bundle a custom firefox profile that includes a mimeTypes.rdf with your TestSuite.
Here's the code to create FirefoxProfile from a given profile directory:
FirefoxProfile profile = new FirefoxProfile(new File("<PATH_TO_FIREFOX_PROFILE_DIRECTORY_THAT_WORKS_WHEN_TESTED_MANUALLY>");
WebDriver driver = new FirefoxDriver(profile);
I am trying to deploy R Shiny App as an Windows Desktop App. So far I have used the framework described at http://blog.analytixware.com/2014/03/packaging-your-shiny-app-as-windows.html and managed to make it work with the help of stackoverflow users (question name "R Shiny as Windows Desktop App Creates Text File With Warning").
An update to this framework has been developed and it has several advantages over the previous one, such as not relying on Google Chrome browser etc. and it is described here: http://oddhypothesis.blogspot.com/2016/04/desktop-deployr.html
All files can be found in the GitHub account of framework creator (link is presented in the description)
I have adjusted the following:
app.R
require(shinyjs,quietly = TRUE,warn.conflicts=FALSE)
require(markdown,quietly = TRUE,warn.conflicts=FALSE)
require(scales,quietly = TRUE,warn.conflicts=FALSE)
require(DT,quietly = TRUE,warn.conflicts=FALSE)
runApp("./app/shiny/", launch.browser=TRUE,quiet=TRUE)
packages.txt
Added the names of the packages I am using
# Primary package dependencies for the application that are loaded during
# startup.
#
# If not available, they will be installed into app/library. Custom source
# packages need to be installed manually.
# bare miniminum: configurations are stored in json format
jsonlite
# if deploying shiny based applications:
shiny
shinyjs
markdown
scales
DT
App does launch, it works. However a new folder is created called log with file error.log, which includes the following:
library paths:
... C:/Users/VoronecI/Desktop/New folder (2)/app/library
... C:/Users/VoronecI/Desktop/New folder (2)/dist/R-Portable/App/R-Portable/library
working path:
... C:/Users/VoronecI/Desktop/New folder (2)
Loading required package: methods
ensuring packages: jsonlite, shiny, shinyjs, markdown, scales, DT
Attaching package: 'shiny'
The following object is masked from 'package:jsonlite':
validate
Attaching package: 'shinyjs'
The following object is masked from 'package:shiny':
runExample
The following objects are masked from 'package:methods':
removeClass, show
Attaching package: 'DT'
The following objects are masked from 'package:shiny':
dataTableOutput, renderDataTable
Is there a way to prevent this logging of the unmeaningful error?
The reason why I want to get rid of it is because I further use Inno Setup Compiler to create .exe and this is not working when I have a log file updating each time I run the app.
As you can see in this file (line 66) https://github.com/wleepang/DesktopDeployR/blob/7c81e72c5beb29bf84ca65fd1d5bb5486caec51a/dist/script/wsf/js/run.js
The command is run as
var strCommand = [Rexe, Ropts, RScriptFile, "1>", Outfile, "2>&1"].join(" ");
which redirects command line outputs (that normally directly print to the screen) to the Outfile. You can change this line to
var strCommand = [Rexe, Ropts, RScriptFile].join(" ");
which will disable the logging. This might have other implications though (you might see a command window for example, I am not too sure but test it out).
Alternatively, you might be able to change this file https://github.com/wleepang/DesktopDeployR/blob/7c81e72c5beb29bf84ca65fd1d5bb5486caec51a/app/config.cfg (line 27) and set
- use_userprofile: true
(you need to uncomment this line, it is currently inside a block comment). This will make sure the log file goes into the user profile folder, and that might also solve your problem.
Ivona, I just finished developing the RInno package which also uses Inno Setup and the DesktopDeployR project to install local Shiny apps, and it will log errors without a problem.
To get started:
install.packages("RInno")
require(RInno)
RInno::install_inno()
Then you just need to call two functions to create an installation framework:
create_app(app_name = "myapp", app_dir = "path/to/myapp")
compile_iss()
If you are interested in other features, check out FI Labs - RInno. I'd be interested to know if turning off the error logging feature is something you would like to add ;)
I am trying to use the Squirrel SQL client to connect to a H2 server instance.
The problem I am facing is that when I hit the "connect" button of the server I want to connect to, then I am getting a:
ClassNotFoundException: org.h2.Driver
I thought it was because h2.jar was not in the classpath. Then I edited squirrel-sql.bar to try two things.
The first thing I tried is to add the JAR into the PATH like this:
SET PATH=%PATH%;C:\Program Files\squirrel-sql-3.5.3\plugins\h2.jar
Then I restarted Squirrel. Same error.
Then I tried adding:
set TMP_CP=%TMP_CP%;"C:\Program Files\squirrel-sql-3.5.3\plugins\h2.jar"
Then I restarted Squirrel. Same error.
When I look at the console, I can see that h2.jar is in the PATH and/or the SQUIRREL_CP but the same error occurs all the time.
I am wondering if I am not forgetting something bout how to install/configure SQuirrel and/or H2?
Rather than modifying the batch files every time you use a different driver just modify the drivers classpath through the GUI.
Double click on the appropriate driver in the Drivers tab then click on the "Extra Class Path" tab and add the driver jar.
You can find more information under "How to connect to a Database" in the SQuirreL section in the Help file. Press F1 in SQuirreL to see the Help file. You can see a screenshot at http://www.squirrelsql.org/screenshots/driver.html
I found the issue to my problem. I was linking to the h2 file in Squirrel SQL. However, I had to link to the h2 file from the H2 application... What I did to solve my issue is to add a line to the addpath.bat file such that the file looks like:
set TMP_CP=%TMP_CP%;%1
set TMP_CP=%TMP_CP%;"C:\Program Files (x86)\H2\bin\h2-1.4.181.jar"
Then I restarted Squirrel SQL and everything was working as expected!
I'm listing the exact steps I followed to add the driver as even though Colin Bell has already given a good answer, without following the final step 4. I still couldn't get this to work.
Download http://www.h2database.com/automated/h2-latest.jar and save it somewhere, in my case ~/drivers/h2-latest.jar
Edit the existing h2 driver.
On the 'Extra Class Path' tab add the driver
Click 'List Drivers' - org.h2.Driver should appear in the 'Class Name' field (as detailed in the link from Colin's answer: http://www.squirrelsql.org/screenshots/driver.html)
I was missing the final step of clicking 'List Drivers' since it already had org.h2.Driver in the 'Class Name' before I tried to add it. But without this step it was still giving the error:
Could not find class org.h2.Driver in neither the Java class path nor the Extra class path of the H2 driver definition:
java.lang.ClassNotFoundException: org.h2.Driver
WebDriver driver = new FirefoxDriver();
driver.get("http://www.google.com/");
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(scrFile, new File("c:\\tmp\\screenshot.png"));
Using this code to take snapshots using selenium web-driver. This code only stores snaphots locally on my PC. If i want to run it automatically from Jenkins, is there any way to store that snapshots somewhere else so that if anyone runs it either though Jenkins or locally from their PC, they don't have to change the link(("c:\tmp\screenshot.png") every time.
You could make the location of the output file something that it controlled by a setting - either a command-line argument to the tool running this code (if you can modify that), or an environment variable that you can read from your section of code above. You could also have a default location that always exists and should be writable like the user's home directory, rather than an absolute path to c:\tmp.
In jenkins, I would have a step (in an ant script, shell script, or whatnot) create a folder called "screenshots" below $WORKSPACE, and then tell the tool that's going to run your code about that location by one of the methods suggested above. This will also be handy if you want to make the screenshots part of the job's output.
Also, unless you really only ever need the latest file (or have downstream code consuming the screenshot and expecting a specific name), I would introduce a timestamp or some other variable file-naming for the png in the code above, e.g. screenshot-2014-05-16_12-15-37.png, so that if you run the tool twice it doesn't just overwrite the file that was there before.
hth
I'm trying out Selenium. I've built a quick script using the Selenium IDE. It logs in to a page, opens up a 'Search' window, does a search, and then opens up one of the results.
When I run the test in the Selenium IDE, it works fine. When I export to a Java JUnit 4 test case, it works fine. But when I export to a Python 2 unittest, the xpath searching seems to be very buggy...
Example:
The page has an input element with name='keyword'. When I search using java with driver.findElement(By.name("keyword")); it's all good - it finds the element.
When I search using python with browser.find_element_by_name("keyword"), it can't seem to find it. I've also tried browser.find_element_by_xpath("//input[#name='keyword']") and browser.find_element_by_xpath("/html/body/form/div/ul/li[2]/input"), the second of which is the xpath I get when I use firebug and the Copy XPath feature.
I've tried adding a delay to the python code before it searches for the input, but to no avail.
Does anyone have any idea why the python calls can't seem to find the element? This seems to happen with different elements throughout the pages of the web app (but doesn't happen in the Selenium IDE that I've found so far)...
I appreciate any help you guys can provide!
Edit:
The error showing in the console is:
Traceback (most recent call last):
File "test.py", line 37, in <module>
elem = browser.find_element_by_xpath("/html/body/form/div/ul/li[2]/input")
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 213, in find_element_by_xpath
return self.find_element(by=By.XPATH, value=xpath)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 671, in find_element
{'using': by, 'value': value})['value']
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 156, in execute
self.error_handler.check_response(response)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/errorhandler.py", line 147, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: u'Unable to locate element: {"method":"xpath","selector":"/html/body/form/div/ul/li[2]/input"}'
Cheers
Jarrett
Turns out, the website was opening a new window when a link was clicked, but the driver was still referencing the old window. Not sure why the Selenium IDE export didn't catch that.
Anyway, I had to set the window for the driver to the newly opened window, and then it worked ok.
Hope this might help other people.
Cheers
Jarrett
check if its inside an iframe, you need to go to that iframe if it does.
driver.switch_to.default_content()
driver.switch_to_frame("fameid")