private static void ResolveTestProject(DotvvmProjectMetadata dotvvmProjectMetadata) { var metadataService = new DotvvmProjectMetadataService(); if (string.IsNullOrEmpty(dotvvmProjectMetadata.UITestProjectPath)) { var hintProjectName = $"..\\{dotvvmProjectMetadata.ProjectName}.Tests"; if (!Console.IsInputRedirected) { dotvvmProjectMetadata.UITestProjectPath = ConsoleHelpers.AskForValue($"Enter the path to the test project\n(relative to DotVVM project directory, e.g. '{hintProjectName}'): ", hintProjectName); } else { dotvvmProjectMetadata.UITestProjectPath = hintProjectName; } Console.WriteLine($@"Path to test project is set to ""{dotvvmProjectMetadata.UITestProjectPath}"""); } // make sure the test directory exists var testProjectDirectory = dotvvmProjectMetadata.GetUITestProjectFullPath(); if (!Directory.Exists(testProjectDirectory)) { var relativeWebDirectory = Path.GetRelativePath(dotvvmProjectMetadata.GetUITestProjectFullPath(), dotvvmProjectMetadata.ProjectDirectory); GenerateTestProject(testProjectDirectory, relativeWebDirectory); } // make sure we know the test project namespace if (string.IsNullOrEmpty(dotvvmProjectMetadata.UITestProjectRootNamespace)) { dotvvmProjectMetadata.UITestProjectRootNamespace = Path.GetFileName(testProjectDirectory); } // save the metadata metadataService.Save(dotvvmProjectMetadata); }
public static void Main(string[] args) { //Console.WriteLine("pid: " + Process.GetCurrentProcess().Id); //while (!Debugger.IsAttached) //{ // Thread.Sleep(1000); //} //Debugger.Break(); try { var arguments = new Arguments(args); DotvvmProjectMetadata dotvvmProjectMetadata = null; if (string.Equals(arguments[0], "--json", StringComparison.CurrentCultureIgnoreCase)) { dotvvmProjectMetadata = JsonConvert.DeserializeObject <DotvvmProjectMetadata>(args[1]); dotvvmProjectMetadata.WebAssemblyPath = dotvvmProjectMetadata.WebAssemblyPath.Replace(@"\\", @"\"); dotvvmProjectMetadata.ProjectDirectory = dotvvmProjectMetadata.ProjectDirectory.Replace(@"\\", @"\"); dotvvmProjectMetadata.MetadataFilePath = dotvvmProjectMetadata.MetadataFilePath.Replace(@"\\", @"\"); arguments.Consume(2); } else { Console.WriteLine(@"Provide correct metadata."); Environment.Exit(1); } ResolveTestProject(dotvvmProjectMetadata); CreatePageObjectsDirectory(dotvvmProjectMetadata.GetUITestProjectFullPath()); var config = ConfigurationHost.InitDotVVM(Assembly.LoadFile(dotvvmProjectMetadata.WebAssemblyPath), dotvvmProjectMetadata.ProjectDirectory, services => services.TryAddSingleton <IViewModelProtector, FakeViewModelProtector>()); // generate the test stubs GeneratePageObjects(dotvvmProjectMetadata, config, arguments); Console.WriteLine(@"#$ Exit 0 - DotVVM Selenium Generator Ended"); Environment.Exit(0); } catch (Exception e) { Console.WriteLine(@"#$ Exit 1 - DotVVM Selenium Generator Failed" + e); throw; } }
public override void Handle(Arguments args, DotvvmProjectMetadata dotvvmProjectMetadata) { // make sure the test directory exists if (string.IsNullOrEmpty(dotvvmProjectMetadata.UITestProjectPath)) { dotvvmProjectMetadata.UITestProjectPath = ConsoleHelpers.AskForValue($"Enter the path to the test project\n(relative to DotVVM project directory, e.g. '..\\{dotvvmProjectMetadata.ProjectName}.Tests'): "); } var testProjectDirectory = dotvvmProjectMetadata.GetUITestProjectFullPath(); if (!Directory.Exists(testProjectDirectory)) { throw new Exception($"The directory {testProjectDirectory} doesn't exist!"); } // make sure we know the test project namespace if (string.IsNullOrEmpty(dotvvmProjectMetadata.UITestProjectRootNamespace)) { var csprojService = new CSharpProjectService(); var csproj = csprojService.FindCsprojInDirectory(testProjectDirectory); if (csproj != null) { csprojService.Load(csproj); dotvvmProjectMetadata.UITestProjectRootNamespace = csprojService.GetRootNamespace(); } else { dotvvmProjectMetadata.UITestProjectRootNamespace = ConsoleHelpers.AskForValue("Enter the test project root namespace: "); if (string.IsNullOrEmpty(dotvvmProjectMetadata.UITestProjectRootNamespace)) { throw new Exception("The test project root namespace must not be empty!"); } } } // generate the test stubs var name = args[0]; var files = ExpandFileNames(name); foreach (var file in files) { Console.WriteLine($"Generating stub for {file}..."); // determine full type name and target file var relativePath = PathHelpers.GetDothtmlFileRelativePath(dotvvmProjectMetadata, file); var relativeTypeName = PathHelpers.TrimFileExtension(relativePath) + "Helper"; var fullTypeName = dotvvmProjectMetadata.UITestProjectRootNamespace + "." + PathHelpers.CreateTypeNameFromPath(relativeTypeName); var targetFileName = Path.Combine(dotvvmProjectMetadata.UITestProjectPath, "Helpers", relativeTypeName + ".cs"); // generate the file //var generator = new SeleniumHelperGenerator(); //var config = new SeleniumGeneratorConfiguration() //{ // TargetNamespace = PathHelpers.GetNamespaceFromFullType(fullTypeName), // HelperName = PathHelpers.GetTypeNameFromFullType(fullTypeName), // HelperFileFullPath = targetFileName, // ViewFullPath = file //}; //generator.ProcessMarkupFile(DotvvmConfiguration.CreateDefault(), config); } }