Key.ENTER on an input does not submit - karate

I'm trying out Karate and have a use case where I need to trigger a search in a search box and there is no button to trigger the search, so it needs to be triggered via the enter key.
I have tried multiple different flavours of trying to provide Key.ENTER to the input to get it to work but none of them triggers it.
I am using the latest binary with a very basic feature file (altered to use google rather than an internal app URL):
Feature: Trigger search with enter
Background:
* configure driver = { type: 'chrome'}
Scenario: Trigger Google search with enter
Given driver 'https://google.com'
# 1: Attempting to search with enter as an array argument
When input('input[name=q]', ['karate dsl', Key.ENTER])
# 2: Attempting to search with enter as a second command
#When input('input[name=q]', 'karate dsl')
#When input('input[name=q]', Key.ENTER)
# 3: Attempting to search using similar approach to 1 but with a submit
#When submit().input('input[name=q]', ['karate dsl', Key.ENTER])
Then waitFor('{h3}intuit/karate: Test Automation Made Simple - GitHub')
When using any of these approaches (by running ./karate <PATH_TO_ABOVE_FEATURE_FILE>) the search results page never loads so the result (the h3) can never be found...what am I doing wrong?

This is a bug for type chrome. It will actually work for type chromedriver.
Opened an issue: https://github.com/intuit/karate/issues/1192
For now please workaround by using a click on the appropriate button / control etc.

Related

Polarion: xUnitFileImport creates duplicate testcases instead of referencing existing ones

