Getting error in selenium test cases - selenium

I'm running somebody written selenium test cases in my system.It showing the few errors like
> [error] Actual value 'null' did not match '[object Object]'
> [error] Threw an exception: this.browserbot.getUserWindow().map is undefined
> [error] Threw an exception: this.browserbot.getUserWindow().map is undefined
Is it the problem with selenium ide version which I'm using or other? I'm using Selenium 1.6.0

This issue is coming because you are trying to get hold of a window , which is not matching to the value you are passing.
So for this you need to investigate more on your locators. Also you can start using a new tool which can find automatically the locators for you , which is Selenium Builder. Hope following links will help you.
http://khyatisehgal.wordpress.com/2014/05/26/selenium-builder-exporting-and-execution/
http://khyatisehgal.wordpress.com/2014/05/25/selenium-builder/

Those errors you're getting are not because of Selenium version, but because the logic of your application changed and the tests expect different results from various actions.
The only thing you can do is to go through your tests, discover what were they trying to assert / achieve / test (you do have your testcases documented, right?) and if their current behaviour is wrong, fix them.
The other possibility is that your tests are ok, just the application began to behave differently (against the spec) and needs to be fixed. But from the context, I'd say that your unmaintained tests broke.

Related

Getting the error while trying to run the code for selenium/selenide script to execute script on browserstack

Error description -
java.lang.IllegalArgumentException: The class org.openqa.selenium.remote.RemoteWebDriver of the given context doesn't implement io.appium.java_client.FindsByIosNSPredicate nor io.appium.java_client.FindsByFluentSelector. Sorry. It is impossible to find something
Please help me if someone have any idea about it.
will add more details, if someone wants.
Looks like the element locator strategy FindsByIosNSPredicate and FindsByFluentSelector is not being captured by the default appium version. Can you try explicitly mentioning the appium version capability and pass the same as passed while executing your tests locally on a real device. You may refer to this: https://www.browserstack.com/automate/capabilities or https://www.browserstack.com/app-automate/capabilities ( for App )

Selenium WebDriverException missing ) after argument list

js.executeScript("document.querySelector('input[name='password']');");
This line is throwing the following Exception in thread:
"main" org.openqa.selenium.WebDriverException: missing ) after argument list
Try the following code.
js.executeScript("document.querySelector('input[name=\'password\']')");
Try
js.executeScript("document.querySelector('input[name='password']')");
Let me know if this Answers your Question.
You can try one of the following
js.executeScript("document.querySelector(\'input[name=\'password\']\');");
js.executeScript("document.querySelector(\"input[name='password']\");");
Although in your comments you added this line
js.executeScript("document.querySelector('input[name=\'pas‌​‌​sword\']').value='ga‌​‌​mb'");
Which wouldn't work because if you look at .value you'll need to escape your .value setting as well more than likely.
Given that I don't have access to your site or your code, I would suggest that you test to make sure your javascript is valid for your page. One way to do so would be to take the javascript itself (everything insdie the .executeScript) and run it through your browsers dev tools console or script execution window.
If the value sets using the browsers dev tools, great...issue is with selenium. If the value does not set using browser dev tools...you'll need to refactor your javascript as the problem is likely not with selenium, rather your JS selector more than likely.
Although, the following, from your comment, works...you may not need to execute it via javascript.
driver.findElement(By.cssSelector("input[name='password']"‌​‌​)).sendKeys("gamb"‌​);

Error running multiple tests in Specflow/Selenium

I have an existing project that uses Specflow and SpecRun to run some tests against Sauce Labs. I have a BeforeSenario hook that creates a RemoteWebDriver and an AfterScenario hook that closes this down.
I've now moved this into another project (copied the files over, just changed the namespace) and the first test runs fine but then get the following error:
An exception of type 'OpenQA.Selenium.WebDriverException' occurred in WebDriver.dll but was not handled in user code
Additional information: Unexpected error. The command you just sent (POST element) has no session ID.
This is generally caused by testing frameworks trying to run commands after the conclusion of a test.
For example, you may be trying to capture a screenshot or retrieve server logs
after selenium.stop() or driver.quit() was called in a tearDown method.
Please make sure this process happens before the session is ended.
I've compared the project and it's using the same version of SpecFlow, same .Net version. I can't see any difference between the two projects.
In my steps I have the following line:
public static IWebDriver driver = (IWebDriver)ScenarioContext.Current["driver"];
which I think is the issue as instead of getting a new instance of it from the ScenarioContext it's using the previous test's version which has now been disposed.
But I can't see why this is working in another project instead?
I am using the Specflow example in Github here
UPDATE
Looks like I've found the issue. In the Default.srprofile the testThreadCount was 1 whereas the value in the working solution was 10. I've now updated this to match and it works.
Not sure what this value should be though. I assume it shouldn't be the same number of tests, but then how do I get around my original issue of the shared driver context?
TestThreadCount specifics the number of threads used by SpecFlow+Runner (aka SpecRun) to execute the tests.
Each of the threads are separated. The default is AppDomain isolation, so every thread runs in a separate AppDomain.
In the SauceLab example there are 7 scenarios and the runner is configured to use 10 threads. This means, every scenario is executed in a different thread with its own AppDomain. As no thread executes a second scenario, you get this error not in the example
With only one thread, your thread is executing more than one scenario and you get this issue.
Easiest fix would be, if you remove the static from the field. For every scenario you get a new instance of the binding class. You do not have to remember it static.
For a better example how to use Selenium with SpecFlow & SpecFlow+ have a look here: https://github.com/techtalk/SpecFlow.Plus.Examples/tree/master/SeleniumWebTest
You have to adjust the WebDriver- class for using SauceLabs over the RemoteWebDriver.

