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?
Related
I'm currently trying to implement a scroll feature for my SpecFlow tests I'm running through Selenium to test a website. I need to be able to scroll down so the driver can see certain elements and test them. Basically, I've coded a scroll feature (using webdriver as IJavaSriptExecutor) but when I implemented that step to my tests it would try and open a separate webdriver. I need this scroll feature to execute on the driver that is currently open testing other features. Basically I need everything to be in unison if that makes sense. Anyway here is my code with the error at the bottom. I have no idea what the issue is.
namespace (mynamespace)
{
[Binding]
public class SeleniumContext
{
public SeleniumContext()
{
//create the selenium context
WebDriver = new ChromeDriver();
}
public IWebDriver WebDriver { get; private set; }
}
public class BeforeAllTests
{
private readonly IWebDriver objectContainer;
private static SeleniumContext seleniumContext;
public BeforeAllTests(IWebDriver container)
{
this.objectContainer = objectContainer;
}
[BeforeTestRun]
public static void RunBeforeAllTests()
{
seleniumContext = new SeleniumContext();
}
[BeforeScenario]
public static void RunBeforeScenario()
{
objectContainer.RegisterInstanceAs<SeleniumContext>(seleniumContext);
}
[Then(#"I scroll down")]
public void ThenIScrollDown()
{
ScenarioContext.Current.Pending();
}
}
}
Severity Code Description Project File Line Suppression State
Error CS0120 An object reference is required for the non-static field, method, or property 'BeforeAllTests.objectContainer'
I have been teaching myself Selenium over the past few weeks and have started writing my own tests, I can get all my happy flow tests to work fine but my first attempt at writing a test to check an error message is not working.
As an overview the test is really simple:
Enter an invalid postcode into a search box
click search
Assert the screen shows an error message below the search box.
I know the logic of my code works as when I run the positive flow (enter postcode, click search, new page opens) the automated test is working fine. Also when I run the test in debug mode and step through the failed Assert the test passes with the error message picked up.
My Test code
[TestClass]
public class invalidSearch
{
[TestInitialize]
public void Init()
{
driver.Initialize();
}
[TestMethod]
public void Invalid_Location_Returns_Error()
{
Homepage.GoTO_HomePage();
SearchPage.enterSearch("CFYUGHGYHYTDFD").Search();
Assert.IsTrue(SearchErrorMessage.IsInValidLocation("Please enter a valid location or postcode", "Validation Fails"));
}
[TestCleanup]
public void Cleanup()
{
driver.Close();
}
My assert class
public class SearchErrorMessage
{
public static bool IsInValidLocation(string InvalidLocation)
{
var ErrorMessage = driver.Instance.FindElement(By.XPath("/html/body/header/div/div[4]/div/div/div[2]/div[1]/form/div[2]/span[2]"));
bool result = ErrorMessage.Text.Contains(InvalidLocation);
return result;
}
My driver Class
public class driver
{
public static IWebDriver Instance { get; set; }
public static void Initialize()
{
Instance = new ChromeDriver(#"C:\Users\xxxxxx.xxxxxx\Documents\Visual Studio 2015\Drivers\Chrome");
Instance.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10));
}
public static void Close()
{
Instance.Close();
}
You probably just need an explicit wait, try this:
public static bool IsInValidLocation(string invalidLocation)
{
By selector = By.XPath("/html/body/header/div/div[4]/div/div/div[2]/div[1]/form/div[2]/span[2]");
// You might want to research how to construct stable xpaths/selctors
new WebDriverWait(driver.Instance, TimeSpan.FromSeconds(5)).Until(ExpectedConditions.ElementIsVisible(selector));
var ErrorMessage = driver.Instance.FindElement(selector);
bool result = ErrorMessage.Text.Contains(invalidLocation);
return result;
}
The above code will give that message up to 5 seconds to appear, and will throw a timeout exception if it doesn't appear within 5 seconds. You can adjust it to wait longer if needed.
I'm new to Selenium Testing and trying to learn it.
When running the test, I have an error OpenQA.Selenium.WebDriverException:
Failed to start up socket within 45000 milliseconds`
This is my sample code:
[TestClass]
public class MyTest
{
IWebDriver driver;
[TestMethod]
public void VerifyTitle()
{
//Write Actual Test
string title = driver.Title;
Assert.AreEqual(title, "Done The deal");
}
[TestInitialize]
public void Setup()
{
//start browser and oprn url
driver = new FirefoxDriver();
driver.Navigate().GoToUrl("http://Donethedeal.com/");
}
[TestCleanup]
public void CleanupTest()
{
//close browser
driver.Quit();
}
}
I installed, I think, all necessary libraries using NuGet Package Manager
I have installed Selenium.WebDriver -Version 2.53.1 instead of 3.0.0 beta, since only with this version I was able to start Firefox browser. However, I could not open the url and got the described error while doing so
What am I missing?
at first your mistake is in the IWebDriver object declaration. You are declaring the object locally in the SetUp() method. If you do that the range of the object is inside the method only. Outside of the method the object is null. So move the declaration outside of all methods (preferably on the top, such as bellow)
The next mistake is the Attributes that you are using. I have to mention here that I used the NUnit3TestAdapter and NUnit from Nuget. I didnt find nowhere your attributes so I add mine :) In the SetUp method I used the [SetUp] attribute in the CleanUp[TearDown] and in VerifyTitle [Test]. Take a look in the code bellow for more details
IWebDriver driver = new FirefoxDriver();
static void Main(string[] args)
{
}
[Test]
public void VerifyTitle()
{
//Write Actual Test
string title = driver.Title;
// Assert.AreEqual(title, "DoneThedeal");
////I wanted to keep it simple change it back if u wish
if (title.Contains("DoneTheDeal"))
{
Console.WriteLine(title);
}
else
{
Console.WriteLine("Title not found");
}
}
[SetUp]
public void Setup()
{
//start browser and oprn url
driver.Navigate().GoToUrl("http://Donethedeal.com/");
}
[TearDown]
public void CleanupTest()
{
//close browser
driver.Quit();
}
}
**If you want to see the console results look for "Output" in the Text Explorer
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.
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;
}
}
}