Skip to content
This repository was archived by the owner on Jun 30, 2021. It is now read-only.

Commit 78573ea

Browse files
committed
Add tests to support Selenium IDE
1 parent 53e6319 commit 78573ea

File tree

15 files changed

+361
-7
lines changed

15 files changed

+361
-7
lines changed

.ruby-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2.3.1

.travis.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# us to pick a language else it will pick Ruby by default
33
# language: generic
44
# language: ruby
5-
language: python
5+
language: ruby
66

77
# Omit running tests on temporal branches,
88
# i.e. branches with names that start with "tmp"
@@ -33,7 +33,7 @@ matrix:
3333
# Linux with docker:stable compose:stable
3434
# Use DOCKER_PUSH_LATEST=false to debug
3535
- os: linux
36-
language: python
36+
language: ruby
3737
sudo: required
3838
dist: trusty
3939
services:
@@ -45,7 +45,7 @@ matrix:
4545
DOCKER_PUSH_LATEST=true
4646
# Linux with docker:beta/older compose:beta/older
4747
- os: linux
48-
language: python
48+
language: ruby
4949
sudo: required
5050
dist: trusty
5151
services:
@@ -55,7 +55,7 @@ matrix:
5555
DOCKER_COMPOSE_VERSION="1.8.1"
5656
# Linux with docker:stable compose:beta/older
5757
- os: linux
58-
language: python
58+
language: ruby
5959
sudo: required
6060
dist: trusty
6161
services:
@@ -65,7 +65,7 @@ matrix:
6565
DOCKER_COMPOSE_VERSION="1.8.1"
6666
# Linux with docker:beta/older compose:stable
6767
- os: linux
68-
language: python
68+
language: ruby
6969
sudo: required
7070
dist: trusty
7171
services:

