"Fossies" - the Fresh Open Source Software Archive

Member "selenium-selenium-4.8.1/dotnet/test/common/Environment/InlinePage.cs" (17 Feb 2023, 2744 Bytes) of package /linux/www/selenium-selenium-4.8.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C# source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 using System;
    2 using System.Collections.Generic;
    3 using System.Linq;
    4 using System.Text;
    5 using System.Threading.Tasks;
    6 
    7 namespace OpenQA.Selenium.Environment
    8 {
    9     public class InlinePage
   10     {
   11         private string title = string.Empty;
   12         private List<string> scripts = new List<string>();
   13         private List<string> styles = new List<string>();
   14         private List<string> bodyParts = new List<string>();
   15         private string onLoad;
   16         private string onBeforeUnload;
   17 
   18         public InlinePage WithTitle(string title)
   19         {
   20             this.title = title;
   21             return this;
   22         }
   23 
   24         public InlinePage WithScripts(params string[] scripts)
   25         {
   26             this.scripts.AddRange(scripts);
   27             return this;
   28         }
   29 
   30         public InlinePage WithStyles(params string[] styles)
   31         {
   32             this.styles.AddRange(styles);
   33             return this;
   34         }
   35 
   36         public InlinePage WithBody(params string[] bodyParts)
   37         {
   38             this.bodyParts.AddRange(bodyParts);
   39             return this;
   40         }
   41 
   42         public InlinePage WithOnLoad(string onLoad)
   43         {
   44             this.onLoad = onLoad;
   45             return this;
   46         }
   47 
   48         public InlinePage WithOnBeforeUnload(string onBeforeUnload)
   49         {
   50             this.onBeforeUnload = onBeforeUnload;
   51             return this;
   52         }
   53 
   54         public override string ToString()
   55         {
   56             StringBuilder builder = new StringBuilder("<html>");
   57             builder.Append("<head>");
   58             builder.AppendFormat("<title>{0}</title>", this.title);
   59             builder.Append("</head>");
   60             builder.Append("<script type='text/javascript'>");
   61             foreach (string script in this.scripts)
   62             {
   63                 builder.Append(script).Append("\n");
   64             }
   65 
   66             builder.Append("</script>");
   67             builder.Append("<style>");
   68             foreach (string style in this.styles)
   69             {
   70                 builder.Append(style).Append("\n");
   71             }
   72 
   73             builder.Append("</style>");
   74             builder.Append("<body");
   75             if (!string.IsNullOrEmpty(this.onLoad))
   76             {
   77                 builder.AppendFormat(" onload='{0}'", this.onLoad);
   78             }
   79 
   80             if (!string.IsNullOrEmpty(this.onBeforeUnload))
   81             {
   82                 builder.AppendFormat(" onbeforeunload='{0}'", this.onBeforeUnload);
   83             }
   84 
   85             builder.Append(">");
   86             foreach (string bodyPart in this.bodyParts)
   87             {
   88                 builder.Append(bodyPart).Append("\n");
   89             }
   90 
   91             builder.Append("</body>");
   92             builder.Append("</html>");
   93             return builder.ToString();
   94         }
   95     }
   96 }