Skip to content

Commit 815b9a9

Browse files
authored
Merge branch 'trunk' into information-pallavi
2 parents 9ecc201 + e321e7c commit 815b9a9

File tree

12 files changed

+300
-48
lines changed

12 files changed

+300
-48
lines changed
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
2+
const assert = require("assert");
3+
const firefox = require('selenium-webdriver/firefox');
4+
const {until, Builder} = require("selenium-webdriver");
5+
6+
let driver
7+
8+
beforeEach(async function () {
9+
driver = new Builder()
10+
.setFirefoxOptions(new firefox.Options().enableBidi())
11+
.build()
12+
})
13+
14+
afterEach(async function () {
15+
await driver.quit()
16+
})
17+
18+
function delay(ms) {
19+
return new Promise((resolve) => setTimeout(resolve, ms))
20+
}
21+
22+
describe('BiDi Logging', function () {
23+
it('can listen to console log', async function () {
24+
let log = null
25+
const handler = await driver.script().addConsoleMessageHandler((logEntry) => {
26+
log = logEntry
27+
})
28+
29+
await driver.get('https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html')
30+
await driver.findElement({ id: 'consoleLog' }).click()
31+
32+
await delay(3000)
33+
34+
assert.equal(log.text, 'Hello, world!')
35+
await driver.script().removeConsoleMessageHandler(handler)
36+
})
37+
38+
it('can remove console log handler', async function () {
39+
let log = null
40+
const handler = await driver.script().addConsoleMessageHandler((logEntry) => {
41+
log = logEntry
42+
})
43+
44+
await driver.script().removeConsoleMessageHandler(handler)
45+
46+
await driver.get('https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html')
47+
await driver.findElement({ id: 'consoleLog' }).click()
48+
49+
await delay(3000)
50+
51+
assert.equal(log, null)
52+
})
53+
54+
it('can listen to javascript error', async function () {
55+
let log = null
56+
const handler = await driver.script().addJavaScriptErrorHandler((logEntry) => {
57+
log = logEntry
58+
})
59+
60+
await driver.get('https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html')
61+
await driver.findElement({ id: 'jsException' }).click()
62+
63+
await delay(3000)
64+
65+
assert.equal(log.text, 'Error: Not working')
66+
assert.equal(log.type, 'javascript')
67+
assert.equal(log.level, 'error')
68+
69+
await driver.script().removeJavaScriptErrorHandler(handler)
70+
})
71+
72+
it('can remove to javascript error handler', async function () {
73+
let log = null
74+
const handler = await driver.script().addJavaScriptErrorHandler((logEntry) => {
75+
log = logEntry
76+
})
77+
78+
await driver.script().removeJavaScriptErrorHandler(handler)
79+
80+
await driver.get('https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html')
81+
await driver.findElement({ id: 'jsException' }).click()
82+
83+
await delay(3000)
84+
85+
assert.equal(log, null)
86+
})
87+
})
88+
89+
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
2+
const assert = require("assert");
3+
const firefox = require('selenium-webdriver/firefox');
4+
const {until, Builder} = require("selenium-webdriver");
5+
6+
let driver
7+
8+
beforeEach(async function () {
9+
driver = new Builder()
10+
.setFirefoxOptions(new firefox.Options().enableBidi())
11+
.build()
12+
})
13+
14+
afterEach(async function () {
15+
await driver.quit()
16+
})
17+
18+
function delay(ms) {
19+
return new Promise((resolve) => setTimeout(resolve, ms))
20+
}
21+
22+
describe('BiDi Script', function () {
23+
24+
it('can listen to dom mutations', async function () {
25+
let message = null
26+
await driver.script().addDomMutationHandler((m) => {
27+
message = m
28+
})
29+
30+
await driver.get('https://www.selenium.dev/selenium/web/dynamic')
31+
32+
let element = driver.findElement({ id: 'reveal' })
33+
await element.click()
34+
let revealed = driver.findElement({ id: 'revealed' })
35+
await driver.wait(until.elementIsVisible(revealed), 5000)
36+
37+
assert.strictEqual(message['attribute_name'], 'style')
38+
assert.strictEqual(message['current_value'], '')
39+
assert.strictEqual(message['old_value'], 'display:none;')
40+
})
41+
42+
it('can remove to dom mutation handler', async function () {
43+
let message = null
44+
let id = await driver.script().addDomMutationHandler((m) => {
45+
message = m
46+
})
47+
48+
await driver.script().removeDomMutationHandler(id)
49+
50+
await driver.get('https://www.selenium.dev/selenium/web/dynamic')
51+
52+
let element = driver.findElement({ id: 'reveal' })
53+
await element.click()
54+
let revealed = driver.findElement({ id: 'revealed' })
55+
await driver.wait(until.elementIsVisible(revealed), 5000)
56+
57+
assert.strictEqual(message, null)
58+
})
59+
60+
it('can pin script', async function () {
61+
await driver.script().pin("() => { console.log('Hello!'); }")
62+
let log
63+
64+
await driver.script().addConsoleMessageHandler((logEntry) => {
65+
log = logEntry
66+
})
67+
68+
await driver.get('https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html')
69+
70+
await delay(3000)
71+
72+
assert.equal(log.text, 'Hello!')
73+
})
74+
75+
it('can unpin script', async function () {
76+
const id = await driver.script().pin("() => { console.log('Hello!'); }")
77+
78+
let count = 0
79+
await driver.script().addConsoleMessageHandler((logEntry) => {
80+
count++
81+
})
82+
83+
await driver.get('https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html')
84+
85+
await driver.script().unpin(id)
86+
87+
await driver.get('https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html')
88+
89+
assert.equal(count, 1)
90+
})
91+
})
92+
93+
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
require 'spec_helper'
2+
3+
RSpec.describe 'Browser' do
4+
let(:driver) { start_session }
5+
6+
it 'gets the current title' do
7+
driver.navigate.to 'https://www.selenium.dev/'
8+
current_title = driver.title
9+
expect(current_title).to eq 'Selenium'
10+
end
11+
12+
it 'gets the current url' do
13+
driver.navigate.to 'https://www.selenium.dev/'
14+
current_url = driver.current_url
15+
expect(current_url).to eq 'https://www.selenium.dev/'
16+
end
17+
end
Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,32 @@
1-
# frozen_string_literal: true
2-
31
require 'spec_helper'
42

