Issues in automation framework for web page testing - c#

Currently I am in process of building an automation tool for testing webpages. Already aware of selenium tool but will not be using that currently as our framework has already been built and requires minor changes to make it reliable. While testing this framework with test pages (html and javascript only) I encounter issues such as webpage takes a lot if time to load(happens like 1 out of 20 times). And when you try to find the co-ordinate and click the button or try to find the element in the webpage and click it sometimes it fails as button doesn't even exists at that point of time.
Currently using Thread.sleep or retry n number of times. Are there any better solutions to remove this flaky behavior?

look into WebDriverWait class. There is a respective binding for c# as well. Also, I have discussed the WebDriverWait here.

You can try to use Implicit waits
Read about it here http://www.seleniumhq.org/docs/04_webdriver_advanced.jsp
Basically you set it once per session. If you can't find an element, selenium waits the amount of time you set before throwing the exception.

Related

How to wait for the end of the loading of a webpage before resuming execution using cefshrap (C#)

I'm currently working with CefSharp on a web application. I would like to be able to pause the execution of the program while the webpage is loading and then, once all the elements have been loaded, resume the execution (for example click on a button or enter a given field).
I'm a former java developper and have used Selenium on a few projects. I know that what I'm looking for is a CefSharp equivalent to the "driver.manage().timeouts().implicitlyWait(...);" method of Selenium. I've been looking for a solution for a while and have found a few threads speaking of this problem however none of the solutions seems to work.

Why is Selenium + Firefox freezing while loading pages?

I'm running the latest version of Firefox and Selenium in C#. I'm automating a crawler to find data in a web app. The server is super slow, so I've had to add in many waits plus put in initial wait using thread sleep.
So my crawler gets a list of items, then iterates: it has to load the details of each item by clicking on its id. Then it goes back (these navigation controls are all built into the web app, no browser controls used), rinse and repeat. The server shows a progress spinner during loading details and going back. The crawler reaches the same item each time and locks, eg: the progress spinner freezes and Firefox crashes.
I've tried a couple of different things including using background threads, deleting all cookies, and checking if my memory is overloading. I haven't noticed any peaks in memory (in task manager). I also tried restarting web driver but it doesn't really work out well because this is a web app.
Is there something I'm overlooking? (I tried to be as clear and elaborate as possible)
Forgot to mention, when I stop the program the page 'unfreezes' and I can continue use from that point.
This was a known problem with C# selenium web bindings 2.39 and earlier. This should now be fixed in 2.40. The problem was to do with a deadlock in the web bindings code when redirecting console logging from firefox. If you upgrade to 2.40 it should solve it. See here under the heading 'Update 25th Feb 2014' for more information.

Waiting for page to be fully loaded using WatiN

I have two questions related to the same problem...
Q1) I am using WatiN(3.5) for automation of a website.
The situation is that I want to obtain a div tag when the result page is fully loaded but WatiN don't wait for that page to be campletely loaded and tries to obatin that div which results in getting div with null. This div is populated by AJAX. This is th code that I am using to avoid that error but it does not work.
while (resultDiv == null)
{
browser.Div("ui-tabs-1").WaitUntilExists();
resultDiv = browser.Div("ui-tabs-1");
}
So how I can wait for a page to be completely loaded by using WatiN?
Q2) I found a solution for above problem here but I stuck at a point as I could not find a reference of library for these interfaces i.e. IElement and IBrowser. These interfaces are bring used in the extension methods.
I have also asked the author of that article and waiting for his reply.
I am making this apllication by usng WatiN 2.5 and .Net framework 3.5 in VS 2010.
I have ran into similar problem with watin on a site using Ajax.
This is the workaround for this.
//After click on link/Tab/Button on which the result is loaded in non Ajax websites.
We have a function here, browser.WaitForComplete() but it works only when the page is in loading state. but in case of Ajax on a part of browser window gets updated. so no loading state for browser.
So one solution for this problem is
Use Thread.Sleep(10000); This time can vary upon the normal time the website takes to load the required div.
Thread.Sleep can be used but for anything other than a proof of concept that waiting for something to load is indeed the issue Thread.Sleep should be avoided. Sleeps add in unnecessary idle time if you sleep for the max time the action is going to take, and give false positive failures when waiting less time.
See Jeroen's link in his response here if you are testing an ASP.NET Ajax site: In WatiN how to wait until postback is complete - WaitForAsyncPostbackToComplete. I used this idea for some methods and properties to rid my code of a lot of long Sleep calls. Tests ran faster and results were much more reliable.
If the specific JS call won't work as you're using a different clientside framework, using the basic polling concept with shorter sleeps in a loop is going to do you better than long sleeps.

