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 ...


39

One of the biggest mistakes in my career was to pick a different programming language for the test automation than the development team uses. You won't get help from the development team when you have a programming issue Developers will probably not run, nor maintain tests as they change the application, you will be maintaining and analysing test results (e....


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?


14

You can choose any language irrespective of which language is used in development. But it would be better if you go with same programming language which is used in the development, in your case it would be C#/.NET for below reasons: You can leverage existing libraries used by your team. Developers can help you out, As you said you will the only person doing ...


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)


9

Definetly learn C#. Why? At Selenium tests level it's basically the same thing as Java 9. With a bit of syntactic sugars. It shouldn't take you more than 2 weeks to get up to speed with C#. CI/CD and whole infrastructure is set up for dotnet. If you don't want to run this automated tests manually, you will have to either: configure whole infrastructure to ...


8

Page Object and Selenium's PageFactory are distinct things in nature, usually the latter complement the former. Page Object is a design pattern aimed at solving the problem of separating the application interface from the HTML interface. Why do we separate these interfaces? Because web pages elements and functions, as saw by the user, differ from the HTML ...


7

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")); ...


7

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

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}");


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

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


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

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 ...


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

You can use the combination of any unit testing framework (like NUnit, MSTest, XUnit) with additional nuget packages for the work with REST API itself RestSharp (http://restsharp.org/) Probably the most popular and convenient REST HTTP Client for .Net. RestAssured.Net (https://github.com/lamchakchan/RestAssured.Net) .Net port of Java's lib, may be easier ...


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 ...


6

Some options in my order of preference: Probably you do not want to test the TwoFactorAuth, but you want to test the application behind it. Consider building a backdoor which is only enabled in the test environment, so that you can bypass the TFA. Generate the OTP from code with OTP.Net: https://dev.to/j_sakamoto/selenium-testing---how-to-sign-in-to-two-...


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

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

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 ...


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