public void CSharpPageObjectGenerator_Generate(string templateFileName)
        {
            CSharpPageObjectGenerator engine = new CSharpPageObjectGenerator();
            string templatesFolder = Path.Combine(Helper.AssemblyDirectory(), "CodeTemplates");
            string fileName = Path.Combine(templatesFolder, templateFileName);

            SwdPageObject pageObject = new SwdPageObject();
            string expectedName = "ExpectedName123456";
            pageObject.PageObjectName = expectedName;

            string[] output = engine.Generate(pageObject, fileName);

            string actual = string.Join("", output);
            actual.Should().Contain(expectedName);
            Console.WriteLine(actual);
        }
        public string[] Generate(SwdPageObject pageObject, string fullTemplatePath)
        {
            var template = File.ReadAllText(fullTemplatePath);

            object model = new TemplateViewModel() { PageObject = pageObject };

            string result = "not parsed";
            try
            {
                result = Razor.Parse(template, model);
            }
            catch
            {
                throw;
            }
            return Utils.SplitSingleLineToMultyLine(result);
        }
        internal string[] Generate(SwdPageObject pageObject, string fullTemplatePath)
        {
            var template = File.ReadAllText(fullTemplatePath);

            object model = new {
                                        PageObject = pageObject,
                                        ExternalGenerator = new ExternalGenerator(),
                                    };

            string result = "not parsed";
            try
            {
                result = Razor.Parse(template, model);
            }
            catch
            {
                throw;
            }
            return Utils.SplitSingleLineToMultyLine(result);
        }
        internal SwdPageObject GetWebElementDefinitionFromTree()
        {
            var pageObject = new SwdPageObject();

            string pageObjectName = "MyPage";

            if (tvWebElements.Nodes.Count > 0)
            {
                string rootNodeText = tvWebElements.Nodes[0].Text;

                pageObjectName = String.IsNullOrWhiteSpace(rootNodeText)
                                        ? pageObjectName
                                        : rootNodeText;
            }

            pageObject.PageObjectName = pageObjectName;

            foreach (var treeNode in tvWebElements.Nodes[0].Nodes)
            {
                var node = treeNode as TreeNode;
                var elementDefinition = node.Tag as WebElementDefinition;
                pageObject.Items.Add(elementDefinition);
            }

            return pageObject;
        }
 public void SaveToJSonFile(SwdPageObject pageObject, string filePath)
 {
     string json = JsonConvert.SerializeObject(pageObject, Formatting.Indented);
     File.WriteAllText(filePath, json);
 }