5-
RSpec.describe 'Navigation' do
3+
RSpec.describe 'Browser' do
64
let(:driver) { start_session }
5+
6+
it 'navigates to a page' do
7+
driver.navigate.to 'https://www.selenium.dev/'
8+
driver.get 'https://www.selenium.dev/'
9+
expect(driver.current_url).to eq 'https://www.selenium.dev/'
10+
end
11+
12+
it 'navigates back' do
13+
driver.navigate.to 'https://www.selenium.dev/'
14+
driver.navigate.to 'https://www.selenium.dev/selenium/web/inputs.html'
15+
driver.navigate.back
16+
expect(driver.current_url).to eq 'https://www.selenium.dev/'
17+
end
18+
19+
it 'navigates forward' do
20+
driver.navigate.to 'https://www.selenium.dev/'
21+
driver.navigate.to 'https://www.selenium.dev/selenium/web/inputs.html'
22+
driver.navigate.back
23+
driver.navigate.forward
24+
expect(driver.current_url).to eq 'https://www.selenium.dev/selenium/web/inputs.html'
25+
end
26+
27+
it 'refreshes the page' do
28+
driver.navigate.to 'https://www.selenium.dev/'
29+
driver.navigate.refresh
30+
expect(driver.current_url).to eq 'https://www.selenium.dev/'
31+
end
732
end

website_and_docs/content/documentation/webdriver/interactions/_index.en.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,14 @@ You can read the current page title from the browser:
2323
{{< tab header="Python" text=true >}}
2424
{{< gh-codeblock path="examples/python/tests/interactions/test_interactions.py#L7" >}}
2525
{{< /tab >}}
26-
{{< tab header="CSharp" >}}driver.Title;{{< /tab >}}
27-
{{< tab header="Ruby" >}}driver.title{{< /tab >}}
26+
{{< tab header="CSharp" >}}driver.Title;{{< /tab >}}
27+
{{< tab header="Ruby" text=true >}}
28+
{{< gh-codeblock path="examples/ruby/spec/interactions/browser_spec.rb#L8" >}}
29+
{{< /tab >}}
2830
{{< tab header="JavaScript" text=true >}}
2931
{{< gh-codeblock path="examples/javascript/test/interactions/interactionsIndex.spec.js#L20" >}}
3032
{{< /tab >}}
31-
{{< tab header="Kotlin" >}}driver.title{{< /tab >}}
33+
{{< tab header="Kotlin" >}}driver.title{{< /tab >}}
3234
{{< /tabpane >}}
3335

