2

I'm using selenium to test a webapp. It has to do with adding Announcements/data. It has alot of inputs...

Problem: Randomly, text-A, meant for input-A get typed in input-B as well as text-B.

Since there's a lot of repetition, I read text-inputs from xml and return a dictionary. And type text as so

public AnnouncementAdvertiserFields TypeAdvertiserFields(string pathToXml)
    {
        var xmlParser = new XmlParser();
        Dictionary<string, string> fields = xmlParser.TypeAdvertiserFieldsFromXml(pathToXml);

        string name;
        string coAddress;
        string streetName;
        string streetNo;
        string streetFloor;
        string streetDoor;
        string city;
        string postalCode;
        string postalCity;
        string phoneNo;
        string mobileNo;
        string faxNo;
        string country;
        string journalNo;

        fields.TryGetValue(WebTesting.Common.Constants.AdvertiserFieldNames.Name, out name);
        fields.TryGetValue(WebTesting.Common.Constants.AdvertiserFieldNames.CoAdress, out coAddress);
        fields.TryGetValue(WebTesting.Common.Constants.AdvertiserFieldNames.Streetname, out streetName);
        fields.TryGetValue(WebTesting.Common.Constants.AdvertiserFieldNames.StreetNumber, out streetNo);
        fields.TryGetValue(WebTesting.Common.Constants.AdvertiserFieldNames.StreetFloor, out streetFloor);
        fields.TryGetValue(WebTesting.Common.Constants.AdvertiserFieldNames.StreetDoor, out streetDoor);
        fields.TryGetValue(WebTesting.Common.Constants.AdvertiserFieldNames.City, out city);
        fields.TryGetValue(WebTesting.Common.Constants.AdvertiserFieldNames.PostalCode, out postalCode);
        fields.TryGetValue(WebTesting.Common.Constants.AdvertiserFieldNames.PostalCity, out postalCity);
        fields.TryGetValue(WebTesting.Common.Constants.AdvertiserFieldNames.PhoneNumber, out phoneNo);
        fields.TryGetValue(WebTesting.Common.Constants.AdvertiserFieldNames.MobilePhoneNumber, out mobileNo);
        fields.TryGetValue(WebTesting.Common.Constants.AdvertiserFieldNames.FaxNumber, out faxNo);
        fields.TryGetValue(WebTesting.Common.Constants.AdvertiserFieldNames.Country, out country);
        fields.TryGetValue(WebTesting.Common.Constants.AdvertiserFieldNames.JounalNo, out journalNo);

        if (name != string.Empty) TypeName(name);
        if (coAddress != string.Empty) TypeCoAddress(coAddress);
        if (streetName != string.Empty) TypeStreetName(streetName);
        if (streetNo != string.Empty) TypeStreetNumber(streetNo);
        if (streetFloor != string.Empty) TypeStreetFloor(streetFloor);
        if (streetDoor != string.Empty) TypeStreetDoor(streetDoor);
        if (city != string.Empty) TypeCity(city);
        if (postalCode != string.Empty) TypePostalCode(postalCode);
        if (postalCity != string.Empty) TypePostalCity(postalCity);
        if (phoneNo != string.Empty) TypePhoneNumber(phoneNo);
        if (mobileNo != string.Empty) TypeMobilePhoneNumber(mobileNo);
        if (faxNo != string.Empty) TypefaxNumber(faxNo);
        if (country != string.Empty) SelectCountryByValue(country);
        if (journalNo != string.Empty) TypeJournalNumber(journalNo);
        return this;
    }

Example of TypeName from AnnouncementAdvertiserFields

public void TypeName(string name)
{
 TypeText(name, _nameInputLocator); 
}

TypeName calls generic TypeText method from a superclass.

protected void TypeText(string text, By locator)
{ 
  Webdriver.FindElement(locator).SendKeys(text);
}

Type AnnouncementAdvertiserFields is a property on the page object page of the specific announcement type.

I have tried using both implicit wait and explicit wait. With sooooooo many combinations of ExpectedConditions

  • TextToBePresentInElement before and after SendKeys
  • ElementExists
  • ElementIsVisible

I would think code like this should work

var wait = new WebDriverWait(Webdriver, TimeSpan.FromSeconds(5));
wait.Until(ExpectedConditions.ElementIsVisible(locator));
var element = Webdriver.FindElement(locator);
element.Clear();
wait.Until(ExpectedConditions.TextToBePresentInElement(element, ""));
element.SendKeys(text);
Wait.Until(ExpectedConditions.TextToBePresentInElement(FindStdkElement(locator), text));

I also tried using the SelectElement but to no avail.

If I debug my way through, everything is dandy and great. No errors. But when I run the test, sometimes it passes other times fails. I cannot find any system as to which fields fails. It's random...

When I run the tests from my local machine I have no issues. But when run from machine in DEV, they fail sporadically. DEV-machine is less powerfull than local, which makes my think it might be a timing issue. That maybe Selenium is is typing to fast for the browser to keep up.

I use Nunit as testframework. With ReSharper.

Any help or directions will be much appreciated. thanks guys

Community
  • 1
  • 1
terle
  • 86
  • 10
  • In TypeText, try reading back the element after typing it and see if it matches. – stark Sep 07 '15 at 13:05
  • @stark. Thanks. I did that. What would you do if they don't match? I tried typing the _exact_ same thing again. But same behaviour :( aaaawwwwww – terle Sep 07 '15 at 13:27
  • If they don't match log what you expected and what you got. That should tell you what's wrong. – stark Sep 07 '15 at 15:11
  • @stark. The trouble is _nothing_ gets typed. What should have gone into one input gets typed in the next. – terle Sep 07 '15 at 16:32

1 Answers1

0

I think there can be timing issues. If there is time out then increase the time out that you have given and then run it again and check weather there is failed tests in you DEV machine.

To increase timeout. Try this...

driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

Reference - http://docs.seleniumhq.org/docs/04_webdriver_advanced.jsp

Saveendra Ekanayake
  • 3,153
  • 6
  • 34
  • 44