jeudi 10 août 2017

C#, merging Extensions section of the framework with Interfaces

I was assigned into a new project couple of days ago, and at the moment I need to wrap most of my extensions into the interfaces. I'm new to c# and I'm struggling with this task. I did some research but could find anything that would help. I'm using Galen Framework. I'm trying to "rebuild" a framework a little bit, for the specific client and they want most of the extensions to be wrapped in one interface file. So for example i need to merge this:

using OpenQA.Selenium;
using System;

namespace Automation
{
public static partial class Extensions
{

    public static IWebElement Parent(this IWebElement element)
    {
        return element.FindElement(By.XPath(".."));
    }


    public static void Click2(this IWebElement element, string logicalName)
    {
        Containers.LogStep logStep = new Containers.LogStep();

        try
        {

            logStep.Source = "Click2";
            logStep.ElementName = logicalName; // element.GetLogicalName();
            logStep.Action = "Click";
            logStep.Data = "";

            logStep.Friendly = String.Concat("Click \"", 
            logStep.ElementName, "\"");

            element.ScrollIntoView(logicalName);
            element.Click();

            logStep.Result = Reporting.Pass;
            Reporting.LogStep(logStep);
        }
        catch (Exception e)
        {
            logStep.Friendly = e.Message.ToString();
            logStep.Result = Reporting.Fail;
            Reporting.LogStep(logStep);
            throw new Exception("Element.Click: " + e.Message.ToString());
        }

    }


    private static string GetLogicalName(this IWebElement element)
    {
        string elementName = "";

        try {elementName = element.GetAttribute("placeholder").ToString(); } 
        catch { }
        if (elementName.Equals("")) try { elementName = 
  element.GetAttribute("name").ToString(); } catch { }
        if (elementName.Equals("")) try { elementName = 
  element.GetAttribute("id").ToString(); } catch { }
        if (elementName.Equals("")) try { elementName = 
  element.Text.ToString(); } catch { }
        if (elementName.Equals("")) try { elementName = 
  element.GetAttribute("class").ToString(); } catch { }

        return elementName;

    }


}
}

With:

using OpenQA.Selenium;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections.ObjectModel;
using System.Drawing;

namespace Automation.Interfaces
{
interface ILoggableWebElement : IWebElement
{
    void Log(ILogger logger);
}

public interface ILogger { }


public class testEle : IWebElement
{
    public string TagName => throw new NotImplementedException();

    public string Text => throw new NotImplementedException();

    public bool Enabled => throw new NotImplementedException();

    public bool Selected => throw new NotImplementedException();

    public Point Location => throw new NotImplementedException();

    public Size Size => throw new NotImplementedException();

    public bool Displayed => throw new NotImplementedException();

    public void Clear()
    {
        throw new NotImplementedException();
    }

    public void Click()
    {
        throw new NotImplementedException();
    }

    public IWebElement FindElement(By by)
    {
        throw new NotImplementedException();
    }

    public ReadOnlyCollection<IWebElement> FindElements(By by)
    {
        throw new NotImplementedException();
    }

    public string GetAttribute(string attributeName)
    {
        throw new NotImplementedException();
    }

    public string GetCssValue(string propertyName)
    {
        throw new NotImplementedException();
    }

    public void SendKeys(string text)
    {
        throw new NotImplementedException();
    }

    public void Submit()
    {
        throw new NotImplementedException();
    }
 }
 }

Aucun commentaire:

Enregistrer un commentaire