/// <summary> /// Get list of locators withrespect to type. Without type it returns all functional locators in xml resource. /// </summary> /// <param name="type"></param> /// <returns>Dictionary<string, By></returns> public static Dictionary <string, By> GetLocators(SupportedResourceType type) { if (type.Equals(SupportedResourceType.config)) { return(null); } ResourceManager loc = new ResourceManager(type); return(loc.locators); }
private ResourceManager(SupportedResourceType type) { try { AppDomain domain = AppDomain.CurrentDomain; string path = domain.BaseDirectory; ResourceManager.path = path; XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(path + "Resource.xml"); XmlNodeList list; if (!type.Equals(SupportedResourceType.config)) { if (type.Equals(SupportedResourceType.xpath)) { list = xmlDoc.SelectNodes("//" + SupportedResourceType.locators.ToString() + "/" + SupportedResourceType.xpath.ToString()); } else if (type.Equals(SupportedResourceType.id)) { list = xmlDoc.SelectNodes("//" + SupportedResourceType.locators.ToString() + "/" + SupportedResourceType.id.ToString()); } else { list = xmlDoc.SelectNodes("//" + SupportedResourceType.locators.ToString() + "/*"); } foreach (XmlNode node in list) { if (node.Attributes[SupportedAttributes.page.ToString()].Value != null && node.Attributes[SupportedAttributes.name.ToString()].Value != null) { By value; string key = node.Attributes[SupportedAttributes.page.ToString()].Value.ToString() + "_" + node.Attributes[SupportedAttributes.name.ToString()].Value.ToString(); if (node.Name.Equals(SupportedResourceType.xpath.ToString()) && node.InnerText.Length >= 1) { value = By.XPath(node.InnerText.ToString()); } else if (node.Name.Equals(SupportedResourceType.id.ToString()) && node.InnerText.Length >= 1) { value = By.Id(node.InnerText.ToString()); } else { throw new Exception("Resource.xml -> Empty locator value - Add locator for key - " + key); } this.locators.Add(key, value); } else { throw new Exception("Resource.xml -> Missing attributes for node - " + node.Name); } } } else { list = xmlDoc.SelectNodes("//" + SupportedResourceType.config); foreach (XmlNode node in list) { if (node.Attributes[ConfigAttributes.key.ToString()].Value != null && node.Attributes[ConfigAttributes.value.ToString()].Value != null && node.Attributes[ConfigAttributes.value.ToString()].Value != string.Empty) { string key = node.Attributes[ConfigAttributes.key.ToString()].Value.ToString(); string value = node.Attributes[ConfigAttributes.value.ToString()].Value.ToString(); this.configElements.Add(key, value); } else { throw new Exception("Resource.xml -> missing key or value in config node"); } } } } catch (Exception ex) { throw new Exception(ex.Message); } }