Automated Browser Testing using selenium, Nunit, Selenium Grid, C#, webdriver/remote control

I have been researching on how to automate browser testing for a number of weeks now using all kind of different methods. Seleniums website is very vague on which is the best route to take.
I have installed
Selenium Webdriver
Remote Control
Selenium Grid
Apache Ant
Nunit
(and pretty much everything else you could need to do this)
I finally give up trying on my own and want to know the best way to do this.
I want to be able to
Load the same webpage on a number of different browsers
Load the same webpage on a number of virtual machines(which I have set up)
Be able to take snapshots comparing the different browser results.
I have knowledge of programming in C# and would prefer to run my tests through Nunit.
Can anyone give me directions or point me to a website that already has them?
Thank you.
I have built up a test framework using junit with Selenium WebDriver that satisfies every one of your points. While its not exactly what you're asking for, I feel it may be beneficial to you regardless.
Load the same webpage on a number of different browsers
Using Selenium's grid, this is very simple to set up. Set up some virtual machines with the environments you're looking to test in. In our environment, for example, we have a grid running with four nodes (as virtual machines) with a setup like the following
Windows with IE7 and FireFox
Windows with IE8 and FireFox
Windows with IE9 and Firefox
Linux with FireFox
Note that Selenium recommends that only one instance of IE be allowed to run on the Windows nodes. On each of the aforementioned nodes, there is one instance of the specified IE and five instances of the specified FF allowed to run at any given time. With the grid setup and the hub configured, firing off tests is a breeze. In WebDriver, use the DesiredCapabilities object to set up the desired environment and then just send the test off and wait for the result to return.
Platform desiredPlatform;
DesiredCapabilities desiredCapabilities;
desiredPlatform = Platform.LINUX;
desiredCapabilities = DesiredCapabilities.firefox();
desiredCapabilities.setPlatform(desiredPlatform);
desiredCapabilities.setVersion("11");
WebDriver driver = new RemoteWebDriver("http://hubURL", desiredCapabilities);
Load the same webpage on a number of virtual machines(which I have set up)
I solved this one by forcing the tests to run, albeit in an unconvential way, in a threaded manner. Each JUnit test uses a shared thread library I put together which creates all the necessary RemoteWebDrivers needed in separate threads. Each of these threads runs simultaneously on its node while the parent thread sits and waits for all to terminate. Then on to the next test which is run multithreaded as well.
There were a couple problems I encountered such as retrieving the Junit stack traces in all of the child threads. I solved this by redirecting Std.err to a bytestream on the parent thread. All errors get routed to that stream which I then convert to a string and print out to Std.out at the end of each test. The html pages generated at the end of the tests include Std.out which worked out perfectly.
Be able to take snapshots comparing the different browser results
While I have gotten this to work, there are some inherent problems with grabbing screenshots remotely. IE will return black screenshots if the process is running as a service. The workaround was to just run the jar from the command line and keep the user logged in, in which case the screenshots return correctly. This is a known issue in the browser and there really is no nice solution to the problem. Taking screenshots works roughly like this
WebDriver augmentedDriver = new Augmenter().augment(driver);
TakesScreenshot ss = (TakesScreenshot) augmentedDriver;
String base64Screenshot = ss.getScreenshotAs(OutputType.BASE64);
byte[] decodedScreenshot = Base64.decodeBase64(base64Screenshot.getBytes());
FileOutputStream fos = new FileOutputStream(new File(imageName));
fos.write(decodedScreenshot);
fos.close();
which saves the captured screenshot from the remote machine's running browser onto the local machine.
In reality, browser automation is still struggling to stabilize itself. There are a number of important features, such as the ones you're asking about, that just aren't implemented solidly that I know of in any framework. With time, though, I'm sure a lot of this will settle down and QA developers everywhere will rejoice.
As for the 2nd point: instead of using Grid you can let your continuous integration server do the job. In my company we use Jenkins and so called Configuration Matrix - it let's you run the same job on multiple Jenkins nodes.
As for the 1st one, I think Jenkins could be helpful here too. You can run multiple jobs on the same node. Although I've never tried that so I am not perfectly sure. And this is just an idea, I wouldn't really recommend such solution. You may also want to read this blog post describing how to run test in parallel using Selenium Grid. For people using Java I would recommend reading about parallel tests with TestNG.
Your third point is a little bit vague. What do you mean by snapshot? And what kind of result you want to compare?
Selenium RC is outdated and webdriver is more reliable way of creating selenium tests. I see the responses above cater more on java side. Below mentioned is more information on how to achieve the questions asked here using C# and selenium webdriver
On how to setup the IDE (VS express), nUnit and selenium refer
How to setup C#,nUnit and selenium client drivers on VSExpress for Automated tests
On Creating simple script that launches a browser does few steps refer
Creating Basic Selenium web driver test case using Nunit and C#
On how to Load the same webpage on a number of different browsers suggest referring
How to invoke locally different types of browser driver using selenium and c#
On Load the same webpage on a number of virtual machines(which I have set up) for this, you need to use Remote webdriver instead of normal webdriver. Also with remote webdriver, you can launch different types of browser. Refer this webpage
How to invoke/run different type of web driver browser using remote webdriver in C#
To take snapshot on different browser you can refer the link
Capturing screen shots using remote/local webdriver in C#/Selenium webdriver
You might also consider the free Telerik Testing Framework. This is the underpinning for Telerik's commercial Test Studio product. The Testing Framework provides cross-browser support, does a great job with dynamic content situations (AJAX), and also lets you handle OS-level dialogs like file upload/download dialogs. You can also take snapshots of the browser at any point.
You can wrap the framework inside whatever runner you prefer. I've used NUnit and MbUnit without trouble.
There's also an option for a support package if you need help with your automation.
(Disclosure: I work for Telerik as their Test Studio evangelist)

