I'm writing UITests on Xamarin
I try 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();
}
}
}
This is, how I try to launch Repl:
That is, what I have in Console.
What wrong with my code??
I tried breakpoints, but nothin happens.
I tried to update references, but it didn't help.
Or if issue not in code, how I can launch Repl window?
Help me please I wrote Xamarin forums, but don't have answer.
UPDATE
I try to use Debug and x86
Have this error
Severity Code Description Project File Line Suppression State
Error java.lang.OutOfMemoryError. Consider increasing the value of $(JavaMaximumHeapSize). Java ran out of memory while executing 'java.exe -jar C:\android-sdk\build-tools\23.0.1\\lib\dx.jar --no-strict --dex --output=obj\x86\Debug\android\bin obj\x86\Debug\android\bin\classes "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\MonoAndroid\v6.0\mono.android.jar" C:\Users\nemes\Documents\GitHub\Murakami_kiev\MurakamiKiev\obj\x86\Debug\__library_projects__\Square.OkHttp\library_project_imports\okhttp.jar C:\Users\nemes\Documents\GitHub\Murakami_kiev\MurakamiKiev\obj\x86\Debug\__library_projects__\Square.OkIO\library_project_imports\okio-1.6.0.jar C:\Users\nemes\Documents\GitHub\Murakami_kiev\MurakamiKiev\obj\x86\Debug\__library_projects__\Square.Picasso\library_project_imports\picasso-2.5.2.jar C:\Users\nemes\Documents\GitHub\Murakami_kiev\MurakamiKiev\obj\x86\Debug\__library_projects__\UrlImageViewHelper\library_project_imports\bin\classes.jar C:\Users\nemes\AppData\Local\Xamarin\Android.Support.Animated.Vector.Drawable\23.3.0.0\embedded\classes.jar C:\Users\nemes\AppData\Local\Xamarin\Android.Support.v4\23.3.0.0\embedded\classes.jar C:\Users\nemes\AppData\Local\Xamarin\Android.Support.v4\23.3.0.0\embedded\libs\internal_impl-23.3.0.jar C:\Users\nemes\AppData\Local\Xamarin\Android.Support.v7.AppCompat\23.3.0.0\embedded\classes.jar C:\Users\nemes\AppData\Local\Xamarin\Android.Support.v7.MediaRouter\23.3.0.0\embedded\classes.jar C:\Users\nemes\AppData\Local\Xamarin\Android.Support.v7.MediaRouter\23.3.0.0\embedded\libs\internal_impl-23.3.0.jar C:\Users\nemes\AppData\Local\Xamarin\Android.Support.Vector.Drawable\23.3.0.0\embedded\classes.jar C:\Users\nemes\AppData\Local\Xamarin\GooglePlayServices.Analytics\8.4.0\embedded\classes.jar C:\Users\nemes\AppData\Local\Xamarin\GooglePlayServices.Base\8.4.0\embedded\classes.jar C:\Users\nemes\AppData\Local\Xamarin\GooglePlayServices.Basement\8.4.0\embedded\classes.jar C:\Users\nemes\AppData\Local\Xamarin\GooglePlayServices.Maps\8.4.0\embedded\classes.jar' MurakamiKiev
My Heap size is set to 1G
Any answers how I can launch Repl?????
Look into adding platform specification for initializer
[TestFixture(Platform.Android)]
public class Tests
{
IApp app;
Platform platform;
public Tests(Platform platform)
{
this.platform = platform;
}
[SetUp]
public void BeforeEachTest()
{
app = AppInitializer.StartApp(platform);
}
[Test]
public void AppLaunches()
{
app.Repl();
}
}
Also I've noticed you have your project in Release mode - put it to Debug.
Related
Sometimes it is required to turn off sleep mode in the application while a lengthy process is running. When the process has done, sleep mode can be turned on again.
How to do that in Xamarin, for Android and iOS projects?
We'll make an interface and use DependencyService to run platform-specific implementation in the platform-agnostic project.
In the platform agnostic project create an interface:
namespace MyCompany.Services {
public interface ISleepModeHandler
{
public void BlockSleepMode(bool blockSleepMode);
}
}
In the Android project:
In the AndroidManifest.xml file, add this permission:
<uses-permission android:name="android.permission.WAKE_LOCK" />
Add Xamarin.Essentials dependency to the platform-agnostic and to the android project. And don't forget to initialize Xamarin.Essentials in the android project.
Create the class:
using Android.Views;
using MyCompany.Android.Services;
using MyCompany.Services
using Xamarin.Essentials;
using Xamarin.Forms;
[assembly: Dependency(typeof(SleepModeHandlerForDroid))]
namespace MyCompany.Android.Services
{
public class SleepModeHandlerForDroid : ISleepModeHandler
{
public void BlockSleepMode(bool blockSleepMode)
{
Xamarin.Forms.Device.BeginInvokeOnMainThread(() =>
{
MainActivity activity = (MainActivity)Platform.CurrentActivity;
if (blockSleepMode)
{
activity.Window.AddFlags(WindowManagerFlags.KeepScreenOn);
}
else
{
activity.Window.ClearFlags(WindowManagerFlags.KeepScreenOn);
}
});
}
}
}
In iOS project create the class:
using MyCompany.Services;
using MyCompany.iOS.Services;
using UIKit;
using Xamarin.Forms;
[assembly: Dependency(typeof(SleepModeHandlerForiOS))]
namespace MyCompany.iOS.Services
{
[Foundation.Preserve(AllMembers = true)]
public class SleepModeHandlerForiOS : ISleepModeHandler
{
public void BlockSleepMode(bool blockSleepMode)
{
Xamarin.Forms.Device.BeginInvokeOnMainThread(() =>
{
UIApplication.SharedApplication.IdleTimerDisabled = blockSleepMode;
});
}
}
}
That's it. Now, in platform agnostic module, when you want to block sleep mode while processing, and turn it on afterwards use the following approach:
ISleepModeHandler sleepModeHandler = DependencyService.Get<ISleepModeHandler>();
sleepModeHandler.BlockSleepMode(true); // blocking the sleep mode
// your process goes here
sleepModeHandler.BlockSleepMode(false); // allowing the sleep mode again
So I've done some coding with unity previously but trying to do traditional coding and am having trouble figuring it out.
After downloading Google Assistant on my Windows 10 computer, it does not listen to "Ok google". So I decided that a simple project was to make a program that would listen for a keyword and would stimulate the keys: Win+Shift+A to open Google Assistant.
The current code I have is here:
using NUnit.Framework;
using WindowsInput;
namespace Ok_Google
{
public class Tests
{
[SetUp]
public void Setup()
{
}
string keyWord1 = "Ok Google";
string keyWord2 = "Hey Google";
private object SendKeys;
public void Start()
{
}
public void ListeForKeyWord()
{
}
public void EnterShortCut()
{
SendKeys.Send("{LWin}");
SendKeys.Send("{Shift}");
SendKeys.Send("{A}");
}
[Test]
public void Test1()
{
Assert.Pass();
}
}
}
It's not recognizing the Object Send, following the command SendKeys
Can anyone find a potential solution for this and show the process of correcting these errors?
I'm beginner in Xamarin Test Cloud and I want to write tests for Xamarin Test Cloud.
I have Xamarin UITests in my solution and I tried to launch REPL, but UITest REPL window didn't open.
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 TestLaunch ()
{
app.Repl();
}
}
}
Where is the error?
Also, what I need to write to launch specified activity?
If you don't have the application source code in the same solution then you'll need to specify the prebuilt app by pointing to it via a full path.
[SetUp]
public void BeforeEachTest ()
{
app = ConfigureApp.Android.ApkFile("<path-as-string>").StartApp ();
}
I'm porting an VS addin to a VS Package. The package subscribes to OnBuildBegin and OnPublishBegin when the package is initialized. Visual Studio triggers OnBuildBegin as expected, but OnPublishBegin is never called.
More or less the same code work in Visual Studio 2013, 2012, and 2010 as an addin. But in VS 2015 as a VS Package, OnPublishBegin doesn't appear to be functional.
Sample Code is below.
To test the code running the debugger configured to start a second instance of VS in Experiment Mode. In the second instance, I open a different solution and publish using the Publish Wizard.
using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using EnvDTE;
using EnvDTE80;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;
namespace MyPackage
{
[PackageRegistration(UseManagedResourcesOnly = true)]
[InstalledProductRegistration("#110", "#112", "1.0", IconResourceID = 400)] // Info on this package for Help/About
[Guid(VSPackage.PackageGuidString)]
[SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1650:ElementDocumentationMustBeSpelledCorrectly", Justification = "pkgdef, VS and vsixmanifest are valid VS terms")]
[ProvideAutoLoad(UIContextGuids80.SolutionBuilding)]
public sealed class VSPackage : Package
{
public const string PackageGuidString = "a8ddf848-00ea-4e4e-b11a-65663a8a8021";
private DTE2 application;
public VSPackage()
{
}
protected override void Initialize()
{
base.Initialize();
this.application = (DTE2) this.GetService(typeof(DTE));
((Events2)this.application.Events).BuildEvents.OnBuildBegin += this.OnBuildBegin;
((Events2)this.application.Events).PublishEvents.OnPublishBegin += this.OnPublishBegin;
}
private void OnBuildBegin(vsBuildScope scope, vsBuildAction action)
{
MessageBox.Show("OnBuildBegin");
}
private void OnPublishBegin(ref bool pubContinue)
{
MessageBox.Show("OnPublishBegin");
}
}
}
Can anyone shed light on the problem for me?
It is highly recommended to keep references to Events objects to protect them from GC:
protected override void Initialize()
{
events = application.Events;
buildEvents = events.BuildEvents;
publishEvents = events.PublishEvents;
buildEvents.OnBuildBegin += this.OnBuildBegin;
publishEvents.OnPublishBegin += this.OnPublishBegin;
}
private Events2 events;
private BuildEvents buildEvents;
private PublishEvents publishEvents;
I am trying to set up a visual studio project with acceptance tests using NUnit and Selenium Web Driver, I would like to be able to "run tests" and this to start my web site, use selenium to run the tests and quit.
I have this basic setup so far:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.PhantomJS;
namespace FrontEndTests.AcceptanceTests
{
[TestFixture]
class Phantom
{
private PhantomJSDriver _driver;
[SetUp]
public void WhenOpeningANewWebPage()
{
_driver = new PhantomJSDriver();
_driver.Navigate().GoToUrl(#"localhost");
}
[Test]
public void ThenICanFindAClass()
{
Assert.NotNull(_driver.FindElement(By.ClassName("featured")));
}
[TearDown]
public void Finally()
{
_driver.Quit();
}
}
}
If I set the URL to 'www.google.com' the tests pass fine (with the correct class set) but localhost returns elementnotfoundexception in selenium.
How do I get it to work locally?
Thanks
Based on this:
"When I run the project in visual studio it points to localhost:31106 I have tried to using this as the URL but this gives the same error - Gregg_1987"
IIS must be running your application. When you click run it starts the application in IIS express for the time that the application is running. Visual Studio then attaches to this for execution purposes.
If you are trying to execute Selenium on this you would have to install regular IIS and register the application through IIS so that it will be accessible. Then your tests can hit this through the URL registered in IIS. Otherwise you would have to try to programmatically execute the app using IIS express which there is some guidance on here: Automatically start ASP.MVC project when running test project
Once the site is accessible through IIS you can then hit it with your Selenium tests.
Well, you need to start you site before all tests or you can start it once in SetUp and kill it in TearDown (or if you are going to run your tests on some CI then run once before all tests and kill after all). To start it you can choose either webdev or iisexpress (on your choice), below sample of using WebDev.WebHost.dll
public class Phantom
{
private PhantomJSDriver _driver;
//Move this field to base class if you need to start site before each test
//e.g. you can move setup and teardown to base class, it's all up to you
public DevServer WebDevServer { get; private set; }
[SetUp]
public void WhenOpeningANewWebPage()
{
WebDevServer = new DevServer();
WebDevServer.Start();
_driver = new PhantomJSDriver();
_driver.Navigate().GoToUrl(#"localhost");
}
[Test]
public void ThenICanFindAClass()
{
Assert.NotNull(_driver.FindElement(By.ClassName("featured")));
}
[TearDown]
public void Finally()
{
_driver.Quit();
WebDevServer.Stop();
}
}
public class DevServer
{
private Server _webServer;
public DirectoryInfo SourcePath { get; set; }
public string VirtualPath { get; set; }
public int Port { get; set; }
public DevServer()
{
//Port
Port = Settings.WebDevPort;
//Path to your site folde
SourcePath = Settings.WebDevSourcePath;
//Virt path can be ~
VirtualPath = Settings.WebDevVirtualPath;
}
public void Start()
{
Stop();
try
{
_webServer = new Server(Port, VirtualPath, SourcePath.FullName);
_webServer.Start();
}
catch (Exception e)
{
Trace.TraceError("Process cannot be started." + Environment.NewLine + e);
throw;
}
}
public void Stop()
{
if (_webServer != null)
{
_webServer.Stop();
_webServer = null;
}
}
}