I'm using Selenium WebDriver in .NET environment. I'm using WebDriver inside NUnit test runner like that:
[Test]
public static void Should_register_user()
{
IWebDriver driver = new FirefoxDriver();
...
driver.Quit();
}
It works quite fine. If I run this test from MSBuild script like that: packages\NUnit.Runners.2.6.2\Tools\nunit-console.exe /nologo S022.SeleniumTests.dll /xml=NUnit.Report.xml (no matter if I'm using NUnit community task or exec task).
The test performs but it it fails the Firefox browser remains opened and the execution in script waits for me to close the browser window. When I do that the script executes further.
Here it is what Selenium says:
ProcessModel: Default DomainUsage: Single
Execution Runtime: net-3.5
.F
Tests run: 1, Errors: 0, Failures: 1, Inconclusive: 0, Time: 10,3118323 secon
ds
Not run: 0, Invalid: 0, Ignored: 0, Skipped: 0
Errors and Failures:
1) Test Failure : S022.SeleniumTests.RegistrationTests.Should_register
_user
Expected string length 6 but was 11. Strings differ at index 0.
Expected: "Log-in"
But was: "News"
-----------^
at S022.SeleniumTests.RegistrationTests.Should_register_user() in S022.SeleniumTests\T
ests\RegistrationTests.cs:line 22
If the test passes the execution goes along as expected.
What am I doing wrong?
You're creating and destroying the browser instance within the [Test] method. When the test case fails, an exception is thrown, and your call to driver.Quit() is never getting executed. You probably want to create the driver instance in the [SetUp] method, and call driver.Quit() in the [TearDown] method.
Related
Exception while taking screenshot Cannot invoke method getScreenshotAs() on null object
Tests run: 2, Failures: 2, Errors: 0, Skipped: 0, Time elapsed: 0.907 sec <<< FAILURE! -
java.lang.IllegalStateException: The driver executable does not exist:/src/***/Chrome_Drivers/chromedriver_win32/chromedriver.exe
While running the selenium jobs in Jenkins, how should we specify the chrome driver path?
I am trying to run the code in windows and the same code is running fine in my local however when I try to run the same code with Jenkins(code in bitbucket) it does not find the path.
I tried adding bitbucket URL in the System.setProperty("webdriver.chrome.driver", "https://bitbucket.org///src/***/config/chromedriver.exe");
but nothing works.
Please help.
I'm trying to run a basic TestNG class, but I'm getting this exception Exception in thread "main" com.beust.jcommander.ParameterException: Was passed main parameter '-d' but no main parameter was defined in your arg class
If I give main() and try with run as a java application, it's launching the browser fine. But when I run as TestNG, it's throwing Exception. I tried adding jcommander.jar manually and even tried with update maven project.
#Test
public void checking()
{
System.setProperty("webdriver.chrome.driver", "./driver/chromedriver");
ChromeDriver driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get("https://www.google.com");
}
}
I expect the browser has to launch and load google.com, but I'm getting Exception in thread "main" com.beust.jcommander.ParameterException: Was passed main parameter '-d' but no main parameter was defined in your arg class
at com.beust.jcommander.JCommander.initMainParameterValue(JCommander.java:936)
at com.beust.jcommander.JCommander.parseValues(JCommander.java:752)
at com.beust.jcommander.JCommander.parse(JCommander.java:340)
at com.beust.jcommander.JCommander.parse(JCommander.java:319)
at com.beust.jcommander.JCommander.<init>(JCommander.java:253)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:44)
check whether testng installed successfully and jars have been added properly in maven
The scenario is:
I have serenity tests that i launch with chromedriver that work
When i launch the tests without headless option the tests are "passed"
while with the headless mode the tests are failed with error:
net.serenitybdd.core.exceptions.SerenityManagedException: The following error occurred: Timed out after 5 seconds. Element not available
here the line command that launch the test : mvn clean verify -Dwebdriver.driver=chrome
And the serenity.properties:
webdriver.chrome.driver = chromedriver
webdriver.base.url= ********
webdriver.timeouts.implicitlywait=5000
chrome.switches=--headless;
serenity.browser.maximized = true
The solution is to add in chrome.switches --window-size=1920,1080;
chrome.switches=--window-size=1920,1080;--headless;
Why am I not getting an error when I use PHPUnit + Selenium Server to log in with an email and password that doesn't exists?
This is the PHPUnit script.
public function testUserNotExists() {
$this->open('https://dev.example.com/login');
$this->type("id=email", "1d0ntex1s7#live.com");
$this->type("id=password", "1d0n73x1s7");
$this->click("name=login_user");
}
When I run it, it doesn't show an error
Terminal: phpunit ExampleTest.php
PHPUnit 3.6.12 by Sebastian Bergmann.
E...
Time: 29 seconds, Memory: 4.75Mb
There was 1 error:
1) ExampleTest::testTitle
Method assertTitleEquals not defined.
FAILURES!
Tests: 4, Assertions: 1, Errors: 1.
You have to write assertions to get some failure. Selenium doesn't know what should (or shouldn't) happen after sending some form.
Followed this post -
Selenium - Could not start Selenium session: Failed to start new browser session: Error while launching browser
Error comes up at selenium.start().
I am using selenium rc(2.16) , junit(4.5) in eclipse ide.
The only way to over come this issue is to redeploy our framework in tomcat server, just restart everything.
This is the piece of code that starts selenium
private static HttpCommandProcessor proc;
public static DefaultSelenium selenium;
if (selenium == null) {
proc = new HttpCommandProcessor("localhost", 4444, browserName,
urlName);
selenium = new DefaultSelenium(proc);
**selenium.start();**
selenium.setTimeout(String.valueOf(PAGE_TIMEOUT_TIME));
selenium.useXpathLibrary("javascript-xpath");
selenium.deleteAllVisibleCookies();
}
the selenium server is already started when the execution reaches the above code.
Below is the exception that comes up when execute the tests -
java.lang.RuntimeException: Could not start Selenium session: Failed to start new browser session: Error while launching browser
at com.thoughtworks.selenium.DefaultSelenium.start(DefaultSelenium.java:107)
at <package>.SuperClass.connectToUrl(SuperClass.java:340)
Any help or clue to resolve this thing would be appreciated!