Playwright (.NET) tries to use different browser versions than installed - c#

I have created some tests using Playwright with .NET bindings.
[OneTimeSetUp]
public async Task OneTimeSetUp()
{
random = new Random();
var playwright = await Playwright.CreateAsync();
browser = await playwright.Chromium.LaunchAsync(new BrowserTypeLaunchOptions
{
Headless = false
});
context = await browser.NewContextAsync();
page = await context.NewPageAsync();
}
Before running tests I had run
npx playwright install
before running tests. The outcome of aforementioned command are browsers installed in path C:\Users\username\AppData\Local\ms-playwright
When running tests however, error is thrown:
OneTimeSetUp: Microsoft.Playwright.PlaywrightException : Executable doesn't exist at C:\Users\11033414\AppData\Local\ms-playwright\chromium-907428\chrome-win\chrome.exe
so it seems like playwright wants to use other versions of browsers than installed ones.
How to make Playwright point to correct versions of browsers installed?

# Install the CLI once.
dotnet tool install --global Microsoft.Playwright.CLI
# Install the browsers
playwright install
(The current error description is a bug in 1.14, it gets fixed with 1.15.)

According to: https://github.com/microsoft/playwright-dotnet/issues/1638#issuecomment-887340857
the workaround is to use dotnet .\bin\Debug\net5.0\Microsoft.Playwright.dll -- install.
I've tried this and it works for me.

Related

How to Create a Test Project for Winappdriver with C#

I need to learn about how to set-up a winappdriver windows app test project in visual studio and inspecting the elements for a medium size windows application.
Navigate to the WinAppDriver GitHub web page and download the latest
version. I downloaded the 1.2 version
After installation, you will find the diver at C:\Program Files
(x86)\Windows Application Driver location.
First, we need to enable Developer Mode on our Windows 10, Developer
mode is not enabled. Enable it through Settings and restart Windows
Application Driver
If you have Microsoft Visual Studio installed, you will most likely
have Element Inspector already installed on your machine
In case you do not have it installed, navigate to the Windows 10 SDK
site, download and install it.Run the inspect.exe and make sure it is
working fine
**.
Create a new NUnit test project
2- download appium dependency from NuGet
3- Update an existing UnitTest1.cs class as follows:**
using NUnit.Framework;
using OpenQA.Selenium.Appium;
using OpenQA.Selenium.Appium.Windows;
using System
[SetUp]
public void Setup()
{
AppiumOptions Options = new AppiumOptions();
Options.AddAdditionalCapability("app", "C:\\Windows\\System32\\notepad.exe");
Options.AddAdditionalCapability("deviceName", "WindowsPC");
DesktopSession = new WindowsDriver<WindowsElement>(new Uri(DriverUrl), Options);
Assert.IsNotNull(DesktopSession);
}
[TearDown]
public void Close()
{
DesktopSession.CloseApp();
}
}
4= Run the test
Note: If some references or packages are missing, right-click on it and include it in the solution.
5- Create Windows Elements and perform actions
Open up application under test (AUT), in our case it is Notepad.exe, and Inspect.exe tool to fetch locators.
Click on the Notepad text area and find the AutomationId attribute on the right-hand side of the Inspect.exe tool.
WindowsElement NotepadTextArea = DesktopSession.FindElementByAccessibilityId(“15”);
NotepadTextArea.SendKeys(“Hello World”);
Try! try! ,Run the test! Run the test! Run the test!
#pawansinghncr's answer is correct, but I would also suggest trying out the UI Recorder, it's in the Releases page of the WinAppDriver's Github.

Is it possible to install a local version of a package at runtime and use said local package?

