Tag Info

Hot answers tagged

38

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


12

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?


9

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


7

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


4

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


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

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


4

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


4

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


3

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


3

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


3

From documentation: BinaryLocation Gets or sets the location of the Chrome browser's binary executable file. So the above excerpt plainly says that the BinaryLocation is the path for chrome.exe and not chromedriver.exe. And chromedriver.exe path should be defined in the PATH environment variable. So in your case the correct line would be: ...


3

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


3

Actually, I can see two questions in your post. Is it better to test SOAP Web services backed by EJB using Java or C#? Actually, Web service stack of technologies was designed to support interaction between application written in different technologies, so it does not matter how the Web service was implemented. I.e., Web service implemented in Java can by ...


3

I don't think that you should be defining the URL to the page inside the pageObject. The methods in your page object should actions/ journeys that your pageObjects can take. For example a login pageObject may have 3 methods in it: Login(String username, String password) { // fill in login form // Submit login form return new landingPage(driver); } ...


3

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


3

To play a devil advocate, if you try Python, you will find that you are substantially more productive because of dynamic typing. Python just works much harder to improve productivity of the programmer, as compared to C# which is focused to create effective code (making programmer to work harder to get it). In testing, it is of little difference if test ...


3

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


3

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


2

Apologies to all for duplicating this question. Turns out, that indeed, the failing script in question lives on a separate domain than the place where my error.js was being included from. So, it was indeed a cross-domain trigger of "same origin".


2

Here are some potential problems: //a[@class='wlcategoryLinkBold']/@href is an Xpath to an href, not to an "a" tag. Furthermore, //a[@class='wlcategoryLinkBold']/@href[i] is the Xpath to the i'th href of an "a" tag, which is nonsensical. I believe you want to use (//a[@class='wlcategoryLinkBold'][@href])[i]. GetSelectedLabel gets option label (visible ...


2

The WaitForPageToLoad method will not work here since Google now return results in an AJAX call when you start typing. The best practice is to wait for something knowing on the page to exist before you proceed. For example you could poll the page to check if selenium.IsTextPresent("openqa.org") is true, if it's not loop back around and try again. Just ...


2

The insertion of Thread.Sleep() is typically indicative of a race condition in your test and your test is running out of sync with the thing is it testing. One suggestion may be to insert a polling loop to wait for the redirect, or an event to indicate the redirect has happened. See http://www.testingmentor.com/imtesty/?p=652 and read the comments for ...


2

The way I handle this is to create WebDriver extensions in an IWebDriverExtensions Class so that the JQuery or Javascript methods are always available through your driver object. The driver object is cast to IjavaScriptExecutor allowing you to execute the JavaScript or Jquery. You can also create any other extension methods you need in he same class. These ...


2

I think I can point you in the right direction for MS Word, at least. You can use the Office Interop Assemblies in C#. Here is an example from .Net Pearls: using System; using Microsoft.Office.Interop.Word; class Program { static void Main() { // Open a doc file. Application application = new Application(); Document document = ...


2

Use profile setting for browsers: firefoxProfile.setPreference("browser.helperApps.neverAsk.saveToDisk","text/csv"); Browser initialize FirefoxProfile profile = new FirefoxProfile(); profile.setPreference("browser.helperApps.neverAsk.saveToDisk","text/csv"); IWebDriver webDriver = new FirefoxDriver(profile);


2

The code that was entered by Brandon Garlock won't work for C# which you included in your tags, here is the C# version to help with the row count: driver.FindElements(By.XPath("//table[@id='yourIDhere'//tr")).Count; Also be aware that if you have a grid header row, you will want to filter that out so it doesn't throw off your count.


2

The Uri class has a property called PathAndQuery that will strip off the fragment identifier (the part after the #). Assert.AreEqual("/shop/en-US/products/berry-blue", new Uri(driver.Url).PathAndQuery); If you need to test the host name too, you will need to add that back.


2

Just use an Excel library to load data from Excel files and use that data in your Asserts? C# and Excel: http://stackoverflow.com/questions/657131/how-to-read-data-of-an-excel-file-using-c C# and Asserts: https://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.unittesting.assert.aspx


2

As the Datepicker is not your code you don't need to test it's functionality, so what I would do is write a JavaScript snippet that sets it to the required value, then execute that in the browser.



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