Selenium RC - t.replace is not a function

[edit for godman] I am working on a web based application, written in PHP. I am using Selenium RC to run tests on the webpages produced by this application, through a browser.
I just upgraded to Firefox 14, so I had to upgrade to Selenium RC 2.25.0.
Now I'm seeing this error when running a test with htmlSuite:
Command execution failure. Please search the user group at
https://groups.google.com/forum/#!forum/selenium-users for error
details from the log window. The error message is: t.replace is not a
function
The command executed is:
clickAndWait //a[text()='! selenium test customer']
As you can see, it's not doing anything too tricky - just clicking a link. The test runs fine in the IDE, it's just when run via RC that it's a problem.
Searching in the groups revealed only really old threads dating back to version 1 of selenium.
Any ideas anyone?
[edit] I've been running the test that has these problems several times a day for the last week - and it doesn't seem to fail like this every time. This looks like it's a random problem. Has anyone seen this happen before?
[edit after the bounty got me no answers] Another example of it failing is with:
clickAndWait css=a.edit_company
This same call works fine earlier in the same test, on the same page.
[edit] Now I'm seeing the same error with a completely separate command:
type id=Address1 Address1
Does anyone have any suggestions about this? Any way I can even debug what's going on (I don't see this in the IDE at all)
I am not terribly familiar with clickAndWait. I personally prefer clicking and then doing my own custom waiting.
Try just clicking and add a Thread.Sleep(5000), or something similar, and see if the error is a result of the click or the wait part.
If it is the wait part, then I have a different suggestion than if it is the click part.
I've seen similar issues across various platforms. It has always been somewhat random for me, so I don't use clickandWait. Generally is is much more reliable to do a plain click, and then wait for specific condition. You could do a waitforpageload, but that has also been unreliable for me so I prefer things like waitfortextpresent and waitforelementpresent.
Usually, this kind of error would occur if you are dealing with something that is not a string. Could you just make sure that you are dealing with strings only?
2 possibilities where it is arising from:-
When text() is executed -> it might be dealing with a non-string
a[expression] -> the expression(text() = '! selenium test customer') when evaluated to False/True might be the problem because if a is a Map/array, the corresponding key should be a string and not a bool, probably.
text()='! selenium test customer' -->> is it an assignment operation? if yes, make sure that text() returns a lvalue or a mutable object (based on the language you are using selenium rc with)

Create screenshot after failed selenium command

The PHPUnit Selenium base class has an option to make a screenshot on failure, which is a huge help in finding out why the test failed. The selenium server, however, returns an error instead of a failure on any error condition other than explicit assert* calls (such us trying to do something with a non-existent element). If I try to make a screenshot after the server reports the error, I get another error saying that the server already discarded the session. Is there any way to change that behavior?
Update: this is because PHPUnit breaks the connection when it receives an error. I was able to change it by some (rather ugly) manipulation of the PHPUnit code.
Make those interactions as test cases.
For example in perl,
If it is written as below and fails due to a non-existent element. the script will error out
$sel->type("email-id","trial\#trial.com");
While if the above step is made as a test case by writing it as follows
$sel->type_ok("email-id","trial\#trial.com");
If there is a non-existent element, the test case will only fail, and the script will continue.
So using TAP (test any protocol) by using the module use Test::More; , if _ok is added after a function, the function return will be used to determine the fate of the test case.
ie. - A return of 'O' means the test Failed
and A return of '1' means the test Passed
It is not the Selenium server but the SeleniumTestCase class for PHPUnit 3.4 which automatically sends a stop command when it detects an error (Driver.php line 921). PHPUnit 3.6 seems handle errors better.
I think you can overwrite method 'travelbox' and make something like this:
public function onNotSuccessfulTest(Exception $e){
file_put_content('/xxx/xxx.jpg', $this->currentScreenshot());
}