As part of trying to test a NuGet package with a Console application, is it possible to have the console application get the latest version of said NuGet package programmatically, and then use said package to call various methods and what not? This is the flow that I'm trying to achieve...
A NuGet package is created locally (already done as part of a build process)
A console application installs this package
The same console application calls a few methods that are inside this package (if this uses reflection insdie the console app to achieve this it isn't an issue)
How can this be achieved? I've tried the following code using the NuGet.Core & NuGet.Protocol NuGet packages...
// exception thrown for trying to resolving newtonsoft
IPackageRepository packageRepository = new NuGet.LocalPackageRepository(directoryPath);
PackageManager pm = new PackageManager(packageRepository, GetExecutingAssemblyDirectory());
pm.InstallPackage("package_id", SemanticVersion.Parse("package_version"));
NuGet.Common.ILogger logger = new Logger();
IEnumerable<LocalPackageInfo> packageInfos = LocalFolderUtility.GetPackagesV2(directoryPath, logger);
foreach (LocalPackageInfo lpi in packageInfos)
{
// no obvious way to actually install the package
}
// never more than zero packages
var localRepo = new LocalPackageRepository(directoryPath);
var packages = localRepo.GetPackages();
if (packages?.Count() > 0)
{
var packageManager = new PackageManager(localRepo, GetExecutingAssemblyDirectory());
packageManager.InstallPackage(packages.ElementAt(0).Id);
}
I haven't been able to get any of those pieces of code to work. Is this actually possible? Would I have to look at using 2 Console apps (one to install into the other, which then does the calling of methods), and if so how would this be done?

Selenium with Microsoft Edge driver never finishes initialising

I'm using the C# bindings for Selenium and trying to get a simple automated test in Microsoft Edge working.
class Program
{
static void Main(string[] args)
{
EdgeOptions options = new EdgeOptions();
options.PageLoadStrategy = EdgePageLoadStrategy.Eager;
RemoteWebDriver driver = new EdgeDriver();
driver.Url = "http://bing.com/";
}
}
But the program halts on the initialisation of the EdgeDriver, the edge browser launches but the url never changes to "bing.com".
Has anyone else experienced this?
I have faced the same issue. I followed the below steps to resolve it :-
Download the correct Microsoft WebDriver server version for your build.
How to find your correct build number :-
1- Go to Start > Settings > System > About and locate the number next to OS Build on the screen. This is your build number. Having the correct version of WebDriver for your build ensures it runs correctly.
2- Run this command systeminfo | findstr /B /C:"OS Version" this will give the output like OS Version: 10.0.10586 N/A Build 10586. Here is build number is 10586
You need to check your Windows OS build number and download appropriate .msi and install it.
Provide the Syetem property where MicrosoftWebDriver.exe installed to webdriver.edge.driver.
Note :- The Default installed location of the MicrosoftWebDriver.exe :-
for 64 bit is C:\Program Files (x86)\Microsoft Web Driver
for 32 bit is C:\Program Files\Microsoft Web Driver
Hope it will work...:)
This happens when your system does not match the webdriver version... Determine which release of Windows 10 you are using... then go here and download same release..
https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver
Here's what the error looks like when the versions don't match.
Selenium will Hang
EdgeOptions options = new EdgeOptions();
options.PageLoadStrategy = EdgePageLoadStrategy.Eager;
RemoteWebDriver driver = new EdgeDriver();
driver.Url = "http://bing.com/";
Results in this exception with Edge still up and on the Bing page
Exception Thrown
changing the code to this, with no options:
var driver = new EdgeDriver();
driver.Url = "http://bing.com/";
Results in this:
Exception thrown: 'System.InvalidOperationException' in WebDriver.dll
And this in the console.
Something's not right with the MicrosoftWebDriver.Exe which was downloaded from here. https://www.microsoft.com/en-us/download/details.aspx?id=48212 and installed into the Program Files folder by default. Here's screenshot of add/remove programs. System is Windows 10 PRO 64 bit.
Note I did not try the 32 bit version

Selenium IEDriver / Firefox Driver browser location Error

unexpectedly I am experiencing this issue. I am trying to run my testcase. For Firefox or IE browser but I don't know where is the issue. It cannot find the browser location.
Selenium.WebDriver -Version 2.52.0
Selenium.Support -Version 2.52.0
Selenium.RC -Version 2.52.0
Selenium.WebDriverBackedSelenium -Version 2.52.0
It was working perfectly but soon after I updated my nupackages. I am having this issue. Also I tried to use previous version but now I am having same problem in that one as well.
Error:
IEDriver
FirefoxDriver Error
Enviorment Variable
Installed Location:
C:\Program Files (x86)\Google\Chrome\Application\chrome.exe
C:\Program Files\Mozilla Firefox\firefox.exe
Make sure you're mentioning path of IEDriverServer executable in PATH variable of your system.
echo $PATH
https://github.com/SeleniumHQ/selenium/wiki/FirefoxDriver
https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver
It happened to me as well. I tried to download older version from the below link and it worked. Let me know, if that helped. About IE I am trying to figure it out what should be the case.
Firefox version download
You don't need to alter your code. Also Anderson is right you probably might have downloaded x64 version and I think Selenium might be trying to find x86 version (in Program File) which might have caused the problem.
For IE Driver download it (32bit) LINK
After that your browser init need to be something like that:
InternetExplorerDriverService driverService = InternetExplorerDriverService.CreateDefaultService();
driverService.HideCommandPromptWindow = true;
driverService.LibraryExtractionPath = #"c:\drivers\"; // here is your driver location
InternetExplorerOptions options = new InternetExplorerOptions();
options.EnableNativeEvents = true;
options.IgnoreZoomLevel = true;
options.IntroduceInstabilityByIgnoringProtectedModeSettings = true;
driver = new InternetExplorerDriver(driverService, options, TimeSpan.FromSeconds(180));
For Firefox just try to update the firefox to last version.

