I am looking to access/use Chrome's devtools panel with Selenium Webdriver.
Specifically, I want to use the "WASP" chrome plugin, which is accessed through devtools. I've got my selenium set up to run with the WASP plugin included, and I can open DevTools (with sendKeys.F12), but I don't know how to actually use that panel now that it is open. Is there a way to do so?
The closest thing I've found to my problem is this link: Chrome Dev Tools API & Selenium WebDriver, but that hasn't been helpful at all to me.
Also, if it looks like this will be impossible (which it does) can anyone think of a workaround?
In Selenium 4 alpha, there is a way to interact with DevTools API using the java-client. What you are looking for specifically is the "Profiler" domain (https://chromedevtools.github.io/devtools-protocol/tot/Profiler)
Recently, I contributed the "Network" and "Performance" domains for a better user facing API in selenium java - https://github.com/SeleniumHQ/selenium/pull/7212
I believe that "Profiler" will also be implemented soon. Of course, there is a generic API for all domains in Java client that was merged a while ago, you can use it like this:
driver.getDevTools().createSession();
driver.getDevTools().send(new Command("Profiler.enable", ImmutableMap.of()));
driver.getDevTools().send(new Command("Profiler.start", ImmutableMap.of()));
//register to profiler events
driver.getDevTools().addListener(new Event("Profiler.consoleProfileStarted", ConsoleProfileStarted.class), new Consumer<Object>() {
#Override
public void accept(Object o) {
//do something
}
});
Until the Profiler domain will added to Selenium java client, you will have to supply your Mapper.
Related
A project I'm on is developing a web app at the same time as an ios app (for the same thing) and I'm hoping to be able to use existing Selenium tests, but we're having trouble with selectors. Is there a selector type or attribute name that can be used for both Selenium Webdriver and Appium ios, so that I can just set a variable to either browser or app and they run and work on both. Nobody on this project has used Appium before, so we are lacking a lot in knowledge.
I tried using IDs and found that ios doesn't work with them, changed to names and found that names have been removed from appium. If possible we'd prefer to use a selector that will be the same in the browser as it is in the app.
Thanks
You can create one object repository file which contains the locators for both WebApp and iOS app. Then you have to follow the below process
Create WebDriver and AppiumDriver instances
Use the relevant drivers for locating the elements in WebApp as well as iOS app. We can use both the drivers within a test case.
Please note that, the way WebDriver and AppiumDriver identifies the elements will be different. For example, in WebDriver if an element is identified by using ID then similarly in AppiumDriver an element can be identified by using the findElementByAccessibilityId.
Even though AppiumDriver uses the same logic which WebDriver uses, the method names will differ. Please find the link for all the methods used by AppiumDriver
Hope this helps.
How about creating multiple object repositories and loading the relevant object repository based on the underlying platform?
1. So you need to store locators of both the platforms in separate repositories
2. Create a Interface / wrapper which would load relevant repository based on the platform on which tests are going to run.
Didn't quite get the question but for Appium You have separated annotations for bot iOS and Android platform similar as for web via:
#FindBy(id="buttonOK")
private WebElement buttonPopUp;
Here is example for Android and iOS
#iOSFindBy(id = "lets_do_it")
#AndroidFindBy(id = "message_popup_dismiss_button")
#WithTimeout(unit = TimeUnit.SECONDS, time = 1)
private MobileElement buttonPopUp;
So in same pageObject you have covered both platforms.
Mobile platform can work together, but recommendation is not to mix web and mobile, but mobile platforms can play together just fine, and is recommended so can share same code functionality.
The FileDownloader class provided on the question below worked fine until I upgraded to selenium 2.46:
Programmatically downloading a file using Selenium in Java
When I run the same test with selenium 2.46, I now get redirected to the login page. Did anyone else face this issue?
The Selenide project has a great, really well thought out, download helper in it. I would investigate that, either as an example, or possibly actually using it.
$.download()
I have a general question about selenium:
Is there a way to run selenium webdriverv2 using java, in different browsers(chrome\firefox\safari...) without opening any browser?
I read about selenium grid, unfortunate in grid it open the browsers/machines.
If you dont want to open a browser, then Selenium isnt for you. If you want headless testing my suggestion would be to look into CasperJS.
I don't use Selenium for 6 month, but when I used it, it was necessary to open the browser and I think still being like that today.
I am wondering if anyone could expand on any of these attempts or has any other ideas for catching JS errors using WebDriver that will work in Firefox, Chrome, Internet Explorer, and Safari.
Here is what's been tried so far:
Attempt – Problem:
JSErrorCollector.jar - Works fine, but is a Firefox only solution.
Inject JS into page source – I injected window.onerror code into the page’s source code using WebDriver, but any initial errors are missed because the injection is too late.
BrowserMob – I can intercept the HTTP response and planned to inject the window.onerror code into response body, but the author has not implemented the getBody() method yet, so only headers can be modified, that I am aware of. The body is always null for all responses. (I was on a webpage where the author talked about implementing getBody() but it hasn’t happened yet and I cannot find it again)
Fiddler – JS will inject correctly, but Fiddler is Windows only so Safari won’t work.
Parent/Child windows – I use javascript to open and store a reference to the test page’s window. The window.onerror code is contained in the parent window so it will not miss startup errors in the child window. I cannot get this to work in anything but Firefox and Chome somewhat. I already asked a question about it here.
Selenium RC – I haven’t tried it because all my tests use WebDriver, but I know it has some kind of method like captureNetworkTraffic(), but I don’t think it can be used in WebDriver.
IE error popup – I was going to use the parent/child solution for Firefox/Chrome and then look for the IE error popup. This popup displays when the setting is checked to display it. The popup is a native Window window (I think) so I cannot use selenium to access it.
Read browser console – I could not find a way to do this in all browsers. In Chrome I found a way to save the console log to a file and then read the file. That is as far as I got.
I would like a solution similar to BrowserMob since it seems like it would be a cross browser solution. Are there any other proxies that can be put in the test and intercept the response? It would have been excellent if the getBody() method was implemented. I also like the parent/child solution because it also seems like a simple, cross browser solution, but it is not working for IE (parent/child question again).
Thanks for any help.
I don't know of any way to directly catch Javascript code errors by a test framework. If I were to guess, I would use PhantomJS. Or, maybe something like MITM Proxy would work?
As a sidenote, if you run Selenium2 Grid Hub with a separate Node, you can pass a Java option to the JVM of the node like this that will allow a proxy through Fiddler to work. Fiddler listens (by default) on port 8888. With this method you can watch packets.
:: batch script: Set JAVA_OPTS java options to JVM
SET "JAVA_OPTS=-Dwebdriver.chrome.^
driver=%CHROMEDRIVER%"
IF "%PROXY_TO_FIDDLER%"=="true" SET "JAVA_OPTS=%JAVA_OPTS% -DproxySet=true^
-Dhttp.proxyHost=127.0.0.1 -Dhttp.proxyPort=8888"
I created scripts you can use to start your grid and node here. It seems to me that you could use this method to also talk to BrowserMob proxy on port 8080? I have not tried that.
I am developing a java application. I have scenario to take screen shot of the URL that comes in to the server.
Is there any java(or any lang) browser library to load webpages and get some screenshots of the loaded page. It would be nice if the lib allows DOM traversal.
Update:
java(or any lang): Any other language is not a problem but the library should co-operate with java.
I have tried to setup Qt Jambi and spent a lot of time on this but the result is nothing.
If you provide any concrete material to setup Jambi, it would be appreciative.
I also gave a try to spynner.py. My native language is Java and i thought i could use spynner.py with Jython. But, PyQt cannot be used with Jython. So, i am not expecting any answers related to Python.
Basically, I need a library to do:
Take Screen shot.
Some DOM traversing.
Some Javascript Execution.
and to get the result of the Executed JS code.
Thanks.
I appreciate all the responses. I ended up with phantomjs. It fits well for my needs. Its a command line tool.
Selenium/Webdriver provides all this functionality.
Webdriver provides a simple api allowing you to "drive" a browser instance. Many browsers are supported.
See here for a simple example:
http://seleniumhq.org/docs/03_webdriver.html#getting-started-with-selenium-webdriver
Traversal of the dom using the "By" locators:
Good examples here: http://www.qaautomation.net/?p=388
driver.findElement(By.name("q"));
Execution of Javascript:
http://code.google.com/p/selenium/wiki/FrequentlyAskedQuestions#Q:_How_do_I_execute_Javascript_directly?
WebDriver driver; // Assigned elsewhere
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("return document.title");
Screenshot capture:
http://seleniumhq.org/docs/04_webdriver_advanced.html#taking-a-screenshot
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
In java, you should read the following stackoverflow posts :
Programmatic web browser Java library
Take a screenshot of a webpage with JavaScript?
Embed a web browser within a java application
Because you say "or any lang" :
In Python, you have Spynner :
Spynner is a stateful programmatic web browser module for Python with Javascript/AJAX support based upon the QtWebKit framework.
According to the documentation, here's a small snippet :
import spynner
browser = spynner.Browser()
browser.load("http://www.wordreference.com")
browser.runjs("console.log('I can run Javascript!')")
browser.runjs("_jQuery('div').css('border', 'solid red')") # and jQuery!
browser.select("#esen")
browser.fill("input[name=enit]", "hola")
browser.click("input[name=b]")
browser.wait_page_load()
print browser.url, len(browser.html)
browser.close()
This site does the screenshot job:
Tutorial:
http://www.paulhammond.org/webkit2png/
The program:
http://www.paulhammond.org/2009/03/webkit2png-0.5/webkit2png-0.5.txt
Could it be any easier ? :)
There are some other tools mentioned at that page:
"
If you use a mac, but don't like the command line then you may want to try Paparazzi or Little Snapper.
If you use linux you may be more interested in khtml2png, Matt Biddulph's Mozilla screenshot script or Roland Tapken's QT Webkit script.
"
You could use Rhino, Gecko for the javascript execution.
For dom traversal there are many options, but if you are using Rhino you could use jQuery to make it even easier!
Hope that works out for you!
If you need a screenshot, I guess the quality of rendering is important for you.
We had a similar scenario. What we ended up doing is to run firefox on headless mode, actually browse the webpage and get a screen shot in memory. It is not trivial, but I can give you more details if you wanted to go for it.