![]() I suspected this, but I learned the hard way. You don't get closures entirely for free in PowerShell.Not only that, but I got to learn some new things about PowerShell. I get to keep using Microsoft Edge with minimal effort beyond what I had when using Google Chrome for my BrowserStack testing, enabling me to take advantage of the performance and battery-life improvements Edge has over Chrome. I am pretty pleased with how this little PowerShell project worked out. TL DR: Use processes to start processes in the background 3. Set-Alias spbs Stop-BrowserStackLocal Conclusion ![]() If (-Not $bslocal) Output from process-based cmdlets Helpful aliasesįinally, to make the task of starting and stopping a little less arduous, I added some aliases (inspired by the helpful sasv and spsv aliases of Start-Service and Stop-Service). Write-Host "$($job.ID):$($job.Name)" -ForegroundColor Cyan Write-Host "BrowserStackLocal already started: " -ForegroundColor Yellow -NoNewline $job = Get-Job BrowserStackLocal -ErrorAction Silentl圜ontinue $bslocal = Get-Command "$browserStackLocalDir\BrowserStackLocal.exe" -ErrorAction Silentl圜ontinue $browserStackLocalDir = "F:\Program Files (x86)\BrowserStackLocal" ![]() The first cmdlet for starting BrowserStackLocal is cunningly named Start-BrowserStackLocal , shown here: function Start-BrowserStackLocal() The downside is that each PowerShell session could have its own job, but only the one that started BrowserStackLocal will actually end it, but I was certain I could work with that. This is useful since the job gets terminated when the PowerShell session ends, which makes it less likely for me to forget. Since the running the command is a blocking operation, I decided to try wrapping it in a PowerShell job so that it would sit in the background. Specifically, I wanted to compare PowerShell jobs with plain old processes for this specific purpose. I decided to take the opportunity to expand my PowerShell fu and put together some cmdlets to run the BrowserStackLocal process in the background. There are a variety of ways this problem can be solved. This works great, but there are a couple of annoyances. Instead, BrowserStack provides a download, BrowserStackLocal.exe , and a secret with which to run it. However, since the Windows Creators Update, I have been giving Microsoft Edge a shot 1 and no such extension exists. Up until recently, my browser of choice has been Google Chrome, for which BrowserStack provides a handy extension to add support for local sites. This often requires accessing locally deployed sites or sites accessible over a VPN connection, and to do that, BrowserStack needs some local code running to be able to route the traffic accordingly. BrowserStack has been an incredibly useful resource for tracking down bugs and testing fixes when I am working on websites.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |