Cannot launch Repl() (Xamarin) - c#

I'm writing UITests on Xamarin. I'm trying to launch the Repl window, but it doesn't launch.
My code:
using System;
using System.IO;
using System.Linq;
using NUnit.Framework;
using Xamarin.UITest;
using Xamarin.UITest.Android;
using Xamarin.UITest.Queries;
namespace MurakamiKiev.UITests
{
[TestFixture]
public class Tests
{
AndroidApp app;
[SetUp]
public void BeforeEachTest ()
{
app = ConfigureApp.Android.StartApp();
}
[Test]
public void ClickingButtonTwiceShouldChangeItsLabel ()
{
app.Repl();
}
}
}
What's wrong with my code? Thanks for the help.

I had the same issue, the problem was that app.Repl(); was already running in the background, from the previous session.(When you are debugging if you terminate debugger it wont close automatically)
The error I got was:
System.Exception: 'Error while performing Repl()
Inner exception
IOException: The process cannot access the file 'C:\Users\daniel\AppData\Local\Temp\uitest\repl\ICSharpCode.NRefactory.CSharp.dll because it is being used by another process.
So you just need to close app.Repl(); command prompt that is running in the background

Nothing is wrong with that code. I have seen this happen before but now can't recall the exact resolution. Might have been using NUnit version >= 3. Can you see if you still get the same issue using NUnit version 2.6.3?

Related

Slow execution of tests using Teststack.White + Nunit3-console

Hello i have small problem with nunit and teststack white.
Here i have small test (Window is localized with option WithCache):
[Test] public void ShouldLogIn()
{
var loginPanel = Window.Get<Panel>("txbLogin");
var loginTextBox = loginPanel.Get<TextBox>("mobTextBox1");
loginTextBox.BulkText = "user1";
}
Now i run this test from VS, and debugging each step. I can notice, that Get takes around 50ms, Get 30ms. Next i run the same test using nunit3-console.exe and now, after attaching to process i can notice around 3 time longer execution of each step. Its not problem with attaching, becouse i checked it in longer test and always steps takes longer.
Another long process is getting new window. My application show new windows, which covers actual one, so i need to get new window when new one appears. Command Application.GetWindows().Last() takes around 200-300ms from VS, but from nunit console in worst case can take about 3 seconds.
Maybe someone of you have similar problem and have any solution for me.
HERE I HAVE EXAMPLE:
You need to download app from here:
https://www.codeproject.com/Articles/607868/Social-Club-Sample-application-using-WinForms-Csha
Build it, run application, login into it with credentials:
login: demo
password: demo123
Then create new unit test prkject, add nuget pacakges for nunit and teststack.white. Here is code for this test:
using System.Diagnostics;
using System.Linq;
using System.Threading;
using Castle.Core.Logging;
using NUnit.Framework;
using TestStack.White;
using TestStack.White.Configuration;
using TestStack.White.Factory;
using TestStack.White.UIItems;
using TestStack.White.UIItems.Finders;
using TestStack.White.UIItems.WindowItems;
namespace StackTestProject
{
[TestFixture]
public class Notepadtests
{
private Application Application;
private Window Window;
[OneTimeSetUp]
public void OneTimeInitialize()
{
CoreAppXmlConfiguration.Instance.FindWindowTimeout = 30000;
CoreAppXmlConfiguration.Instance.LoggerFactory = new WhiteDefaultLoggerFactory(LoggerLevel.Debug);
}
[SetUp]
public void TestInitialize()
{
Thread.Sleep(5000);
ProcessStartInfo psi = new ProcessStartInfo("John.SocialClub.Desktop.exe");
psi.WorkingDirectory = #"C:\Users\[USER NAME]\Downloads\John.SocialClub\John.SocialClub\John.SocialClub.Desktop\bin\Debug";
Application = TestStack.White.Application.AttachOrLaunch(psi);
//before this u need to have opened and logged in aplication with login:demo and password: demo123
Window = Application.GetWindow("Social Club - Membership Manager", InitializeOption.WithCache); //250ms
}
[Test]
public void NotepadTest()
{
var toolbar = Window.Get<Panel>(SearchCriteria.ByClassName("tabRegistration")); //33ms
}
[TearDown]
public void TestCleanup()
{
Application.Kill();
}
}
}
I hit breakpoint on line where i assign value to Window, and now i check time of getting window with name "Social Club - Membership Manager":
a) when i debug test from visual studio - its around 450ms for first assign, when i move cursor back to this line and assign again its faster and takes about 250ms
b) when i run from nunit3-console with command :
nunit3-console.exe C:\Users\kamil.chodola\source\repos\StackTestProject\StackTestProject\bin\Debug\StacktestProject.dll
and attach to proces nunit-agent.exe program stops on breakpoint and now assign of Window take around 1second, second assign takes around 700ms which is still longer than running same test from visual studio adapter.
I must notice that its not problem with attaching to proces, becouse without attaching i can see as well, that this test takes longer than from visual studio.
Really interesting thing is that i reproduce this issue only on winforms applications. When i automatize app like notepad which is base on Win32 framework times are normal or even faster. Same thing on web application, and automatizing with selenium webdriver.

Can't get Process.Start to work in C#

I've been trying to run a command from an app written in C#, and all I've read had to do with using System.Diagnostics.Process.Start to run it. However, whenever I try to use this function, the compiler throws an error telling me that 'The type or namespace name 'Process' does not exist in the namespace System.Diagnostics'.
When I try to write the command, intellisense doesn't show anything about "Process" inside the System.Diagnostics namespace.
This doesn't work:
using Windows.ApplicationModel.Activation;
using Windows.UI.Xaml;
using System.Diagnostics;
namespace App2
{
sealed partial class App : Application
{
public App()
{
}
protected override void OnLaunched(LaunchActivatedEventArgs e)
{
System.Diagnostics.Process.Start("CMD.exe", "help"); // This is giving me an error
}
}
}
EDIT: I just tried creating a new Windows Forms project, and I could find System.Diagnostics.Process.Start. Does anyone know how can I run a command from an Universal Windows App, since it's apparently not supported?

Sikuli Integrator C#

I want to use SikuliIntegrator in C#.
I run VS as administrator, install SikuliIntegrator throught NuGet manager and want to test him on simple task.
Heres my code
using SikuliModule;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SikuliTrainingNet
{
class Program
{
static void Main(string[] args)
{
string MyPicture = #"c:\111\Sik\MyPicture.png";
SikuliAction.Click(MyPicture);
}
}
}
after running code (and have prepared MyPicture on screen), all i get is exception "###FAILURE" any idea why?
I dont wanna use Sikuli4Net, becose its look like it work on web aps and I need just few simple clicks on desktop aplication.
I try sikuli in Java, and there it works with no problem. But I need to make my program in C#.
I Used This Code For Sikuli4Net in C#,It Was Working For Me First You need add the References please see this link for Reference
http://interviews.ga/angularjs/sikulic/
static void Main(string[] args)
{
APILauncher launch = new APILauncher(true);
Pattern image1 = new Pattern(#"C:\Users\Ramesh\Desktop\Images\userName.png");
Pattern image2 = new Pattern(#"C:\Users\Ramesh\Desktop\Images\password.png");
Pattern image3 = new Pattern(#"C:\Users\Ramesh\Desktop\Images\Login.png");
launch.Start();
IWebDriver driver = new ChromeDriver();
driver.Manage().Window.Maximize();
driver.Url = "http://gmail.com";
Screen scr = new Screen();
scr.Type(image1, "abc#gmail.com", KeyModifier.NONE);
scr.Type(image2, "12345", KeyModifier.NONE);
scr.Click(image3, true);
Console.ReadLine();
}
I used this code and it was working fine. First you should open the webpage on which you want to click and then give a path of the image(it should be a part of the webpage)
here is my code:
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using SikuliModule;
using OpenQA.Selenium;
namespace WordPressAutomation.DifferentTests
{
[TestClass]
public class Sikuli
{
[TestMethod]
public void TestMethod1()
{
driver.Initialize();
driver.instance.Navigate().GoToUrl("https://www.google.co.in");
SikuliAction.Click("E:/img.png");
}
}
}
To use SikuliInyegrator, you need to check the execution results in these files:
C:\SikuliExceptionLog.txt
C:\SikuliOutputLog.txt
Also you need to:
Have installed JRE7 or superior
Have environment variable PATH with the location of the bin folder
See installed in your “control panel > program and features> visual C++ 2010 Redistributable Package” at x86 and x64 bits according to your java JRE runtime platform. If not, then download and install the Redistributable Package form Microsoft site.

system ("pause") in C# won't work. Alternatives?

I am building a program for the purposes of displaying Smartgraph3 readings. Whenever I start debugging, the command line opens but it then immediately disappears. I know ctrl + f5 works, but I was looking for a solution where I would not have to enter the same command to keep it from disappearing.
I have used System("pause"); but it keeps coming up with a blue line under System, and in the error list says 'System' is a 'namespace' but is used like a 'variable'. Does anybody know what is wrong?
Also, I have heard System("pause") should not be used, so does anybody have an alternative that's just as effective?
Here is a copy of my code. Thank you.
using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.Text;
using Infowerk.SmartGraph3.SmartGraph3API;
//using CSTestClient.SmartGraph;
namespace CSTestClient
{
class Program
{
static void Main(string[] args)
{
TestAPI();
}
static void TestAPI()
{
System.ServiceModel.Channels.Binding service_binding = new BasicHttpBinding();
EndpointAddress endpoint_address = new EndpointAddress("http://localhost:8000/SmartGraph3API/APIV01");
SmartGraph3APIClient client = new SmartGraph3APIClient(service_binding, endpoint_address);
List<SG3APIDeviceIdentification> device_list = client.GetDeviceList();
foreach (SG3APIDeviceIdentification device_identification in device_list)
{
Console.WriteLine("device id: {0}", device_identification.DeviceId);
System("pause");
}
}
}
}
Go ahead and simply use:
Console.ReadKey();
Set a breakpoint on the closing brace of your Main(). Or use an IDE which streams console output to a debug window which persists after the process exits (e.g., Eclipse, I assume basically anything other than VS). No reason to force everyone who actually wants to run your program the normal way to invoke it like:
:; ./myProgram.exe < /dev/null; exit $?
.\myProgram.exe < NUL
See https://stackoverflow.com/a/20487235.

C# "await" error when using WinRT from Desktop app

I trying to get my GPS position from a Desktop app, using Windows Runtime, in C#.
I followed this how-to to set up Visual Studio and this code sample to create the following trivial code as a C# console app :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.IO;
using System.Runtime;
using System.Windows;
using Windows;
using Windows.Devices.Geolocation;
using Windows.Foundation;
using Windows.Foundation.Collections;
namespace GeoLocCS
{
public sealed partial class Program
{
static void Main(string[] args)
{
Test test = new Test();
Console.Read();
}
}
public class Test
{
private Geolocator geolocator;
public Test()
{
Console.WriteLine("test");
geolocator = new Geolocator();
this.getPos();
}
async void getPos()
{
Geoposition pos = await geolocator.GetGeopositionAsync();
Console.WriteLine(pos.Coordinate.Latitude.ToString());
}
}
}
When trying to compile, I get the error :
Error 1 'await' requires that the type 'Windows.Foundation.IAsyncOperation<Windows.Devices.Geolocation.Geoposition>' have a suitable GetAwaiter method. Are you missing a using directive for 'System'?
I tried to reference every DLL that I could, like "System.runtime", "System.Runtime.WindowsRuntime", "Windows.Foundation"...
What I am missing ?
Thanks for the answer,
Serge
I finally figured out my problem :
I am on 8.1 so I changed this in the .csproj file (targetingPlatform) instead of targeting 8.0
After that modification, I could reference "Windows"
I manually referenced the two following DLLs :
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.5\Facades\System.Runtime.dll
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\System.Runtime.WindowsRuntime.dll
If you are On Win8.1 Please Use:
<TargetPlatformVersion>8.1</TargetPlatformVersion>
and not 8.0.
Adding to the existing answers:
I suddenly got this problem with a multiproject solution in WPF (still don't know why). I tried switching between TargetPlatformVersions 8.1 and 10.0, tried using the v4.5- and v4.5.1-System.Runtime.WindowsRuntime.dll, always alternating between BadImageFormatException and FileNotFoundException.
Turned out to be references in some of the app.config-files (not the .csproj-files!). Visual Studio 2017 must have added them at some point and as soon as I removed these entries, the above solutions finally worked.

Categories