Pa11y actions reference / documentation - pa11y

How do you enter values to match a name="" attribute, or class=""? I'm guessing that # is referring to id="" only? If HTML ID attributes are not available there needs to be a way to match other attributes or the element itself.
Is there a reference for how to use actions?
actions: [
'set field #login_field to abc',
'set field #password to defghi',
'click element #password"',
'wait for url to be http://github.com'
],

From the documentation that you linked (emphasis mine):
This allows you to click an element by passing in a CSS selector. This action takes the form click element .
[...]
You can use any valid query selector, including classes and types.
You should be able to use any valid CSS selector, including IDs, classes, and more complex CSS selectors. For example, to click on an element with class="myClass" you could use:
{
"actions": [
"click element .myClass",
"wait for path to be /foo"
]
}
Running pa11y using the --debug flag should help you understand if the actions are working correctly. For an example like the one above you should be able to see an output similar to this:
Welcome to Pa11y
> Running Pa11y on URL https://www.example.com/
[...]
> Running actions
> Debug: Running action: click element .myClass
> Debug: ✔︎ Action complete: click-element
> Debug: Running action: wait for path to be /foo
> Debug: ✔︎ Action complete: wait-for-url
> Finished running actions
[...]
> Debug: Document title: "Foo"
No issues found!

I found the actions reference, although the documentation is very limited for this project. Selectors seem limited to IDs as far as I can tell, not much good if there aren't any. I was hoping for Selenium-type selectors inc Xpath.
Pa11y Documentation - Actions

Related

Key.ENTER on an input does not submit

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.

Issues with video path

TestCafe doesn't recognize ${TEST} for video path.
I'm trying to implement test recording for failed tests in order to see how we could replicate the appeared problem, but the video path isn't recognized even though a similar path pattern works for screenshots.
According to the documentation, this should work but the following warning is displayed:
Warnings (1):
The "${TEST}" path pattern placeholder cannot be applied to the recorded video.
The placeholder was replaced with an empty string.
I created TestRunner.js as shown in https://devexpress.github.io/testcafe/documentation/using-testcafe/programming-interface/runner.html. Then I added
if(runnerOptions.takeVideo === true && runInParallel === 1) {
runner.video(reports.videoPath, {
singleFile: true,
failedOnly: true,
pathPattern: store + '-' + env + '/${TEST}/${DATE}_${TIME}/${USERAGENT}'
})
}
return runner
.src(tests)
.browsers(config.browsers)
.screenshots(reports.screenshotPath, runnerOptions.takeScreenshots,
store + '-' + env + '/${TEST}/${DATE}_${TIME}/${RUN_ID}/${USERAGENT}/step-${FILE_INDEX}')
.concurrency(runInParallel)
.run(runnerOptions.run);
As I said screenshots work fine, but videos don't.
According to this GitHub issue, specifying singleFile: true is the cause. When saving all the failed tests into one recording, the path pattern can't use a single test or fixture identifier to name the file.
The following pattern placeholders resolve to an empty string with a single file:
${TEST_ID}
${TEST_INDEX}
${FIXTURE}
${TEST}
${TEST_ID}
The documentation for the path patterns does mention this restriction for single files, but only in reference to ${TEST_ID} and not the other placeholders.
I've checked the scenario and it works without any "path pattern" issues under Windows 10:
testcafe chrome test.js --video artifacts/videos --video-options pathPattern=${TEST}.mp4
Would you please clarify how you specified the pathPattern video option? In addition, please provide your environment details.

How to resolve "Using 'Get Element Attribute' without explicit attribute is deprecated" in robot framework using selenium library

This works and returns exactly what I want:
*** Variables ***
${HOME_LOGO}= css=#header > nav > div.header-gutter > div > img
*** Keywords ***
Home logo is visible
Element Should Be Visible ${HOME_LOGO}
${logo_src}= Get Element Attribute ${HOME_LOGO}#src
log ${logo_src}
However, I am getting a WARN when I run it: Using 'Get Element Attribute' without explicit attribute is deprecated
I have tried several approaches, but have not been able to resolve the warn message AND get the information I want into ${logo_src}. I am looking for the img src.
What is the best way to either handle the warn or get the img src from the element in the xpath?
Thank you - I'm very new to robot framework and selenium but not new to test automation. Also new to stackoverflow.
They have changed how this keyword works from when it was originally designed. Instead of appending the attribute to the locator, provide it as an argument:
${logo_src}= Get Element Attribute ${HOME_LOGO} src
(note: there needs to be two or more spaces before src)

Codeception function to seeOrWaitForElement

