Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Hot answers tagged

50

I think it's difficult to make through-the-UI tests reliable. The challenge comes down to the difficulty of reliably controlling and observing the variables that matter to your tests. Whether this is worthwhile depends on your ability to make your test code more resilient, and on the value of being able to run the tests automatically. Asynchrony. For web ...


14

I +1'd Dale's answer, however I wanted to add a few additional things. Dale is absolutely correct that a large part of the fragility of automated UI tests comes from timing issues and can often be fixed by using polling (referred to as implicit waits in Selenium) or latches. I also agree with his assertions on identifying elements and depending on the ...


14

I think that Selenium functional tests are reliable enough if done right. In my opinion your fragile tests are not selenium specific but depend on how the tests are implemented. The first step to resolve this issue is finding out why most tests fail that shuldn-t fail. Timing? External Services not reachable/available? Wrong database content?


13

How to get started with Selenium: A Brief Overview So you want to automate browser-driven tests, and you're not sure where to get started. You've heard of this "Selenium" thing, and you think it's what you want, but you can't be sure. Fret not! Here's a quick rundown of what you're looking at and how to get going. This is mostly adapted from two sources: ...


11

To broadly address your question, just pick some test cases with simple interactions that aren't very dynamic and automate those. Trial, error, and practice will get you there. Is Java mostly used for Selenium tests? Do you recommend it over C#? According to StackOverflow, there are more Selenium tagged questions in Java than any other language (as of ...


9

WaitForPageLoad() continue's after all the data for the page has been retrieved and I think when the browser OnLoad() function is called. Its possible the browser is still executing JavaScript or processing CSS. Meaning your elements might not be visible on the page just yet. Instead of waiting for the page to load you should use an explicit wait to wait ...


9

You can use a CSS Selector looking for a substring at the onclick attribute: div[onclick*='2005256'] This will look for the client regardless of the position. If you want by position: #searchpanel-clientlist li:nth-of-type(6)


6

A heavier weight solution that may net you more flexibility/control in the end is to run all your tests in a VM on your local machine. With a VM, it's fairly easy to setup snapshots so you can be sure that you're resetting your testing environment to a specific, known point every single test run. That's freakin' nice. You can minimize the VM window and ...


6

I haven't used it, but possible it may be helpfull for you: FiddlerCore And one more alternative: BrowserMob Proxy


6

NONONONONO. All above posters have it wrong. Polling and latching and what not do not account for INHERENT RANDOMNESS or SELENIUM BUGINESS . Why does a test fail and turn red in Jenkins or some other automated build? Here are the past 5 selenium failures on our build An element doesn't have a type="file". Selenium chokes sending input keys to it for ...


6

After further research, come across the following links: https://github.com/SeleniumHQ/selenium/issues/886 https://code.google.com/p/chromedriver/issues/detail?id=962 http://peter.sh/experiments/chromium-command-line-switches/ https://sites.google.com/a/chromium.org/chromedriver/capabilities Although I did not see any definitive conclusion, someone ...


6