CONTRIBUTING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ For pull requests or local commits:
66
time (./test/bef && ./test/install && ./test/script_start && ./test/script_end) ; beep
77
docker exec grid versions && ./test/after_script && travis lint
88
open ./images/grid2_console.png && open ./images/grid3_console.png && open ./videos/mobile_emulation/*.mkv
9+
open test/seleIDE/videos/rc/sele_ide.mkv
910
git checkout -b tmp-3.0.0b4b && git checkout ./images/grid2_console.png && git checkout ./images/grid3_console.png
1011
#git add ... git commit ... git push ... open pull request
1112

test/python_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def webdriver_connect():
6363

6464
# Set location top left and size to max allowed on the container
6565
width = os.environ.get('SCREEN_WIDTH','800')
66-
height = os.environ.get('SCREEN_HEIGHT','1200')
66+
height = os.environ.get('SCREEN_HEIGHT','600')
6767
driver.set_window_position(0, 0)
6868
driver.set_window_size(width, height)
6969

@@ -80,7 +80,7 @@ def check_hub_title():
8080
assert "Grid Console" in driver.title
8181

8282
if args.browser == 'chrome':
83-
driver.set_window_size(1400, 500)
83+
driver.set_window_size(1400, 670)
8484
# Selenium grid console - open
8585
open_hub_page()
8686
time.sleep(msleep)

test/script_scenario_basic

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,39 @@ docker cp grid3:/test/console.png ./images/grid3_console.png
9494
# cleanup
9595
docker stop grid3 || true
9696
docker rm grid3 || true
97+
98+
echo "#==================================================================="
99+
echo "# Scenario 1d [basic]: Selenium IDE RC"
100+
echo "#==================================================================="
101+
102+
docker run --name=gridrc -d -e VIDEO=true \
103+
-e MOCK_SERVER_HOST="d.host.loc.dev" \
104+
-e MOCK_SERVER_PORT \
105+
-e USE_SELENIUM="2" \
106+
-e CHROME=true -e FIREFOX=true \
107+
-e RC_CHROME=true -e RC_FIREFOX=true \
108+
-e VIDEO_FILE_NAME=sele_ide \
109+
--shm-size=1g \
110+
-p 4444:24444 \
111+
selenium
112+
113+
sleep 0.5 && docker logs gridrc
114+
docker exec gridrc wait_all_done 40s
115+
docker exec gridrc versions
116+
docker exec gridrc errors || true
117+
docker logs gridrc
118+
119+
# Run tests
120+
cd test/seleIDE
121+
gem install bundler -v=1.13.2
122+
bundle install
123+
RUBYOPT=W0 bundle exec ./seleIDE *.rb
124+
125+
docker exec gridrc stop-video
126+
docker exec gridrc errors || true
127+
mkdir -p ./videos/rc
128+
docker cp gridrc:/videos/sele_ide.mkv ./videos/rc/
129+
130+
# cleanup
131+
docker stop gridrc || true
132+
docker rm gridrc || true

test/seleIDE/.ruby-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../.ruby-version

test/seleIDE/DesktopTest.html

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4+
<head profile="http://selenium-ide.openqa.org/profiles/test-case">
5+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
6+
<link rel="selenium.base" href="https://www.zalando.co.uk" />
7+
<title>DesktopNavabrLogin</title>
8+
</head>
9+
<body>
10+
<table cellpadding="1" cellspacing="1" border="1">
11+
<thead>
12+
<tr><td rowspan="1" colspan="3">DesktopNavabrLogin</td></tr>
13+
</thead><tbody>
14+
<tr>
15+
<td>open</td>
16+
<td>/customer-logout</td>
17+
<td></td>
18+
</tr>
19+
<tr>
20+
<td>open</td>
21+
<td>/</td>
22+
<td></td>
23+
</tr>
24+
<tr>
25+
<td>assertElementPresent</td>
26+
<td>id=login-btn</td>
27+
<td></td>
28+
</tr>
29+
<tr>
30+
<td>click</td>
31+
<td>id=login-btn</td>
32+
<td></td>
33+
</tr>
34+
<tr>
35+
<td>verifyAttribute</td>
36+
<td>css=#desktop-popup-modal@style</td>
37+
<td>display: block;</td>
38+
</tr>
39+
<tr>
40+
<td>type</td>
41+
<td>name=email</td>
42+
43+
</tr>
44+
<tr>
45+
<td>type</td>
46+
<td>name=password</td>
47+
<td>somepassword</td>
48+
</tr>
49+
<tr>
50+
<td>click</td>
51+
<td>id=sign-in-button</td>
52+
<td></td>
53+
</tr>
54+
<tr>
55+
<td>waitForPageToLoad</td>
56+
<td></td>
57+
<td></td>
58+
</tr>
59+
<tr>
60+
<td>pause</td>
61+
<td>5000</td>
62+
<td></td>
63+
</tr>
64+
<tr>
65+
<td>assertText</td>
66+
<td>id=navbar-profile-name</td>
67+
<td>Dominik</td>
68+
</tr>
69+
</tbody></table>
70+
</body>
71+
</html>

test/seleIDE/DesktopTest.java

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
package com.example.tests;
2+
3+
import java.util.regex.Pattern;
4+
import java.util.concurrent.TimeUnit;
5+
import org.junit.*;
6+
import static org.junit.Assert.*;
7+
import static org.hamcrest.CoreMatchers.*;
8+
import org.openqa.selenium.*;
9+
import org.openqa.selenium.firefox.FirefoxDriver;
10+
import org.openqa.selenium.support.ui.Select;
11+
12+
public class DesktopTest {
13+
private WebDriver driver;
14+
private String baseUrl;
15+
private boolean acceptNextAlert = true;
16+
private StringBuffer verificationErrors = new StringBuffer();
17+
18+
@Before
19+
public void setUp() throws Exception {
20+
driver = new FirefoxDriver();
21+
baseUrl = "https://www.zalando.co.uk";
22+
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
23+
}
24+
25+
@Test
26+
public void testDesktopTest() throws Exception {
27+
driver.get(baseUrl + "/customer-logout");
28+
driver.get(baseUrl + "/category/women-shoes/products?gender=FEMALE");
29+
assertTrue(isElementPresent(By.xpath("//div[7]/div/div[3]")));
30+
assertTrue(isElementPresent(By.xpath("//div[18]/div[3]")));
31+
assertTrue(isElementPresent(By.xpath("//div[@id='slider-range']/div/div")));
32+
assertTrue(isElementPresent(By.cssSelector("div.filter-checkbox-wrapper > div.checkbox > label")));
33+
driver.findElement(By.cssSelector("div.filter-checkbox-wrapper > div.checkbox > label")).click();
34+
driver.findElement(By.cssSelector("div.filter-apply")).click();
35+
try {
36+
assertTrue(driver.findElement(By.cssSelector("input.filter-tag-id")).isSelected());
37+
} catch (Error e) {
38+
verificationErrors.append(e.toString());
39+
}
40+
String url = driver.getCurrentUrl();
41+
// ERROR: Caught exception [ERROR: Unsupported command [getEval | new RegExp(‘tags=attribute_tag.([0-9]+)’).exec(‘${url}’)[1] | ]]
42+
System.out.println("$(urlHasTags)");
43+
}
44+
45+
@After
46+
public void tearDown() throws Exception {
47+
driver.quit();
48+
String verificationErrorString = verificationErrors.toString();
49+
if (!"".equals(verificationErrorString)) {
50+
fail(verificationErrorString);
51+
}
52+
}
53+
54+
private boolean isElementPresent(By by) {
55+
try {
56+
driver.findElement(by);
57+
return true;
58+
} catch (NoSuchElementException e) {
59+
return false;
60+
}
61+
}
62+
63+
private boolean isAlertPresent() {
64+
try {
65+
driver.switchTo().alert();
66+
return true;
67+
} catch (NoAlertPresentException e) {
68+
return false;
69+
}
70+
}
71+
72+
private String closeAlertAndGetItsText() {
73+
try {
74+
Alert alert = driver.switchTo().alert();
75+
String alertText = alert.getText();
76+
if (acceptNextAlert) {
77+
alert.accept();
78+
} else {
79+
alert.dismiss();
80+
}
81+
return alertText;
82+
} finally {
83+
acceptNextAlert = true;
84+
}
85+
}
86+
}

test/seleIDE/DesktopTest.rb

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
require "rubygems"
2+
gem "rspec"
3+
gem "selenium-client"
4+
require "selenium/client"
5+
require "selenium/rspec/spec_helper"
6+
require "spec/test/unit"
7+
8+
describe "DesktopTest" do
9+
attr_reader :selenium_driver
10+
alias :page :selenium_driver
11+
12+
before(:all) do
13+
@verification_errors = []
14+
@selenium_driver = Selenium::Client::Driver.new \
15+
:host => "localhost",
16+
:port => 4444,
17+
:browser => "*chrome",
18+
:url => "https://www.zalando.co.uk",
19+
:timeout_in_second => 60
20+
end
21+
22+
before(:each) do
23+
@selenium_driver.start_new_browser_session
24+
end
25+
26+
append_after(:each) do
27+
@selenium_driver.close_current_browser_session
28+
@verification_errors.should == []
29+
end
30+
31+
it "test_desktop" do
32+
page.open "/brands/men/"
33+
page.wait_for_page_to_load "9000"
34+
begin
35+
page.is_element_present("css=.header").should be_true
36+
rescue ExpectationNotMetError
37+
@verification_errors << $!
38+
end
39+
url = page.get_location
40+
puts "Last url: #{url}"
41+
end
42+
end

test/seleIDE/Gemfile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
ruby '2.3.1'
2+
source 'https://rubygems.org'
3+
4+
gem 'selenium-client', '1.2.18'
5+
gem 'rspec', '2.99.0'
6+
gem 'rspec-core', '2.99.0'
7+
gem 'rspec-mocks', '2.99.4'
8+
gem 'rspec-expectations', '2.99.2'
9+
gem 'test-unit', '1.2.3'
10+
gem 'bundler', '~> 1.13'

0 commit comments

Comments
 (0)