I've got an application which I want to test with selenium/codeception. It has a lot of ajax function which changes the pages (show/hide sections of the page) which codeception at the moment doesn't handle well.
The problem I am having is I want to click on buttons/elements which either
are already on the page (ajax calls finished early)
which are not yet on the page (waiting for ajax response)
If I use waitForElement() it only seems to works in the second case (it waits for the element to appear and continues) but if the element is already present waitForElement will timeout and fire an Fail.
What I am looking for is a seeOrWaitForElement() function but I can't figure out how to insert logic in codeception.
Is this function available somewhere or how can I solve this problem in another way?
You could use
waitForJs("return document.querySelector('".$element."') != null", $seconds);
which will wait until the element exists (and returns instantly if the element already is present).
Codeception introduced a feature called SmartWait in version 2.3.4 which seems like an elegant solution to your problem. Note that it does not work for all kind of locators.
From the Codeception documentation:
SmartWait
since 2.3.4 version
It is possible to wait for elements pragmatically. If a test uses element which is not on a page yet, Codeception will wait for few extra seconds before failing. This feature is based on Implicit Wait of Selenium. Codeception enables implicit wait only when searching for a specific element and disables in all other cases. Thus, the performance of a test is not affected.
SmartWait can be enabled by setting wait option in WebDriver config. It expects the number of seconds to wait. Example:
wait: 5
With this config we have the following test:
<?php
// we use wait: 5 instead of
// $I->waitForElement(['css' => '#click-me'], 5);
// to wait for element on page
$I->click(['css' => '#click-me']);
It is important to understand that SmartWait works only with a specific locators:
#locator - CSS ID locator, works
//locator - general XPath locator, works
['css' => 'button''] - strict locator, works
But it won’t be executed for all other locator types. See the example:
<?php
$I->click('Login'); // DISABLED, not a specific locator
$I->fillField('user', 'davert'); // DISABLED, not a specific locator
$I->fillField(['name' => 'password'], '123456'); // ENABLED, strict locator
$I->click('#login'); // ENABLED, locator is CSS ID
$I->see('Hello, Davert'); // DISABLED, Not a locator
$I->seeElement('#userbar'); // ENABLED
$I->dontSeeElement('#login'); // DISABLED, can't wait for element to hide
$I->seeNumberOfElements(['css' => 'button.link'], 5); // DISABLED, can wait only for one element
I used waitForJS from the docs and it worked. Example:
$I->see('Jane Doe', '#table tbody tr');
$I->click(['css' => '#reload-ajax']); // Ajax trigger here
$I->waitForJS("return $.active == 0;", 60);
$I->see('John Doe', '#table tbody tr');

Running a GEB test using Intellij

Being a beginner in GEB testing, I am trying to run a simple login program in Intellij. Could you please help me run this test in Intellij? My question is what selections should I make in the edit configurations page? Please help. This example is from the book of geb.
import geb.Browser
Browser.drive {
go "http://google.com/ncr"
// make sure we actually got to the page
assert title == "Google"
// enter wikipedia into the search field
$("input", name: "q").value("wikipedia")
// wait for the change to results page to happen
// (google updates the page dynamically without a new request)
waitFor { title.endsWith("Google Search") }
// is the first link to wikipedia?
def firstLink = $("li.g", 0).find("a.l")
assert firstLink.text() == "Wikipedia"
// click the link
firstLink.click()
// wait for Google's javascript to redirect to Wikipedia
waitFor { title == "Wikipedia" }
}
If you are running this in IntelliJ you should be able to run this as a JUnit test (ctrl+F10). Make sure that this is inside of a Class and in a method.
For ease of syntax, it would be good to use Spock as your BDD framework (include the library in your project; if using Maven, follow the guide on the site but update to Spock 0.7-groovy-2.0 and Geb 0.9.0-RC-1 for the latest libraries
If you want to switch from straight JUnit to Spock (keep in mind you should use JUnit as a silent library) then your test case looks like this:
def "show off the awesomeness of google"() {
given:
go "http://google.com/ncr"
expect: "make sure we actually got to the page"
title == "Google"
when: "enter wikipedia into the search field"
$("input", name: "q").value("wikipedia")
then: "wait for the change to results page to happen and (google updates the page dynamically without a new request)"
waitFor { title.endsWith("Google Search") }
// is the first link to wikipedia?
def firstLink = $("li.g", 0).find("a.l")
and:
firstLink.text() == "Wikipedia"
when: "click the link"
firstLink.click()
then: "wait for Google's javascript to redirect to Wikipedia"
waitFor { title == "Wikipedia" }
}
Just remember: Ctrl + F10 (best key shorcut for a test in IntelliJ!)
The above is close but no cigar, so to speak.
If you want to run bulk standard Gebish test from WITHIN Intellij,
I tried 2 things.
I added my geckodriver.exe to the test/resources under my Spock/Geb tests
I literally in the given: part of my Spok/Geb test did the following:
given:
System.setProperty("webdriver.gecko.driver", "C:\\repo\\geb-example-gradle\\src\\test\\resources" + "\\geckodriver.exe");
Failed
Succeeded
Now the usual deal with answers is, that someone writes something, you try it and then it fails.
So, if it did not work for you, use the reference Geb/Spock project on Github as follows and import it into intellij (remember, New Project, then find the gradle.build script and then intellij will import it nicely)...it also kicks off a build so dont freak out:
https://github.com/geb/geb-example-gradle
Download the driver:
https://github.com/mozilla/geckodriver/releases
and move it to the test/resource folder of the reference project you just imported under test/groovy...(see image)
Now add the above given: clause to the GebishOrgSpec Sock/Geb test:
The test runs nicely from WITHIN Intellij. Evidence the browser open and the test running:
LOVELY JOBBLY :=)