I have the xUnitFileImport scheduled job configured in my polarion project (as described in Polarion documentation) to import e2e test results (formatted to JUnit test results)
<job cronExpression="0 0/5 * * * ? *" id="xUnitFileImport" name="Import e2e Tests Results" scope="system">
<path>D:\myProject\data\import-test-results\e2e-gitlab</path>
<project>myProject</project>
<userAccountVaultKey>myKey</userAccountVaultKey>
<maxCreatedDefects>10</maxCreatedDefects>
<maxCreatedDefectsPercent>5</maxCreatedDefectsPercent>
<templateTestRunId>xUnit Build Test</templateTestRunId>
<idRegex>(.*).xml</idRegex>
<groupIdRegex>(.*)_.*.xml</groupIdRegex>
</job>
This works and I get my test results imported into a new test run and new test cases are created. But if I run the import job multiple times (for each test run) it creates duplicate test case work items even though they have the same name, which leads to this situation:
Is there some way to tell the import job to reference the existing testcases to the
newly created test run, instead of creating new ones?
What i have done so far:
yes I checked that the "custom field for test case id" in the "testing > configuration" is configured
yes I checked that the field value is really set in the created test case
The current value in this field is e.g. ".Login" as i don't want the classnames in the report.
YES I still get the same behaviour with the classname set
In the scheduler I have changed the job parameter for the group id because it wasn't filled. New value is: <groupIdRegex>e2e-results-(.*).xml</groupIdRegex>
I checked that no other custom fields are interfering, only the standard fields are set
I checked that no readonly fields are present
I do use a template for the testcases as supported by the xUnitFileImport. The testcases are successfully created and i don't see anything that would interfere
However I do have a hyperlink set in the template (I'll try removing this soon™)
I changed the test run template from "xUnit Build test" to "xUnit Manual Test Upload" this however did not lead to any visible change
I changed the template status from draft to active. Had no change in behaviour.
I tripple checked all the fields in the created test cases. They are literally the same, which leads to the conclusion that no fields in the testcases interfere with referencing to them
After all this time i have invested now, researching on my own and asking on different forums, I am ready to call this a polarion bug unless someone proves me this functionality is working.
I believe you have to set a custom field that identifies the testcase with the xUnit file you're importing, for the importer to identify the testcase.
Try adding a custom field to the TestCase workitem and selecting it here.
Custom Field for Test Case ID option in settings
If you're planning on creating test cases beforehand, note that the ID is formatted form the {classname}.{name} for a given case.

Is it possible to include the same few lines of scenario at the beginning of a new one?

I have a 138 tests long scenario that allows me to test if a workflow works as it should.
However, I'm not a huge fan of having to repeat the same 6 lines that allows me to log in as an administrator, which are:
Given I am on "user/login"
And I fill in "admin#admin.com" for "name"
And I fill in "admin" for "pass"
And I press "Log in"
Then I should get a "200" HTTP response
And I should see "Dashboard"
I repeat this part 6 times so far, and I'm planning on needing to add this a few more time for some other tests.
So my question is the following: is there a way, through the FeatureContext file or any other way, to make these lines repeat?
Thank you in advance
So this is how I did:
Instead of calling Gherkin sentence one after the other, I parsed the vendor/ directory to find examples of how sentences where made.
my function to that connects me looks like the following:
/**
* #throws ElementNotFoundException
* #throws Exception
* #Given I am the administrator
*/
public function iAmTheAdministrator(){
$this->visitPath('/user/login');
$element = $this->getSession()->getPage();
$element->fillField('name', 'admin#admin.com');
$element->fillField('pass', 'admin');
$element->pressButton("Se connecter");
$this->assertSession()->pageTextContains('Dashboard');
}
This is pretty straight forward, and works well
There are 2 ways I know of that repeats steps. One is with background steps and the other involves running snippets of steps.
Background steps run at the start of each scenario.
Background:
Given I have done this
And this other thing
Scenario: Do stuff
When I do this
Then stuff should happen
This only works if all tests have the same starting procedure...
Snippets run whenever you call them which I assume you would rather want
Given I have logged in as an administrator
Step definition:
Given(/^I have logged in as an administrator$/) do
steps %{
Given I am on "user/login"
And I fill in "admin#admin.com" for "name"
And I fill in "admin" for "pass"
And I press "Log in"
Then I should get a "200" HTTP response
And I should see "Dashboard"
}
end
This allows you to use only one step which you can call at any time to run multiple steps
Hope this helps.

Check if login was successful with Selenium

I'm just getting to grips with Selenium, and have made a simple log in script using the Firefox IDE.
What want to do now is check if the log in was successful.
The simplest way I could think of was to search for a piece of text that is only visible after log in i.e. Hi, [account name].
But I'm a little unsure on how to do this with Selenium.
Is there a way you can search for a term on a page and then act, upon its presence?
Also, is this the best way to check if your logged in?
1) Yes, I am checking for sucessful login by the way that I search for specific label. In my case that label contains ID of logged in user. Example:
<span id="username">PAVEL007</span>
So, when I log in:
driver.get("http://PAVEL007:OmgTooSecretToTellYou!#my-test-site.com");
Then I search for that label
WebElement loggedInUser = driver.findElement(By.id("username"));
And verify that I am in:
Assert.assertEquals(loggedInUser.getText(),"PAVEL007");
In nutshell:
If your website shows some specific text visible only after sucessful login, use that text
Best way is not to search for that text itself, but for element containing the text
NOTE
The driver variable is assumed healthy, living instance of WebDriver
My pseudo code is Java based
Get a url which can be accessed only after login.
url = "some url accessed only after login"
driver.navigate_to url
driver.current_url == url ? "logged_in" : "not_logged_in"
if not logged in it will be redirected to some other url. This is applicable in websites where url is not created dynamically
If you're using the IDE it should be a simple case of recording your login action and then where you have your Hi [username] element, right-click on it and then in the context menu you should see additional options that are from the IDE.
One of those should be verify text or assert text. Select that, when you then run your test case it will complete the login account and verify/assert that the Hi [username] text is on the page.
If you are using selenium IDE, it should very easy case, first of all you have to recording your login action and after login you have Hi [username] text is present on the screen, right-click on that text then select verifytext in the the context menu you should see additional options that are from the IDE.
One of those should be verify text or assert text. Select that, when you then run your test case it will complete the login account and verify/assert that the Hi [username] text is on the page
open | www.gmail.com
type | id=username |usrename
type | id=password |password
Verifytext | HI[Username]|
The obvious answer is the fluent method:
driver.getSource().contains("a string");
Personally, I prefer using cssLocator to locate values:
if ( driver.findElement(myElement).getText().equalsIgnoreCase("my value") ) //do
Verify successful login through assertion. This is my code you can verify
WebElement useremail = driver.findElement(By.xpath("//input[#placeholder='Email']"));
WebElement password = driver.findElement(By.xpath("//input[#placeholder='Password']"));
WebElement login = driver.findElement(By.xpath("//a[#class='btn-signin']"));
useremail.sendKeys("abc#mailinator.com"); password.sendKeys("XXX");
login.click(); String actualurl="url";
String expectedurl= driver.getCurrentUrl();
Assert.assertEquals(expectedurl,actualurl);
You can use WebDriverWait of selenium.webdriver.support.ui to wait for login.
from selenium import webdriver
from selenium.webdriver.support import ui
wait = ui.WebDriverWait(driver, 60)
wait.until(lambda driver: driver.find_elements_by_tag_name('fieldset')) # there is also a until_not do the not condition
# do something after the login, if not login after 60 there will throw timeout exception

