Testing a file streaming with selenium? - selenium

Is it possible to test a webpage which supports an export mechanism? This export mechanism streams the data displayed in a table via xml to the user. For now it's sufficient to test if the streaming works and the user receives a file, regardless of the file content. Any ideas how I can achieve this with selenium?

I googled around for a while, and according to selenium core FAQ, u may need to use firefox template to do that.
u may take a look of this:
http://oopsnullpointer.wordpress.com/2011/01/14/selenium-handling-testing-downloads-with-a-custom-profile/
I have not yet personally tested that though.

If you're using Selenium script by itself, this would be hard, if not impossible. Luckily, you can run selenium from Java, C# and more and have it integrate with JUnit, NUnit or your favorite unit testing framework. If you use one of these languages, you could use it to cause selenium to export the file to a specific location, then use C#/Java to actually go out on the file system and verify that the file was correctly exported to the location, and do any other validation on it.
For doing this development, you can typically find all the client libraries under the bin directory of Selenium server. If you're using Selenium IDE, you can even export your test cases to C#, Java, Ruby, or whatever else, or just use it as an example to manually write your own in code.
Hope that helps!

Related

Can we customize Chrome browser launch with different options using Chrome Java API? [duplicate]

I am using the Karate framework to do the API testing. As part of CI efforts, we send an email at the end of test execution listing the summary of test results. There is a need to include the screeshot of the test execution counts from 'overview-feature.html' file.
I did so through the TestRunner.java file - launched Chrome using Chrome.start() and then using it to take screenshot. It all works well locally on Windows.
However when executing on CI server which is a Unix box, the chrome executable is not present in the default location (usr/bin/google-chrome) and hence the connection for the localhost fails.
Is there a way we can change the default location of the chrome executable?
PS: Apologies if this was too trivial to be asked.
Yes Chrome on CI is hard to get right, refer: https://stackoverflow.com/a/62325328/143475 - note that CI boxes typically are "headless" a browser may not be even installed.
I think the best thing for you is to ZIP the HTML and send it. But I really think you need to work with some CI experts, because the report generation and e-mailing business is normally done by things like Jenkins. What you are doing is certainly not normal or best-practice.
If you really want, there is a Karate Docker container that can give you a proper Chrome instance (see docs) but that is overkill for what you need.
EDIT: The Chrome Java API allows for customization of the executable path and this is in the docs: https://github.com/intuit/karate/tree/master/karate-core#chrome-java-api
It should be something like this:
Chrome.start("/opt/blah/chrome");

How to handle Flash objects using Selenium Web Driver

How to handle Flash objects to perform some actions in my application. i am unable to identify the element. can any one help me for this issue
Selenium automates Web browsers.
From http://seleniumhq.org..
Selenium automates browsers. That's it.
Flash objects are impossible to automate using Selenium as flash objects are not technically 'browser driven' like javascript is. You'll have to find other software to automate Flash.
Source - I am a contributor / maintainer of the project.
If you are using Ruby language for Selenium-Webdriver automation then you can use "Gem SIKULI" using which we can deal with all Flash elements. http://rubygems.org/gems/sikuli
But it is not that much reliable.
Gem sikuli needs Jruby i.e Java+Ruby
Not possible. All you can do is do some clicking based on the coordinates, but this is really unreliable.
It is not possible to automate flash objects with selenium as selenium is only for HTML so you can use 3rd party API Sikuli for this purpose sikuli provides image based automation in which you take image of an object and then use that image as reference to perform your operation .So in other words in sikuli object identification is done via image processing
please check following simple blog posts to learn about usage of sikuli
Automating flash calculator with sikuli integration with selenium.
Add the flashdriver jar into your project and then use the FlashWebDriver method to operate the Flash file.

Exporting Selenium code to a file people without selenium can use

Is there a way to export Selenium code into some sort of file I could send to others to use without selenium? Preferably inserting it into some html file or something they wouldn't have to install on their computers. Thank you!
Kind of, depending on what you use currently.
If you use the IDE, then yes. The steps the IDE records are essentially put into a HTML file that it reads. You can just give that HTML file to someone else, have them import it into the IDE and it would pick up from there. This has the dependency that the user must have an FF version supported by the IDE.
If you use the WebDriver, then no. At least not without much work - even just due to the dependencies. For instance, you have the various drivers, that the user would need to have a copy of for the tests to work. You have the language that the tests were coded in, for instance Java - you'd have to ensure the user has Java.
You could package them up into a nice installer - whereby the installer gets the dependencies for the user, but this will be slow, unreliable and totally not worth the time and effort you place into it. Think of it when you are installing large programs - it's also downloading lots of dependencies for that application too. Visual Studio/Eclipse are prime examples, they depend on hundreds of things. So when you install them, they are not just installing the core files, but the things they depend on too. You could replicate the same thing.
In order to run a Selenium test you would need one this too things:
Selenium IDE running on Firefox, in this case you just export as html and import in the other computer
The runtime of the specific language you are using to export (i.e. for jre, .net for C# etc.) plus the selenium-server running
As for your question, I would say there is no way to export a test case into a single file to be executable by itself.
You Can Export your Test Case Or Test Suite in different languages.
If you are using Selenium IDE follow these steps:
After recording your Test Case click on file menu.
Click on Export Test Suite As.
Save this file.
Now you can send this file.

Implementing selenium with Jenkins and PHPUnit

I'm trying to do set up some Selenium WebTests using PHPUnit, but php is no longer supported by Selenium IDE, does this mean I have to re-write all my tests into php in order to use this method?
I'm trying to set up a continuous integration system, but have never even used one before, I tried using jenkins-php.org but it wasn't very helpful.
The newer releasee Selenium IDE "claims" it does not support PHP,
But you can still convert your IDE to PHP or PHPUnit.
(In Selenium IDE) Option > Options > Enable Experimental Functions.
With this option checked you can switch your format under Options again.
You may still want to review your code.
Hope this helps and it is what you meant by "Selenium IDE does not support PHP".
I was able to find: https://addons.mozilla.org/en-US/firefox/addon/selenium-ide-php-formatters/
It allows output from Selenium to PHP, either PHPUnit format or Selenium Testing.
However after all this playing around it became apparent that the best way was to use htmlSuite, it has the most support when it comes to automation and seems to work out of the box, whereas PHPUnit testing requires lots of tinkering.
After a lot of hacking around it became apparent that the best solution is this tool:
http://www.enjoyxstudy.com/selenium/autoexec/index.en.html
It works out of the box, supports htmlSuite, works with windows and linux, runs most browsers, sends email reports, can get new tests from SVN, integrates with Jenkins well, and works with Selenium tests, its not PHP based tests but it works wonders compared to the other tools I tried out.
Really, so much easier, very user friendly, free and works out the box.

Any good command-line tools (for a build server) for validating websites?

My team creates a number of dynamic/data-driven websites. We use a CruiseControl.NET to download the code, create test data, run unit tests, and install each site into IIS for manual testing. However we haven't found a good tool (or tools) that can actually run through some simple tests of the websites, such as checking for broken links or invalid HTML.
Are there any good tools that we can incorporate into our build process to automate basic website testing? E.g. check for broken links, check for HTML/JavaScript/CSS coding errors, and so on? Load testing would be great too.
Looking for something totally generic; we don't need to write/record scripts for playback. Just something to cover the basics.
Thank you!
-James
For link checking you could always look at http://linkchecker.sourceforge.net/ if that isn't suitable they list other alternatives.
It also seems like it is an active project.
JSLint does javascript validation and there are two options for executing it via the commandline so that might be worth a look too http://www.jslint.com/