There are three .Net wrappers for Sikuli. Personally, I was a bit disappointed in all of them. Edit: there was a small bug in SikuliSharp which was causing commands to Sikuli to fail. Now that this is working, I'm a happy SikuliSharp user. SikuliSharp: looked most promising, couldn't get it to work with the same images that worked for Sikuli4Net (see ...


6

In this context, a goal you most likely want to achieve is one of Continuous Integration (CI). To that end, from the developer side, every check-in will trigger a build (to perform certain checks and see if it passes). Then you will usually have a nightly build that gives you an up-to-date test environment every morning. Now, this pipeline should include ...


6

Disabling infobars is not supported anymore by Chromium. According to them, Remove --disable-infobars. This flag is no longer needed by the perf testing infrastructure and can be misused for malicious purposes, so remove it. So either you can downgrade your chrome version or start ignoring the infobar in the new version.


6

To add explanation to what you have already figured out. The problem was that with this line you correctly acquired the second row: IWebElement secondRow = driver.FindElement(By.CssSelector("table tr:nth-of-type(2)")); but with the next piece of code, you did not get the 4th cell of the second row, but the first 4th cell of the DOM and that starts from the ...


5

How Selenium determines whether an element exists and how it behaves when an element is not found seems to vary from one release to the next. With the current release, it is possible to finesse the problem by switching to the findElements method. For example, in Java I would do something like this: elements = driver.findElements(By.id(Element_ID")); if (...


5

I'm assuming you're using Firefox? Right-click the drop-down list and select "Inspect Element". Get the tag from the information (everything in green following the pound sign). Then add this to your code where you need to select the element new SelectElement(driver.FindElement(By.Id("{put your tag information here}"))).SelectByText("{State here}");


5

You should avoid doing assertions on the method's innards as much as possible, to avoid coupling the unit tests to implementation specific details. In reality, of course, that's not always possible. In this case, you don't need to verify whether those methods were called. You're gonna have to provide a mock for _emailMessageBuilder, IEmailMessage and ...


5

Start by looking for testing tasks that require a lot of manual effort and do not change from one release to the next. This is especially important for UI automation; if a web page changes frequently, you will spend so much time updating your automated test that it will have been faster to test the page by hand. Note that there are often ways to use ...


5

Quickly glanced over the properties and methods of IWebElement, doesn't look like they can set values. However, you can easily execute some javascript snippet to change HTML in your page. IWebDriver driver; IJavaScriptExecutor js = driver as IJavaScriptExecutor; js.ExecuteScript("document.getElementById("title").innerHTML = "New text!";"); You might need ...


5

Below code should help you. public static class WebDriverExtensions { public static IWebElement FindElement(this IWebDriver driver, By by, int timeoutInSeconds) { if (timeoutInSeconds > 0) { var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(timeoutInSeconds)); return wait.Until(drv => drv....


5

Yes, you can use NUnit for functional testing. But still it is a unit-testing framework. No, you are not creating unit-tests by using a unit-testing framework to write functional tests. A unit-test is testing just a single methods input and output, by writing end-2-end tests it by definition cannot be a unit-test. :) Unit testing frameworks are often ...


5

StaleElementReferenceException is really common with Selenium. To avoid these issues you should be waiting for an element to load before manipulating it (clicking, sending keys, etc). This will reduce the likelihood of something between dependent actions like your click and send keys. I will typically do an explicit wait on a single or multiple related ...


5

If you are concerned about learning too much, you are doing it WRONG. The more you learn, the easier it will be for you to solve common problems. We are getting questions DAILY here which would be solved trivially by having some (very little) programming experience - which is very obviously missing. And in some cases, even willingness to learn is missing. ...


5

Get the table, then its rows, then each row's TDs, then each TD's anchor: var table = driver.FindElement(By.TagName("table")); var rows = table.FindElements(By.TagName("tr")); foreach (var row in rows) { var rowTds = row.FindElements(By.TagName("td")); foreach (var td in rowTds) { var a = td.FindElement(By.TagName("a")); ...


5

You are likely getting a StaleElementException. When you first get the list of elements to click, they are attached to the current DOM. After navigating away (the first time) the elements are no longer attached to the DOM (even if you navigate back). One way of getting around this is to: Get all the HREFs of the elements and store that into a list Visit ...


5

GitHub is really useful for lists of resources and I came across one yesterday that is a collection of free APIs for use in web development. <- I think you'd be good to test most any of these APIs for practice as well. The List is fairly descriptive mentioning which APIs have auth or not and then you can click to the API's, read the documentation and ...


4

Your question brings these considerations to mind: Does the component invoke the logging system at the appropriate times? This is hard to determine and impossible to determine automatically because you cannot predict where things will go wrong. It is likely that additional logging will appear as a result of bugs discovered during testing. Is the ...


4

You could combine the not null tests into one if statement if (Data != null || Data.SubData != null) { //Do Whatever } else { //Message Evaluation Example return Data = null ? "Data is null!" : "Data.SubData is null!"; } Above I have made a check on both Data and Data.SubData to ensure they are not null, if they are however I use a Ternary ...


4

You can run it using BrowserWindow.Launch("http://www.google.com/", "-private"); Official information is available on CodeProject.


Only top voted, non community-wiki answers of a minimum length are eligible