Textbox Restrictions(Special chars/Numeric etc) not working for selenium automated test execution

I am testing a web application where certain text fields have restrictions based on requirements (eg.Amount textfield disallows alphabets and special characters & Name textfield disallows Numeric and special characters.), So while trying manually in a browser the restrictions work fine. But while automating the same testcase such textfields accept all data(eg. alphabets(lowercase and upper case),digits,special characters.)...Means in automation no restricton works at all..I am writing automated tests using Selenium in Eclipse(testNG framework) and using SeleniumRC to run tests.
I would suggest to use RegExps for verifying strings format.
e.g. my veryfying of build version format
#Test
public void buildVersionFormatVerify() throws IOException {
String buildVersion = findElementByCssSelector("home.buildversion.label").getText().trim();
String extractedVer;
extractedVer = buildVersion.substring(buildVersion.indexOf(':')+1,buildVersion.length()).trim();
Assert.assertTrue("build version does not match regexp",extractedVer.matches("\\d.\\d\\s.\\s\\d{2}"));
}
another approach can be the following:
you enter a certain string which does not satisfy input format accordingly to functional spec. Then you can trigger somhow that input was accepted (no error messages appears or validator has not handled inproper input) and you can block the 'accepted input' not following to functional spec with assert
e.g.
Assert.assertFalse("improper input format",isElementPresent(By.xpath(...xpath of the error message...)));
IMHO, it is my vision of solution to this issue.

Cucumber + Capybara tests to ensure a new window is opened

I have the following lines in my feature file:
Given I have website "www.google.co.uk"
When I click the website "www.google.co.uk"
Then "www.google.co.uk" page is opened in a new window
I am struggling to find a way to test that the webpage is definately opened in a new window.
Currently I have been using this in my step def:
Then /url "([^"]*)" is opened in new window/ do |url|
browser = page.driver.browser
current_id = browser.window_handle
tab_id = page.driver.find_window(url)
browser.switch_to.window tab_id
page.driver.browser.close
browser.switch_to.window current_id
end
but this still passes the test if the webpage is loaded on the same page, I want it to fail if the webpage is loaded on the same window/tab.
Any suggestions?
Many thanks
I see no assertions in your test.
My approach would be to test size of window_handles array after performing clicking action on the link, since before clicking the size should equal 1 and after the clicking window_handles should equal 2.
assert page.driver.browser.window_handles.size == 2
Imho, good enough, since if the webpage is loaded in the same tab, the size will be 1 and the test will fail.