Auto populate / screen scrape multipage webform

Firstly apologies if this is a duplicate question, I have spent a while searching and can't find anything that looks to be the same.
I need to automate the completion of a multi page web form and then process the result from within an asp.net system. The ideal solution would be to create a web service which takes in some data, then processes it through the website and returns a result - I can then use this in any app that requires this functionality. The form that needs completing is quite complicated, and also includes some if / then / else logic when going through e.g:
Complete personal details
Enter postcode
If 1 result found goto 5
Display list of possible addresses, when one selected goto 5
If time at address < 3 years, display new address page
etc.
I have created a solution which launches an ActiveX browser control and controls the website as if a user were entering the data which works well however is subject to a limit on concurrent users (anything > 1 starts to cause issues, >2 is not allowed by windows default settings), is there a better way of doing this? I've heard of Selenium although not used it, would this be a possible solution?
I have looked at using the WebClient class, and have used this in the poast for screen scraping systems however I don't know how I could chain these calls together to allow for the full workflow.
FYI - this work is all being undertaken with the full knowledge and consent of the site owner. They have a queue of development tasks which building an internal API does not feature on so whilst they are happy for this type of solution to be implemented, will not be able to change anything their end.
Thanks in advance
There is a .NET port of Watir called WatiN - it might be worth giving that a try if you haven't already.

Categories

Resources