Skip to content

Commit

Permalink
Change Uknown element to Window in page source, and --logpath to allo…
Browse files Browse the repository at this point in the history
…w use to set log folder (#20)

* reduce the log for screenshot and change Unknow element to Window for screenshot

* allow change the log folder via --logpath
  • Loading branch information
licanhua authored Nov 28, 2020
1 parent d79ed78 commit 2de64a4
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 20 deletions.
21 changes: 5 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ By default, YWinAppDriver is http://127.0.0.1:4723. You can change the port numb
run `WinAppDriver.exe --urls http://127.0.0.1:4723 --basepath /wd/hub`


A complete command line:
```
WinAppDriver.exe --urls http://127.0.0.1:4723 --basepath /wd/hub --logpath logs
```

2. From Visual Studio

There are two [settings](docs/images/LaunchFromVS.png) are ready for you. `IIS Express /wd/hub` is http://127.0.0.1:4723/wd/hub
Expand All @@ -46,22 +51,6 @@ There are two [settings](docs/images/LaunchFromVS.png) are ready for you. `IIS E
```


Logs are in `Logs/WinAppDriver-{Date}.txt`.
If you run it from visual studio, there is no logs. If you want it, just remove `else` from below code
```
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
loggerFactory.AddFile("Logs/WinAppDriver-{Date}.txt");
}
```



- Build and run the CalcatorTest in [examples](https://github.com/licanhua/YWinAppDriver/tree/main/examples/CalculatorTest)
Please run the test, please make sure Calculator is in Standard mode.

Expand Down
2 changes: 1 addition & 1 deletion src/Infra/Communication/Element.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace WinAppDriver.Infra.Communication
public class Element : IElement
{
static Regex TagNameRegExpr = new Regex("^[a-zA-Z0-9 ]*$");
const string TAGUNKNOWN = "Unknown";
const string TAGUNKNOWN = "Window"; // match with WinAppDriver
const string UNIQID = "UniqId";

private readonly UIObject _uiObject;
Expand Down
3 changes: 2 additions & 1 deletion src/WinAppDriver/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public static IHostBuilder CreateHostBuilder(string[] args) =>
.ConfigureAppConfiguration((hostingContext, config) =>
{
config.AddCommandLine(args, new Dictionary<string, string>() {
{ "--basepath", "BasePath"}
{ "--basepath", "BasePath"},
{ "--logpath", "LogPath"},
});
})
.ConfigureWebHostDefaults(webBuilder =>
Expand Down
4 changes: 4 additions & 0 deletions src/WinAppDriver/RequestLoggingMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ private async Task LogResponse(HttpContext context)
var text = await new StreamReader(context.Response.Body).ReadToEndAsync();
context.Response.Body.Seek(0, SeekOrigin.Begin);

// trim the log for screenshot
if (context.Request.Path.ToString().EndsWith("screenshot"))
text = text.Substring(0, 100) + "...";

_logger.LogInformation(
$"Response {context.Response.StatusCode}: {context.Request.Host} " +
$"{context.Request.Path} " +
Expand Down
8 changes: 6 additions & 2 deletions src/WinAppDriver/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,13 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerF
{
app.UseDeveloperExceptionPage();
}
else

var logPath= Configuration["LogPath"];
if (!string.IsNullOrEmpty(logPath))
{
loggerFactory.AddFile("Logs/WinAppDriver-{Date}.txt");
var file = logPath + "\\WinAppDriver-{Date}.log";
Console.WriteLine("LogPath: " + logPath);
loggerFactory.AddFile(file);
}

var basepath = Configuration["BasePath"];
Expand Down

0 comments on commit 2de64a4

Please sign in to comment.