Summary| Tags| Feature: src/test/java/driver/00.feature|
Scenario: [1:9]
ms: 19608
>>
Background:
4
* driver serverUrl + '/00'
4539
09:36:37.285 using driver: playwright 09:36:37.297 Installing Playwright browsers (this may take some time)... 09:36:41.466 Using native PlaywrightDriver
5
* def dimensions = karate.get('dimensions')
14
6
* if (dimensions) driver.dimensions = dimensions
2
7
* def skipSlowTests = karate.properties['skip.slow.tests']
2
# driver.send() (has to be first)
# * if (driverType == 'chrome') karate.call('12.feature')
# driver.url | driver.title | waitForUrl() | refresh() | back() | forward() | driver.dimensions
# * call read('01.feature')
# waitFor() | waitForText() | waitForEnabled()
17
* call read('02.feature')
2442
>>
src.test.java.driver.02
2396
4
* driver serverUrl + '/02'
24
# wait for slow loading element
8
* waitFor('#slowDiv')
2359
# this is a string "contains" match for convenience
11
* waitForText('#slowDiv', 'APPEARED')
9
# how to search the whole html
14
* waitForText('body', 'APPEARED')
4
# will be false if disabled
17
* waitForEnabled('#slowDiv')
1
# script() | waitUntil()
20
* call read('03.feature')
2104
>>
src.test.java.driver.03
2088
4
* driver serverUrl + '/03'
22
# different ways to use waitUntil()
8
* waitUntil('#helloDiv', "function(e){ return e.innerHTML == 'hello world' }")
2011
9
* waitUntil('#helloDiv', "_.innerHTML == 'hello world'")
10
10
* waitUntil('#helloDiv', '!_.disabled')
4
# different ways to use script()
13
* match script('#helloDiv', "function(e){ return e.innerHTML }") == 'hello world'
14
14
* match script('#helloDiv', '_.innerHTML') == 'hello world'
4
15
* match script('#helloDiv', '!_.disabled') == true
5
16
* match script('#helloDiv', "_.style['color']") == 'red'
4
17
* match script('.styled-div', "function(e){ return getComputedStyle(e)['font-size'] }") == '30px'
5
18
* match script('.styled-div', "_ => getComputedStyle(_)['font-size']") == '30px'
4
# Regression test for https://github.com/karatelabs/karate/issues/1786
# Tests that Karate can handle console logging -- we can't assert it is working, but we can check that it doesn't crash devtools connection
# Expect Karate to log "[console] testing"
23
* script("console.log('testing')")
3
# Expect Karate to log "[console] true"
26
* script("console.log(true)")
2
# Expect Karate to log "[console] 1"
29
* script("console.log(1)")
1
# cookies
23
* if (driverType != 'safaridriver' && driverType != 'playwright') karate.call('04.feature')
2
# driver.intercept
26
* if (driverType == 'chrome' || driverType == 'playwright') karate.call('05.feature')
343
>>
src.test.java.driver.05
333
4
* driver serverUrl + '/05'
22
7
* url serverUrl + '/api/05'
1
8
* method get
181
09:36:46.569 request: 1 > GET http://localhost:58779/api/05 1 > Host: localhost:58779 1 > Connection: Keep-Alive 1 > User-Agent: Apache-HttpClient/4.5.14 (Java/21.0.2) 1 > Accept-Encoding: gzip,deflate 09:36:46.610 response time in milliseconds: 40 1 < 200 1 < set-cookie: karate.sid=2-1712237806581; Secure; HTTPOnly 1 < content-type: application/json 1 < content-length: 25 1 < server: Armeria/1.27.0 1 < date: Thu, 4 Apr 2024 13:36:46 GMT 1 < Set-Cookie: karate.sid=2-1712237806581; Secure; HTTPOnly {"message":"hello world"}
9
* match response == { message: 'hello world' }
8
11
* click('button')
58
12
* waitForText('#containerDiv', 'hello world')
3
14
* def mock = driver.intercept({ patterns: [{ urlPattern: '*/api/*' }], mock: '05_mock.feature' })
16
16
* click('button')
40
17
* waitForText('#containerDiv', 'hello faked')
3
19
* def requests = mock.get('savedRequests')
1
20
* match requests == [{ path: '/api/05', params: { foo: ['bar'] } }]
1
# position()
29
* call read('06.feature')
60
>>
src.test.java.driver.06
52
4
* driver serverUrl + '/06'
25
7
* def loc1 = position('#first')
20
8
* match loc1 contains { x: '#number', y: '#number', width: '#number', height: '#number' }
0
9
* def loc2 = position('#second')
4
10
* match loc1.y == loc2.y
1
11
* match loc1.width == 102
0
12
* match loc1.width == loc2.width
0
# input() | value() | text() | html()
32
* call read('07.feature')
189
>>
src.test.java.driver.07
180
4
* driver serverUrl + '/07'
38
7
* input('#inputId', 'hello world')
29
8
* click('input[name=submitName]')
30
9
* match value('#inputId') == 'hello world'
4
10
* match text('#valueId') == 'hello world'
3
11
* match html('#valueId') == '<div id="valueId">hello world</div>'
10
12
* def expected = '72d72u69d69u76d76u76d76u79d79u32d32u87d87u79d79u82d82u76d76u68d68u'
0
13
* if (driverType == 'chrome') expected = '104d104u101d101u108d108u108d108u111d111u32d32u119d119u111d111u114d114u108d108u100d100u'
0
14
* if (driverType == 'safaridriver') expected = '72d72u69d69u76d76u76d76u79d79u65d65u87d87u79d79u82d82u76d76u68d68u'
0
15
* match text('#pressedId') == expected
2
17
* clear('#inputId')
13
18
* waitFor('#inputId').input('hello world')
16
19
* waitFor('input[name=submitName]').click()
29
20
* match value('#inputId') == 'hello world'
1
21
* match text('#valueId') == 'hello world'
1
22
* match html('#valueId') == '<div id="valueId">hello world</div>'
3
# switchFrame()
35
* call read('08.feature')
566
>>
src.test.java.driver.08
525
4
* driver serverUrl + '/08'
77
7
* match text('#messageId') == 'this div is outside the iframe'
18
8
* switchFrame('#frameId')
3
9
* input('#inputId', 'hello world')
17
10
* click('input[name=submitName]')
48
11
* match value('#inputId') == 'hello world'
3
12
* match text('#valueId') == 'hello world'
3
# switch back to parent frame
15
* switchFrame(-1)
2
16
* match text('#messageId') == 'this div is outside the iframe'
1
4
* driver serverUrl + '/08'
64
19
* match text('#messageId') == 'this div is outside the iframe'
12
20
* switchFrame(0)
1
21
* input('#inputId', 'hello world')
18
22
* click('input[name=submitName]')
35
23
* match value('#inputId') == 'hello world'
2
24
* match text('#valueId') == 'hello world'
2
# switch back to parent frame
27
* switchFrame(-1)
0
28
* match text('#messageId') == 'this div is outside the iframe'
2
4
* driver serverUrl + '/08'
54
#* if (driverType != 'chrome') karate.abort()
32
* switchFrame('#uploadFrameId')
1
33
* driver.inputFile('#fileToUpload', '08.pdf')
31
34
* click('#uploadButton')
39
35
* waitForText('#uploadMessage', '08.pdf')
94
# wildcard locators
38
* call read('09.feature')
59
>>
src.test.java.driver.09
53
4
* driver serverUrl + '/09'
26
7
* switchFrame(-1)
1
8
* def parent = waitFor('.div-02')
13
# make sure the find-by-text works relative to search node and not from document root
10
* def found = parent.locate('{}Some Text')
5
11
* match found.attribute('class') == 'div-04'
3
# find all, exact match
14
* def list1 = locateAll('{}Some Text')
1
15
* assert list1.length == 2
0
# find all, contains match
18
* def list2 = locateAll('{^}Text')
1
19
* assert list2.length == 2
0
# works with exists too
22
* match exists('{}Some Text') == true
2
# element position
41
* call read('10.feature')
112
>>
src.test.java.driver.10
106
4
* driver serverUrl + '/10'
20
7
* waitFor('{}this test verifies an element can be located even when the page needs scrolling')
12
8
* scroll('{}Label without scroll :').input('it works')
38
# TODO rightOf() not working only on firefox (is apple m1 the reason ?)
11
* if (driverType == 'geckodriver') karate.abort()
0
12
* scroll('{}Label with scroll :').rightOf().input('it should not fail')
36
# switchPage()
44
* if ((driverType == 'chrome' || driverType == 'playwright') && !skipSlowTests) karate.call('11.feature')
211
>>
src.test.java.driver.11
206
4
* driver serverUrl + '/11'
24
7
* click("#helloDiv")
73
8
* switchPage('/11_tab')
32
9
* waitForUrl('/11_tab')
3
10
* match text('#content') == 'Page 11 Tab'
75
# switchPage() with external URLs
47
* if (driverType == 'playwright' && !skipSlowTests) karate.call('13.feature')
859
>>
src.test.java.driver.13
850
4
* driver serverUrl + '/13'
589
7
* match text("div#messageId") == "this div is outside the iframe"
10
8
* waitFor("#myiframe")
3
9
* switchFrame("#myiframe")
1
## matching Wikipedia page title
## hopefully won't change often :)
12
* match driver.title == "Office Space - Wikipedia"
92
# * click('#p-search a')
# * input('body', 'karate' + Key.ENTER)
# * waitFor('a[title=Karate]').click()
# * waitForUrl('https://en.wikipedia.org/wiki/Karate')
# * match driver.title == "Karate - Wikipedia"
18
* switchFrame(null)
1
# trying the same thing with locate chained by switchFrame()
20
* locate("iframe[id='myiframe']").switchFrame()
3
21
* switchFrame(null)
0
22
* switchFrame("#frameId")
1
23
* input("input#inputId", "testing input")
23
24
* click("input#submitId")
38
25
* match text("div#valueId") == "testing input"
4
26
* match optional("div#messageId").present == false
5
27
* switchFrame(null)
0
28
* match text("div#messageId") == "this div is outside the iframe"
2
# maybe fix also solves for #1715
31
* switchFrame("#iframe08")
0
32
* switchFrame("#frameId")
0
33
* input("input#inputId", "testing input")
24
34
* click("input#submitId")
47
35
* match text("div#valueId") == "testing input"
3
36
* switchFrame(null)
0
# survive Target.detachedFromTarget with nested iframes
50
* if ((driverType == 'chrome' || driverType == 'playwright') && !skipSlowTests) karate.call('14.feature')
3897
>>
src.test.java.driver.14
3891
4
* driver serverUrl + '/14'
449
# switch into nested iframe and fill out form
8
* switchFrame("#nestedParent")
2
9
* waitFor("#nestedChild")
14
10
* switchFrame("#nestedChild")
0
11
* waitFor("input[name='search']")
10
12
* input("input[name='search']", "hello world")
27
# switch back to root frame and click "continue"
15
* switchFrame(null)
0
16
* click('#continueButton')
32
# wait for "processing" => nested iframe is replaced and is then removed in background
19
* waitForText('body', 'Success')
3323
# after successful processing we'll get a "finish button" that creates our final state
22
* click('#finish')
24
23
* match html('#result') == '<p id="result">Done</p>'
9
# xpath locators
53
* call read('15.feature')
117
>>
src.test.java.driver.15
99
4
* driver serverUrl + '/15'
21
# xpath script in whole document
8
* def first = script('//li', '_.textContent')
21
9
* match first == 'item 1'
0
# xpath scriptAll in whole document
12
* def list = scriptAll('//li', '_.textContent')
14
13
* match list == ['item 1', 'item 2', 'item 2.1', 'item 2.2', 'item 3']
0
# get first ul in entire document
16
* def first = locate('//ul')
1
# validates that operations other than locate also work...
18
* match attribute('//ul', 'id') == 'first'
3
# relative xpath - locate
21
* def second = first.locate('./ul/li')
1
22
* match second.text == 'item 2.1'
2
# relative xpath - locate all
25
* def seconds = second.locateAll('..//li')
1
26
* assert seconds.length == 2
0
27
* match (seconds[1].text) == 'item 2.2'
1
# relative xpath - script all
30
* match first.locateAll('./li').length == 3
2
31
* def level1 = first.scriptAll('./li', '_.textContent')
10
32
* match level1 == ['item 1', 'item 2', 'item 3']
0
# relative xpath (any depth) script all
35
* def all = first.scriptAll('.//li', '_.textContent')
15
36
* match all == ['item 1', 'item 2', 'item 2.1', 'item 2.2', 'item 3']
0
38
* def children = first.children
1
39
* match (children.length) == 4
0
40
* match (children[0].text) == 'item 1'
1
41
* match (children[0].parent).attribute('id') == 'first'
2
# image comparison
56
* if (!skipSlowTests) karate.call('16.feature')
714
>>
src.test.java.driver.16
708
4
* driver serverUrl + '/16'
23
# compare screenshot (normally would read a baseline from disk but we'll simulate here)
8
* def baselineBytes = screenshot()
61
9
* compareImage { baseline: '#(baselineBytes)', latest: '#(baselineBytes)' }
204
Loading...
# compare mismatched screenshot with ignoredBoxes
12
* click('#show')
48
13
* def latestBytes = screenshot()
55
14
* def ignoredBoxes =
0
[{ top: 0, bottom: 200, left: 0, right: 200 }]
23
* compareImage { baseline: '#(baselineBytes)', latest: '#(baselineBytes)', options: { ignoredBoxes: '#(ignoredBoxes)' } }
96
Loading...
# compare mismatched screenshot: allowed to fail with custom failureThreshold
26
* compareImage { baseline: '#(baselineBytes)', latest: '#(latestBytes)', options: { failureThreshold: 99.9 } }
74
Loading...
# compare mismatched screenshot: allowed to fail with mismatchShouldPass
29
* configure imageComparison = { mismatchShouldPass: true }
0
30
* def result = karate.compareImage(baselineBytes, latestBytes)
80
Loading...
09:36:53.461 image comparison failed: latest image differed from baseline more than allowable threshold: 4.340277777777778% >= 0.0%
31
* match result.isMismatch == true
1
# missing baseline screenshot: allowed to fail with mismatchShouldPass
34
* def result = karate.compareImage(null, latestBytes)
65
Loading...
09:36:53.527 image comparison failed: baseline image was empty or not found
35
* match result.isBaselineMissing == true
1
# switch to root session on page close
59
* call read('17.feature')
247
>>
src.test.java.driver.17
209
4
* driver serverUrl + '/17_a'
22
7
* def openPageInNewTab = (pageUrl) => driver.script(`window.open('${pageUrl}', '_blank', 'noopener')`)
3
9
* waitFor('input[name=a]').input('a1')
17
11
* openPageInNewTab(serverUrl + '/17_b')
20
12
* switchPage('17_b')
31
13
* waitFor('input[name=b]').input('b1')
80
14
* close()
16
16
* switchPage('17_a')
14
17
* input('input[name=a]', 'a2')
6
# submit and retry Should in theory pass for all browsers but playwright handles retries a bit different so expectations that work with it may not work with other implementations.
62
* if (driverType == 'playwright') karate.call('18.feature')
3064
>>
src.test.java.driver.18
3055
7
* driver serverUrl + '/02'
24
8
* def start = new Date().getTime();
7
# wait for slow loading element
10
* retry(3, 1500).click('#slowDiv')
2323
11
* def end = new Date().getTime();
1
12
* def elapsedTime = end - start
4
13
* print "Elapsed time:", elapsedTime
1
09:36:56.142 [print] Elapsed time: 2325.0
# setTimeout in the html page kicked off when the page was loaded, which is a few (50-ish) ms before we get here.
# Since slowDiv takes 2s to load, click() should return not faster than 2s - 50ms, and not longer than 2s + some arbitrary buffer
16
* assert elapsedTime > 1550
2
17
* assert elapsedTime < 3500
1
21
* driver serverUrl + '/18'
19
22
* submit().click('#slowlink')
662
23
* match optional('#containerDiv').present == true
11
# friendly locators
65
* if (driverType != 'geckodriver') karate.call('19.feature')
62
>>
src.test.java.driver.19
57
4
* driver serverUrl + '/19'
17
5
* timeout(2000)
1
9
* match locate('{^i}Center').rightOf().find('span').attribute('id') == 'e'
19
10
* match rightOf('{^i}Center').find('span').attribute('id') == 'e'
2
11
* match leftOf('{^i}Center').find('span').attribute('id') == 'w'
2
12
* match above('{^i}Center').find('span').attribute('id') == 'n'
2
13
* match below('{^i}Center').find('span').attribute('id') == 's'
2
14
* match leftOf('{^i}Center').find('{^b}West').attribute('id') == 'w_nested'
2
# PW returns them all sorted by distance. Currently, the Karate API only allows find() to return one element.
16
* match near('{^i}Center').find('span').attribute('id') == 'n'
2
17
* if (driverType != 'playwright') karate.abort()
0
# Drivers other than playwright will fail the tests below because:
# they will fail calling rightOf('{^i}Center').find('{^b}West') rather than return an element with present = false
# they don't support xpath in find()
21
* match rightOf('{^i}Center').find('{^b}West').present == false
3
22
* match locate('//i').rightOf().find('//span').attribute('id') == 'e'
3
23
* match locate('{^i}Center').rightOf().find('//span').attribute('id') == 'e'
2