3436

@@ -45,7 +47,9 @@ You can read the current URL from the browser's address bar using:
4547
{{< gh-codeblock path="examples/python/tests/interactions/test_interactions.py#L10" >}}
4648
{{< /tab >}}
4749
{{< tab header="CSharp" >}}driver.Url;{{< /tab >}}
48-
{{< tab header="Ruby" >}}driver.current_url{{< /tab >}}
50+
{{< tab header="Ruby" text=true >}}
51+
{{< gh-codeblock path="examples/ruby/spec/interactions/browser_spec.rb#L14" >}}
52+
{{< /tab >}}
4953
{{< tab header="JavaScript" text=true >}}
5054
{{< gh-codeblock path="examples/javascript/test/interactions/interactionsIndex.spec.js#L24" >}}
5155
{{< /tab >}}

website_and_docs/content/documentation/webdriver/interactions/_index.ja.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ aliases: [
2323
{{< gh-codeblock path="examples/python/tests/interactions/test_interactions.py#L7" >}}
2424
{{< /tab >}}
2525
{{< tab header="CSharp" >}}driver.Title;{{< /tab >}}
26-
{{< tab header="Ruby" >}}driver.title{{< /tab >}}
26+
{{< tab header="Ruby" text=true >}}
27+
{{< gh-codeblock path="examples/ruby/spec/interactions/browser_spec.rb#L8" >}}
28+
{{< /tab >}}
2729
{{< tab header="JavaScript" text=true >}}
2830
{{< gh-codeblock path="examples/javascript/test/interactions/interactionsIndex.spec.js#L20" >}}
2931
{{< /tab >}}
@@ -43,7 +45,9 @@ aliases: [
4345
{{< gh-codeblock path="examples/python/tests/interactions/test_interactions.py#L10" >}}
4446
{{< /tab >}}
4547
{{< tab header="CSharp" >}}driver.Url;{{< /tab >}}
46-
{{< tab header="Ruby" >}}driver.current_url{{< /tab >}}
48+
{{< tab header="Ruby" text=true >}}
49+
{{< gh-codeblock path="examples/ruby/spec/interactions/browser_spec.rb#L14" >}}
50+
{{< /tab >}}
4751
{{< tab header="JavaScript" text=true >}}
4852
{{< gh-codeblock path="examples/javascript/test/interactions/interactionsIndex.spec.js#L24" >}}
4953
{{< /tab >}}

website_and_docs/content/documentation/webdriver/interactions/_index.pt-br.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ Você pode ler o título da página atual no navegador:
2424
{{< gh-codeblock path="examples/python/tests/interactions/test_interactions.py#L7" >}}
2525
{{< /tab >}}
2626
{{< tab header="CSharp" >}}driver.Title;{{< /tab >}}
27-
{{< tab header="Ruby" >}}driver.title{{< /tab >}}
27+
{{< tab header="Ruby" text=true >}}
28+
{{< gh-codeblock path="examples/ruby/spec/interactions/browser_spec.rb#L8" >}}
29+
{{< /tab >}}
2830
{{< tab header="JavaScript" text=true >}}
2931
{{< gh-codeblock path="examples/javascript/test/interactions/interactionsIndex.spec.js#L20" >}}
3032
{{< /tab >}}
@@ -44,7 +46,9 @@ Você pode ler a URL atual na barra de endereço do navegador usando:
4446
{{< gh-codeblock path="examples/python/tests/interactions/test_interactions.py#L10" >}}
4547
{{< /tab >}}
4648
{{< tab header="CSharp" >}}driver.Url;{{< /tab >}}
47-
{{< tab header="Ruby" >}}driver.current_url{{< /tab >}}
49+
{{< tab header="Ruby" text=true >}}
50+
{{< gh-codeblock path="examples/ruby/spec/interactions/browser_spec.rb#L14" >}}
51+
{{< /tab >}}
4852
{{< tab header="JavaScript" text=true >}}
4953
{{< gh-codeblock path="examples/javascript/test/interactions/interactionsIndex.spec.js#L24" >}}
5054
{{< /tab >}}

website_and_docs/content/documentation/webdriver/interactions/_index.zh-cn.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ aliases: [
2323
{{< gh-codeblock path="examples/python/tests/interactions/test_interactions.py#L7" >}}
2424
{{< /tab >}}
2525
{{< tab header="CSharp" >}}driver.Title;{{< /tab >}}
26-
{{< tab header="Ruby" >}}driver.title{{< /tab >}}
26+
{{< tab header="Ruby" text=true >}}
27+
{{< gh-codeblock path="examples/ruby/spec/interactions/browser_spec.rb#L8" >}}
28+
{{< /tab >}}
2729
{{< tab header="JavaScript" text=true >}}
2830
{{< gh-codeblock path="examples/javascript/test/interactions/interactionsIndex.spec.js#L20" >}}
2931
{{< /tab >}}
@@ -42,7 +44,9 @@ aliases: [
4244
{{< gh-codeblock path="examples/python/tests/interactions/test_interactions.py#L10" >}}
4345
{{< /tab >}}
4446
{{< tab header="CSharp" >}}driver.Url;{{< /tab >}}
45-
{{< tab header="Ruby" >}}driver.current_url{{< /tab >}}
47+
{{< tab header="Ruby" text=true >}}
48+
{{< gh-codeblock path="examples/ruby/spec/interactions/browser_spec.rb#L14" >}}
49+
{{< /tab >}}
4650
{{< tab header="JavaScript" text=true >}}
4751
{{< gh-codeblock path="examples/javascript/test/interactions/interactionsIndex.spec.js#L24" >}}
4852
{{< /tab >}}

website_and_docs/content/documentation/webdriver/interactions/navigation.en.md

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ open your website. This can be achieved in a single line:
2323
{{< tab header="CSharp" text=true >}}
2424
{{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/NavigationTest.cs#L17-L20" >}}
2525
{{< /tab >}}
26-
{{< tab header="Ruby" >}}
27-
driver.navigate.to 'https://selenium.dev'
28-
{{< /tab >}}
26+
{{< tab header="Ruby" text=true >}}
27+
{{< gh-codeblock path="examples/ruby/spec/interactions/navigation_spec.rb#L7-L9" >}}
28+
{{< /tab >}}
2929
{{< tab header="JavaScript" text=true >}}
3030
{{< gh-codeblock path="examples/javascript/test/interactions/navigation.spec.js#L16-L20" >}}
3131
{{< /tab >}}
@@ -53,7 +53,9 @@ Pressing the browser's back button:
5353
{{< tab header="CSharp" text=true >}}
5454
{{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/NavigationTest.cs#L24-L25" >}}
5555
{{< /tab >}}
56-
{{< tab header="Ruby" >}}driver.navigate.back{{< /tab >}}
56+
{{< tab header="Ruby" text=true >}}
57+
{{< gh-codeblock path="examples/ruby/spec/interactions/navigation_spec.rb#L15" >}}
58+
{{< /tab >}}
5759
{{< tab header="JavaScript" text=true >}}
5860
{{< gh-codeblock path="examples/javascript/test/interactions/navigation.spec.js#L24-L25" >}}
5961
{{< /tab >}}
@@ -73,7 +75,9 @@ Pressing the browser's forward button:
7375
{{< tab header="CSharp" text=true >}}
7476
{{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/NavigationTest.cs#L29-L30" >}}
7577
{{< /tab >}}
76-
{{< tab header="Ruby" >}}driver.navigate.forward{{< /tab >}}
78+
{{< tab header="Ruby" text=true >}}
79+
{{< gh-codeblock path="examples/ruby/spec/interactions/navigation_spec.rb#L23" >}}
80+
{{< /tab >}}
7781
{{< tab header="JavaScript" text=true >}}
7882
{{< gh-codeblock path="examples/javascript/test/interactions/navigation.spec.js#L29-L30" >}}
7983
{{< /tab >}}
@@ -94,7 +98,9 @@ Refresh the current page:
9498
{{< tab header="CSharp" text=true >}}
9599
{{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/NavigationTest.cs#L34-L35" >}}
96100
{{< /tab >}}
97-
{{< tab header="Ruby" >}}driver.navigate.refresh{{< /tab >}}
101+
{{< tab header="Ruby" text=true >}}
102+
{{< gh-codeblock path="examples/ruby/spec/interactions/navigation_spec.rb#L29" >}}
103+
{{< /tab >}}
98104
{{< tab header="JavaScript" text=true >}}
99105
{{< gh-codeblock path="examples/javascript/test/interactions/navigation.spec.js#L34-L35" >}}
100106
{{< /tab >}}

0 commit comments

Comments
 (0)