Testing a Windows 8 Store App with NUnit

I'm currently working on a Windows Store Application (Windows 8) for a class and I'm having problems getting my NUnit tests to run.
My Solution/Project setup looks like the following:
TheMetroApp.sln
SQLite-net.csproj - Class Library (Windows Store Apps). Files are pulled from NuGet.
DataModel.csproj - Class Library (Windows Store Apps)
UnitTests.csproj - Unit Test Library (Windows Store Apps). NUnit framework is pulled from NuGet.
TheMetroApp.csproj - A project file which was pulled from one of the Windows SDK examples.
Misc. Dependencies and Utilities
Windows 8 Pro RTM/Visual Studio 2012 RTM
ReSharper 7
NUnit 2.6.1
SQLite (Set up per the instructions here)
UnitTests is dependent upon and references DataModel. DataModel is dependent upon and references SQLite-net. The only thing I have added to the UnitTests project is a single class containing some stub NUnit unit tests. As far as I can tell, these are set up correctly:
[TestFixture]
public class TaskSourceTests
{
#region Private Class Members
private ITaskSource _taskSource;
private String _dbPath;
#endregion
#region Testing Infrastructure
[SetUp]
public void SetUp()
{
// This part makes NUnit/ReSharper have problems.
_dbPath = Path.Combine(ApplicationData.Current.LocalFolder.Path, "UnitTestDatabase.sqlite");
}
#endregion
#region Misc. CRUD stuff
[Test]
public void CreateTaskTest()
{
// Save the task.
Task task = new Task( "Some Task", "lol.", DateTime.Now, false );
_taskSource.Save( task );
// Confirm that it is in the task db.
using( SQLiteConnection db = new SQLiteConnection( _dbPath ) )
{
const String query = "SELECT * FROM Task WHERE Id = ?";
IList<Task> results = db.Query<Task>( query, task.Id );
Assert.True( results.Contains( task ) );
}
}
// ...and so on [but with stubs that are basically Assert.Fail( "" )].
#endregion
}
TheMetroApp is one of the Windows 8 SDK sample projects, but with some custom XAML forms thrown in. I'm not having any problems with this project.
My issue is that none of the Unit Test runners that I have tried to use are working.
When I try to use the official NUnit x86 Test runner (version 2.6.1), my tests fail due to certificate related issues (see here):
UnitTests.TaskSourceTests.CreateTaskTest:
SetUp : System.InvalidOperationException : The process has no package identity. (Exception from HRESULT: 0x80073D54)
ReSharper's NUnit test runner fails for the exact same reason. Unfortunately, it doesn't look like there is currently a workaround for that.
I have also tried using the test runner built into Visual Studio 2012 (through the NUnit Visual Studio Test Adapter). When I try to run my tests using "Run All", I get the following output:
------ Run test started ------
Updating the layout...
Checking whether required frameworks are installed...
Registering the application to run from layout...
Deployment complete. Full package name: "GibberishAndStuff"
No test is available in C:\Projects\project-name\ProjectName\UnitTests\bin\Debug\UnitTests.dll. Make sure that installed test discoverers & executors, platform & framework version settings are appropriate and try again.
========== Run test finished: 0 run (0:00:09.4873768) ==========
Something strange I have noticed is that if I select a specific test in the Test Explorer and tell it to run, I get a slightly different error message:
Could not find test executor with URI 'executor://nunittestexecutor/'. Make sure that the test executor is installed and supports .net runtime version 4.0.30319.18010.
This is kind of perplexing because I have the NUnit Test Adapter installed. I'm not seeing anything similar to my issue on the launchpad page for the test adapter.
I'm not really sure where I should proceed from here. If this doesn't work I don't mind reworking my project to use xUnit.net, Microsoft's unit testing framework or something else. It would be pretty awesome if I could get NUnit working though.
Thanks!
I have a Windows 7 Phone app which had the same issue that you have. My solution was to create a separate "linked" project which compiles the code using the standard .net libraries. The linked project will have no issues with unit test / NUnit.
See the following for more information:
http://msdn.microsoft.com/en-us/library/ff921109(v=pandp.40).aspx
http://visualstudiogallery.msdn.microsoft.com/5e730577-d11c-4f2e-8e2b-cbb87f76c044/
I've ported the app to Windows 8 and have no problems running my test cases.
I've just hit the same error message while creating unit tests for an Universal App (W81 + WP81). The only solution here was to stop using NUnit and use MSTest only.

Categories

Resources