How to fix “Firefox is already running” error on Linux

How to fix “Firefox is already running” error

Sometimes when I try to start Firefox, it warns me that Firefox is already running. The message looks like this:

Firefox is already running, but is not responding. To open a new window, you must first close the existing Firefox process, or restart your system.

Usually, you can just kill the firefox process to solve this problem. For example, on Linux the command “ps auxwww | grep firefox” will find the process number and then “kill [processnumber]” will work fine. 

If none of that worked, try killall [processname]. Example to kill Firefox

killall firefox.

Taking Fullscreen Screenshots with Webdriver and in Internet Explorer too

Someone had contacted me yesterday about how to take screenshots in Selenium. There are tons of advantages of doing this. First, you can run a job anytime you want, have it visit every page on the website, and review the screenshots for obvious bugs. Second, we can insert screenshots at breaking points, or during any function.

The dreaded problem from what I’ve seen scouring the Internet is how to take screenshots in the Microsoft IE family.

Many have gotten success from using the following code in Firefox and have wondered how to get it work across IE:

selenium.captureEntirePageScreenshot(“/users/[username]/[folder/screenshot.png”,””);

First, a lot of things have not worked for me. I’ve tried SnapsIE but I wouldn’t go this route as SnapsIE (The latest snapsie-0.2.) is no longer being actively developed and the last update was in 2008. I tried registering the DLL in IE 9/10 and wasn’t able to get it to work. I can only imagine this would be of no purpose if it only worked in older browsers. Hell, IE8 came out March 19, 2009; so SnapeIE last update was almost a year before. I did not check if this worked for IE8.

captureScreenshot()
This method works in FF an IE but the big problem is that it only takes a screenshot of the content within the screen view. Not too useful if you want the full page.

captureEntirePageScreenshot()
This method does not work either in IE at all; so this is pretty much a useless command for IE screen shots.

Anyway, let’s get to it.
Due to Selenium limitations, you want to user WebDriver to so this because WebDriver makes direct calls to the browser using each browser’s native support for automation. That’s key here. Selenium-RC worked the same way for each supported browser. It ‘injected’ javascript functions into the browser when the browser was loaded and then used its javascript to drive the AUT within the browser. This causes many problems so let’s utilize Webdriver’s powerful capabilities instead.

So, first thing you want to do is download Internet Explorer Driver. The InternetExplorerDriver is a standalone server which implements WebDriver’s wire protocol. This driver has been tested with IE 6, 7, 8 and 9 on appropriate combinations of XP, Vista and Windows 7. Get the download here. https://code.google.com/p/selenium/downloads/list

Add this exe file to your PATH variable on your Windows machine.

If you need help doing this, please send me an IM.

Once you’ve added this .exe file to your PATH variable, you’re all ready to go.

Try the following code in your test script and Run as a JUnit Test/Ant build, etc.; however you have your scripts set up.

-@Before
-public void setUp() throws Exception {
-//driver = new FirefoxDriver();

-WebDriver driver = new InternetExplorerDriver();
-driver.get(“http://www.nydailynews.com”);
-driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
-File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
-FileUtils.copyFile(scrFile, new File(“C://[folder]//[somesubfolder]//nameofmybeautifulscreenshot.png”));

This script opens up a very long page and takes a screenshot in IE.

This should work for you in the all the IE browsers that I’ve listed above.

If you’re sick to your stomach of trying this, there’s a pretty cool tool you can find here which will do it manually for you. It works similar to the existing screenshot plug-ins that are available for Chrome and Firefox. But in IE. However, this little manual plug-in did not worked in all the IE’s except in IE 10.

Happy Testing.

Getting a list of all link URL’s on a page with Selenium..

You get a list of all URLs on the page by using the getHtmlSource command to get all of the HTML source code from the page. You can then use either a regular expression or HTML parser to extract what you’d like. In this case; all of the a href elements on the page.

If you’re using Selenium, you can the following code into your script.

This will open up yahoo.com in Safari and get a list of all the link on the page and put the output into your console. If you use this as a function for every page that loads, the output in your console could get pretty lengthy if you’re dealing with multiple pages. It would be better to have this output in a text file.

If you’re using JUnit Reports to do your reporting, you can easily have all that information output into a text file. If you’re new to reporting, please see my post on how to set up JUnit reporting in Eclipse with Junit and Ant.

@Before
public void setUp() throws Exception {
selenium = new DefaultSelenium(“localhost”, 4444, “*safari”, “http://www.yahoo.com”);
selenium.start();

}

@Test
public void testUntitled() throws Exception {

selenium.open(“/”);
selenium.waitForPageToLoad(“20000”);

String htmlSource = selenium.getHtmlSource();
Pattern linkElementPattern = Pattern.compile(“]*href=\”[^>]*>(.*?)“);
Matcher linkElementMatcher = linkElementPattern.matcher(htmlSource);
while (linkElementMatcher.find()) {
System.out.println(linkElementMatcher.group());
}
Object myurl = selenium.getLocation();
System.out.println(myurl);

@After
public void tearDown() throws Exception {
selenium.stop();
}
}

Getting Started with JUnit Reports with Eclipse and Ant…

So a lot of people have been asking me about how to create JUnit Reports with their automated test cases. I’m going to show you how to create these reports in the easiest way possible. You will not have to download anything, add any code, etc. You will only have to use generate the HTML report using Ant with Eclipse.

The first think you have to do is generate the Ant build. You can do this by:

1. Right click on the project and
select Export –> Ant Buildfiles (this will be under General) –> Next–> Select the project that contains your JUnit tests –> Finish.

The default JUnit output directory is appropriately named “junit”.

2. The next thing you have to do is resolve your dependencies by making sure that the junit.jar is added to
Ant’s “Global Entries.”. You can do this by.

Window->Preferences->Ant->Runtime->Global Entries and Add External JARs… Navigate to your “eclipse” directory (where eclipse is installed). It is under “plugins” directory and presently the junit.jar is in a directory named “org.junit_3.8.1”. If this is missing then you will see error messages since
junit is an optional Ant task.

* If you are using a Mac, Preferences are under the the Eclipse menu.

3) Finally, right-click on the Ant build file build.xml (this file is the one you created in Step 1) and Run As->Ant Build. This will display a list of targets. All of the launch configurations you have previously configured will have a corresponding target in your Ant build file. Select the desired target(s), and also select the “junitreport” target (very important). Check the “Target execution order” text area to make sure the junitreport is run last.

As you can see I’ve specified the order in which I want my cases to run (below)

JUnit Targets

Whenever you run a test case it will generate results and will be placed in the junit output directory. These results are formatted into an HTML report by the junitreport target and stored in the junit output directory.

As you can see below my automated Test Suite has completely run and you can see which tests failed and which passed (below). I see my cases for login, registration, and account-sign up are failing. Upon further investigation, these are failing because the web service is down on our staging server.

Pass or Fail

This is a fast and easy explanation of how to create JUnit HTML reports, but hopefully it helps get you off your feet. Next time around, we’ll have some more fun when I show you how to extend this output to get more information displayed in the report. For example to add an additional column which contains link to a screenshot taken by the test.

Happy Testing!

Time to Automate

Automated testing has always been the subject of a lot of criticism. This has been due to the fact that automation loses it’s meaning when the software is constantly changing. On top of that there is always the challenge of debugging these scripts when they fail due to a false positive. This is when the script fails not because of a bug in the software, but because these is a problem in the automated test framework. Possibly in the script, or maybe there is a problem with the proxy setting.

Therefore, it’s very crucial to all QA people to know when it is the right time to automate. The best and easiest to even think about if something can be automated would be when the functional requirements have been truly stabilized.
After deciding that this is the case there are a file things I would certainly consider before makin the decision.

1. Is this test repeatable? Can I execute the same script repeatedly and will this function that I am testing have to be tested over and over again where I will have to execute this script on a continuous basis.
2. What is the ROI or return on investment (time wise ), when you want to automate the test? I say time wise because there are many open-source automation tools available that are of no cost so if anything will be wasted; it will be time.
3. Script Death. If I am executing these scripts repeatedly and they fail on a regular basis because of some minor change to the software, it may not be worth the hassle of having to maintain and debug your scripts.
4. Is this script reusable. If we were moving a release from multiple environments during a deployment, then the tests that we are executing can be reused in these different deployment environments. Also, can this code that is not going to change, also be used to help your developers unit test their code? For example, a developer may not want to fill out a five-page form when unit testing that data transmitted through Web Services is functioning as expected.
5. The most easiest way to determine this if you are really not sure is to ask yourself; Has this manual test that I have been performing on a regular basic when regression testing become so tedious and repetitive that it literally becomes painful performing the test manually.

This is where automation seems like the a really good choice. Automating your functional tests will allow you to:
a)Test your Site
b)Write your scripts
c)Execute your scripts
d) Generate all of your Test Script pass/fail documentation, including screenshots, using third-party libraries specifically created for reporting test results in your chosen programming language and all done across different platforms and also cross browser to boot. This cuts your time by more than 80%.

