So I use RemoteTesttRunner to run a couple of tests with selenium and they work perfectly the first time I run them. But if I try to run them a second time the web browser don't show up and he fail the test directly.
I run the tests like this:
var location = AppDomain.CurrentDomain.BaseDirectory;
var runner = new RemoteTestRunner();
runner.Load(new TestPackage(Path.Combine(location,"/my_test.dll")));
var result = runner.Run(new NullListener(), TestFilter.Empty, false, LoggingThreshold.All);
return result;
And the test I run look like this:
[Test]
public void AutomationTest()
{
ChromeDriver driver = new ChromeDriver()
driver.Navigate().GoToUrl("www.google.se")
}
So is there something I need to clean after every test or why does the web browser not show up after my first test run? As it run just fine the first time I can't find any wrong with the code.
Should add that I don't get any exception or anything like that, it just don't show up.
Related
I'm having issues testing iPhone on BrowserStack with tests written in C# with Selenium and Protractor-net.
The test starts running and after it opens the webpage to my website, it just hangs and never moves on to the StringAssert step. There are no errors when this happens. I must manually stop my test and the session in BrowserStack to continue.
I tried turning on logging from within BrowserStack's capabilities, but no errors are returning and the console log is empty. I've tried multiple configs of iPhones too.
Note, this sample test works fine with Android Google Pixel 2 and Windows 10 testing on BrowserStack, just iPhone's are giving me this problem.
Here is my sample test:
class Class1
{
[Test]
public static void FirstTest()
{
IWebDriver driver;
DesiredCapabilities capability = new DesiredCapabilities();
capability.SetCapability("browserName", "iPhone");
capability.SetCapability("device", "iPhone 6S");
capability.SetCapability("realMobile", "true");
capability.SetCapability("os_version", "11.4");
capability.SetCapability("browserstack.console", "errors");
capability.SetCapability("browserstack.user", "");
capability.SetCapability("browserstack.key", "");
driver = new RemoteWebDriver(new Uri("http://hub-cloud.browserstack.com/wd/hub/"), capability);
driver.Manage().Timeouts().AsynchronousJavaScript = TimeSpan.FromSeconds(10);
NgWebDriver ngdriver = new NgWebDriver(driver);
ngdriver.Navigate().GoToUrl("https://myproduction.website/");
StringAssert.Contains("MyTitle", ngdriver.Title);
NgWebElement query = ngdriver.FindElement(NgBy.Model("employeeCode"));
query.Clear();
query.SendKeys("Browserstack");
Console.WriteLine(ngdriver.Title);
ngdriver.Quit();
}
}
I understand you are running Protractor tests on real iOS devices. Protractor injects JavaScripts using execute_async method. The execute_async method is not fully supported by Appium due to which you may be seeing failures. You will find more details on the issue at the links below:
https://github.com/angular/protractor/issues/2840
https://github.com/angular/protractor/issues/1736
I am writing a UI test. This is to check for the error 404 page which I have enabled in Web.Config via;
<customErrors mode="On" redirect="~/Errors/"/>
This all works fine, however I only have custom errors set to "On" whilst in the "UAT" development environment. If I am in "Dev" or "IST" then I still want to see the default ASP.Net errors.
So now back to the UI test using Selenium
public string GetAlertBoxDetails()
{
IWebElement alertBox = _driver.FindElement(By.CssSelector(".alert.alert-danger"));
return alertBox.Text;
}
As you can see I am detecting the Bootstrap ".alert.alert-danger" box and returning the text inside. I then check to see if this text contains "Sorry, that page doesn't exist.". I am using Specflow for the text story.
[Then(#"The user should be told that no such page exists")]
public void ThenTheUserShouldBeToldThatNoSuchPageExists()
{
string alertboxDetail = GetAlertBoxDetails();
Assert.IsTrue(alertboxDetail.Contains("Sorry, that page doesn't exist."), "Couldn't find the message \"Sorry, that page doesn't exist.\"");
}
This all works fine, however I would only like this test to run in the UAT environment. This is because the element ".alert.alert-danger" will only be found if customErrors is set to "Off". For this I have included this step in the test.
[Given(#"I am in the UAT environment")]
public void GivenIAmInTheUATEnvironment()
{
var env = EnvironmentType;
if (env != EnvironmentType.Uat)
{
Assert.Inconclusive($"Cannot run this test on environment: {env}. " +
$"This test is only for the UAT environment.");
}
else
{
Assert.IsTrue(true);
}
}
Again this works fine. My only problem is that I do not want to use "Assert.Inconclusive" I would rather "Assert.Pass" and say the test passed if it is carried out in a non-UAT environment.
I see XUnit has an Assert.Pass function, but can this be done in MsTest? To force a test to pass WITHOUT continuing to the next Assert. In specflow I am running the "given" step I would like to stop it from continuing to the "Then" step.
WRT NUnit, you can try Assert.Pass. I can't try it out myself right now as I'm traveling. My uncertainty is that I'm not sure if it will prevent the test from being run if you do it in the SetUp, which is what Given maps to.
My view is that accepting the behavior you looking for, all the code belongs in the test itself and not the Given. What Given would normally do would be to actually create the situation you expect, i.e. change the environment. That's obviously not possible here so I would simply put the environment check in the test itself. I wouldn't even use Assert.Pass unless you want a special message, I'd just skip the test code if the environment is wrong. As a side benefit, this approach works for all three test frameworks.
Although you didn't ask, I have to say that the instructions you have been given to show the test as passing even if it is not run seem pretty crazy to me!
I have a class initialize method that runs sets up an autofac.config amoung other dependencies in mstest. When I run the tests in the file individually they pass. however when I run the tests together I get the following error:
"The configuration file 'autofac.config' was not found and is not optional.":null`
var applicationPath = new Uri(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().CodeBase)).LocalPath;
var containerBuilder = new ContainerBuilder();
var msContainerBuilder = new Microsoft.Extensions.Configuration.ConfigurationBuilder();
msContainerBuilder.AddXmlFile(Path.Combine(applicationPath,"autofac.config"));
var msContainer = msContainerBuilder.Build();
var module = new Autofac.Configuration.ConfigurationModule(msContainer);
containerBuilder.RegisterModule(module);
I am completely lost as to what is causing this. Can anybody help solve this issue?
Edit:
Opening up the msContainerBuilder object gives the same information whether the tests are run individually or all at once.
I'm using FitNesse to do some testing with Fixtures written in C#. One of my fixtures kicks off some testing suites to run in Ab Initio in a Unix environment. I would like to be able to kill the whole test suite if one of the tests within it fail. I imagine I would need some kind of return value from the test suite (on the unix box) and then that would get passed back up to my fixture which would kill FitNesse (from within my C# fixture). This is what my KickOff() method looks like right now:
public string KickOff()
{
var data = new Dictionary<string, string>();
foreach (var row in System.IO.File.ReadAllLines(unixConfigFile))
data.Add(row.Split('=')[0], String.Join("=", row.Split('=').Skip(1).ToArray()));
string server = data["servername"];
string userId = data["username"];
string password = data["password"];
StringEncryptor3DES encryptor = new StringEncryptor3DES("fitnesse");
password = encryptor.Decrypt(password);
UnixScriptRunner runner = new UnixScriptRunner(server, userId, password, unixPath, scriptName,EtlType.AbInitio);
return runner.Run() & EtlStatus.IsEtlSuccessful(runner.LogFile,EtlType.AbInitio) ? "True":"False";
}
I think I need something that catches the value of EtlStatus.IsEtlSuccessful(), if it is false it will terminte FitNesse. The two questions I have are this:
Is this reasoning correct?
What is the code needed to terminite/kill FitNesse (or end the test suite if there is a more graceful way)?
Edit: I did a little more research and it looks like it is the 'runner' that I have to kill. Still not sure how to do this though...
If you're using Slim, you can throw an exception with "StopTest" in the class name to stop the test.
http://www.fitnesse.org/FitNesse.UserGuide.WritingAcceptanceTests.SliM.ExceptionHandling
If you're using Fit, you can throw an AbandonStoryTestExecption to stop the test.
http://fitsharp.github.io/Fit/AbandonStoryTest.html
There's a new Fit feature coming in the next release (any day now!) to throw AbandonTestSuiteException to stop the entire test suite. There's no comparable feature with Slim AFAIK.
I am using Firefox 28, Web Driver v2.41, and C#.
I have the following simple test (anyone can replicate. I have added the horrible wait to demonstrate that this is not an issue related to the page not being ready):
[TestMethod]
public void TestMethod1()
{
var FF = new FirefoxDriver();
FF.Navigate().GoToUrl(#"http://www.bing.com");
FF.FindElement(By.Id("sb_form_q")).SendKeys("Stack Overflow");
Thread.Sleep(5000);
FF.FindElement(By.Id("sb_form_go")).Click();
}
The test behaves as expected in machine A.
The test fails to perform the click on the last line in machine B (Lenovo W530). The click method is not working with ANY of my tests on this machine.
If I switch the .Click() for .SenKeys(Keys.Enter) then the problem is solved.