These libraries also provide the programming support that allows you to run commands from a program of your own design.

After reports are generated, you can then set up a review where you might involve IT, your project manager, and Creative to view the results of your tests. Now you have your full QA functional tests and also you regression test and a way to re-export all of these reports again during upcoming release reviews.

Here are some free tools to get you started:

1) Selenium FireFox Plugin – http://seleniumhq.org/projects/ide/
2) Firebug – http://getfirebug.com/whatisfirebug -Firebug integrates with Firefox to put a wealth of web development tools at your fingertips. You can edit, debug, and monitor CSS, HTML, and JavaScript live in any web page.
2) Selenium Remote Control – http://code.google.com/p/selenium/downloads/detail?name=selenium-server-standalone-2.0b3.jar&can=2&q= – is a test tool that allows you to write automated web application UI tests in any programming language against any HTTP website using any mainstream JavaScript-enabled browser. It can automatically launch and kill browsers.
3) JUnit – https://github.com/KentBeck/junit/downloads – JUnit is a simple, open source framework to write and run repeatable tests
4) Eclipse IDE for Java Developers – http://www.eclipse.org/downloads/ – Eclipse is a multi-language software development environment comprising an integrated development environment (IDE) and an extensible plug-in system. It is written mostly in Java and can be used to develop applications in Java and, by means of various plug-ins, other programming languages including Ada, C, C++, COBOL, Perl, PHP, Python, Ruby (including Ruby on Rails framework) Scala, Clojure, and Scheme.
5) Selenium Java Client Driver – http://selenium.googlecode.com/files/selenium-java-2.0b3.zip – In order to create scripts that interact with the Selenium Server (Selenium RC, Selenium Remote Webdriver)or create local Selenium WebDriver scripts, you need to make use of language-specific client drivers. There are other client drivers available on the Selenium downloads Page.

Happy Testing

Earl