101 |
102 |
103 |
--------------------------------------------------------------------------------
/selenium/desiredcapabilities.h:
--------------------------------------------------------------------------------
1 | #ifndef DESIREDCAPABILITIES_H
2 | #define DESIREDCAPABILITIES_H
3 |
4 | #include
5 | #include
6 | #include
7 |
8 | #include "proxy.h"
9 | #include "browser.h"
10 | #include "platform.h"
11 |
12 | class DesiredCapabilities
13 | {
14 | public:
15 | DesiredCapabilities(Browser::Type browser);
16 |
17 | void setBrowser(Browser::Type browser) { m_browser = browser; }
18 | void setProxy(Proxy* proxy) { m_proxy = proxy; }
19 | void setVersion(QString version) { m_version = version; }
20 | void setPlatform(Platform::Type platform) { m_platform = platform;}
21 |
22 | Browser::Type browser() { return m_browser; }
23 | Platform::Type platform() { return m_platform; }
24 | Proxy* proxy() { return m_proxy; }
25 | QString version() { return m_version; }
26 |
27 | void setDatabaseEnabled(bool enabled) { setProperty("databaseEnabled", enabled); }
28 | void setLocationContextEnabled(bool enabled) { setProperty("locationContextEnabled", enabled); }
29 | void setApplicationCacheEnabled(bool enabled) { setProperty("applicationCacheEnabled", enabled); }
30 | void setBrowserConnectionEnabled(bool enabled) { setProperty("browserConnectionEnabled", enabled); }
31 | void setWebStorageEnabled(bool enabled) { setProperty("webStorageEnabled", enabled); }
32 | void setAcceptSslCerts(bool accept) { setProperty("acceptSslCerts", accept); }
33 | void setNativeEvents(bool enabled) { setProperty("nativeEvents", enabled); }
34 | void setUnexpectedAlertBehaviour(int value) { setProperty("unexpectedAlertBehaviour", value); }
35 | void setJavascriptEnabled(bool enabled) { setProperty("javascriptEnabled", enabled); } //only on HTMLUnitDriver
36 | void setRotatable(bool rotable) { setProperty("rotatable", rotable); } //only applies to mobile platforms
37 | void setElementScrollBehavior(int value) { setProperty("elementScrollBehavior", value); } //Supported in IE and Firefox (since 2.36)
38 | void setCssSelectorsEnabled(bool enabled) { setProperty("cssSelectorsEnabled", enabled); }
39 | void setHandlesAlerts(bool handle) { setProperty("handlesAlerts", handle); }
40 | void setTakesScreenshot(bool take) { setProperty("takesScreenshot", take); }
41 |
42 | bool isTakesScreenshot() { return property("takesScreenshot").toBool(); } //Read-only from server
43 | bool isHandlesAlerts() { return property("handlesAlerts").toBool(); } //Read-only from server
44 | bool isCssSelectorsEnabled() { return property("cssSelectorsEnabled").toBool(); }//Read-only from server
45 | bool isDatabaseEnabled() { return property("databaseEnabled").toBool(); }
46 | bool isLocationContextEnabled() { return property("locationContextEnabled").toBool(); }
47 | bool isApplicationCacheEnabled() { return property("applicationCacheEnabled").toBool(); }
48 | bool isBrowserConnectionEnabled() { return property("browserConnectionEnabled").toBool(); }
49 | bool isWebStorageEnabled() { return property("webStorageEnabled").toBool(); }
50 | bool isAcceptSslCerts() { return property("acceptSslCerts").toBool(); }
51 | bool isNativeEvents() { return property("nativeEvents").toBool(); }
52 | bool isJavascriptEnabled() { return property("javascriptEnabled").toBool(); }
53 | bool isRotatable() { return property("rotatable").toBool(); }
54 | int unexpectedAlertBehaviour() { return property("unexpectedAlertBehaviour").toInt(); }
55 | int elementScrollBehavior() { return property("elementScrollBehavior").toInt(); }
56 |
57 | QJsonObject properties() { return m_properties; }
58 |
59 | protected:
60 | QVariant property(QString property);
61 | void setProperty(QString property, QString value);
62 | void setProperty(QString property, int value);
63 | void setProperty(QString property, bool value);
64 |
65 | bool hasProperty(QString property);
66 |
67 | //QStringList m_properties;
68 | QJsonObject m_properties;
69 |
70 | Browser::Type m_browser;
71 | Proxy* m_proxy;
72 | QString m_version;
73 | Platform::Type m_platform;
74 | };
75 |
76 | #endif // DESIREDCAPABILITIES_H
77 |
--------------------------------------------------------------------------------
/selenium/select.cpp:
--------------------------------------------------------------------------------
1 | #include "select.h"
2 | #include "by.h"
3 | #include
4 | Select::Select(WebElement* element) :
5 | m_element(element)
6 | {
7 | QString tagName = m_element->tagName();
8 |
9 | if(tagName.isEmpty() || tagName != "select") {
10 | WebDriverException::throwException("Element is not select");
11 | }
12 |
13 | QString value = m_element->attribute("multiple");
14 |
15 | m_isMulti = !value.isEmpty() && (value != "false");
16 | }
17 |
18 | bool Select::isMultiple()
19 | {
20 | return m_isMulti;
21 | }
22 |
23 | Select::SOptions Select::options()
24 | {
25 | return m_element->findElements(By::tagName("option"));
26 | }
27 |
28 | Select::SOptions Select::allSelectedOptions()
29 | {
30 | SOptions selectedOptions;
31 | SOptions opts = options();
32 |
33 | for(int i = 0; i < opts.size(); i++) {
34 | if(opts.at(i)->isSelected()) {
35 | selectedOptions.push_back(opts.at(i));
36 | }
37 | }
38 |
39 | return selectedOptions;
40 | }
41 |
42 | WebElement* Select::firstSelectedOption()
43 | {
44 | SOptions opts = options();
45 |
46 | WebElement* option = 0;
47 |
48 | for(int i = 0; i < opts.size(); i++) {
49 | if(opts.at(i)->isSelected()) {
50 | option = opts.at(i);
51 | break;
52 | }
53 | }
54 |
55 | if(option == 0) {
56 | WebDriverException::throwException("No options are selected", ResponseStatusCodes::NO_SUCH_ELEMENT);
57 | }
58 | return option;
59 | }
60 |
61 | void Select::selectByVisibleText(QString text)
62 | {
63 | SOptions opts = options();
64 | bool matched = false;
65 |
66 | for(int i = 0; i < opts.size(); i++) {
67 | if(opts.at(i)->text() == text) {
68 |
69 | setSelected(opts.at(i));
70 |
71 | if(!isMultiple()) {
72 | return;
73 | }
74 |
75 | matched = true;
76 | }
77 | }
78 |
79 | if(!matched) {
80 | WebDriverException::throwException("Cannot locate option with text: " + text, ResponseStatusCodes::NO_SUCH_ELEMENT);
81 | }
82 | }
83 |
84 | void Select::selectByIndex(int index)
85 | {
86 | QString v = QString::number(index);
87 | bool matched = false;
88 |
89 | SOptions opts = options();
90 |
91 | for(int i = 0; i < opts.size(); i++) {
92 | if(opts.at(i)->attribute("index") == v) {
93 |
94 | setSelected(opts.at(i));
95 |
96 | if(!isMultiple()) {
97 | return;
98 | }
99 |
100 | matched = true;
101 | }
102 | }
103 |
104 | if(!matched) {
105 | WebDriverException::throwException("Cannot locate option with index: " + v, ResponseStatusCodes::NO_SUCH_ELEMENT);
106 | }
107 | }
108 |
109 | void Select::selectByValue(QString value)
110 | {
111 | SOptions opts = m_element->findElements(By::xpath(".//option[@value = '" + value + "']"));
112 | bool matched = false;
113 |
114 | for(int i = 0; i < opts.size(); i++) {
115 |
116 | setSelected(opts.at(i));
117 |
118 |
119 | if(!isMultiple()) {
120 | return;
121 | }
122 |
123 | matched = true;
124 | }
125 |
126 | if(!matched) {
127 | WebDriverException::throwException("Cannot locate option with value: " + value, ResponseStatusCodes::NO_SUCH_ELEMENT);
128 | }
129 | }
130 |
131 | void Select::deselectAll()
132 | {
133 | if(!isMultiple()) {
134 | WebDriverException::throwException("You may only deselect all options of a multi-select");
135 | return;
136 | }
137 |
138 | SOptions opts = options();
139 | for(int i = 0; i < opts.size(); i++) {
140 |
141 | if(opts.at(i)->isSelected()) {
142 | opts.at(i)->click();
143 | }
144 | }
145 |
146 | }
147 |
148 | void Select::deselectByValue(QString value)
149 | {
150 | if(!isMultiple()) {
151 | WebDriverException::throwException("You may only deselect option of a multi-select");
152 | return;
153 | }
154 |
155 | SOptions opts = m_element->findElements(By::xpath(".//option[@value = '" + value + "']"));
156 |
157 | for(int i = 0; i < opts.size(); i++) {
158 |
159 | if(opts.at(i)->isSelected()) {
160 | opts.at(i)->click();
161 | }
162 | }
163 | }
164 |
165 | void Select::deselectByIndex(int index)
166 | {
167 | if(!isMultiple()) {
168 | WebDriverException::throwException("You may only deselect option of a multi-select");
169 | return;
170 | }
171 |
172 | QString v = QString::number(index);
173 |
174 | SOptions opts = options();
175 |
176 | for(int i = 0; i < opts.size(); i++) {
177 | if(opts.at(i)->attribute("index") == v && opts.at(i)->isSelected()) {
178 | opts.at(i)->click();
179 | }
180 | }
181 | }
182 |
183 | void Select::deselectByVisibleText(QString text)
184 | {
185 | if(!isMultiple()) {
186 | WebDriverException::throwException("You may only deselect option of a multi-select");
187 | return;
188 | }
189 |
190 | SOptions opts = options();
191 |
192 | for(int i = 0; i < opts.size(); i++) {
193 | if(opts.at(i)->text() == text && opts.at(i)->isSelected()) {
194 | opts.at(i)->click();
195 | }
196 | }
197 | }
198 |
199 | void Select::setSelected(WebElement *option)
200 | {
201 | if(!option->isSelected()) {
202 | option->click();
203 | }
204 | }
205 |
--------------------------------------------------------------------------------
/selenium/webdriverhub.h:
--------------------------------------------------------------------------------
1 | #ifndef WEBDRIVERHUB_H
2 | #define WEBDRIVERHUB_H
3 |
4 | #include
5 | #include
6 | #include
7 | #include
8 |
9 | #include "seleniumserverhub.h"
10 | #include "desiredcapabilities.h"
11 | #include "proxy.h"
12 | #include "browser.h"
13 | #include "unexpectedalertbehaviour.h"
14 | #include "platform.h"
15 |
16 | class WebDriverHub : public SeleniumServerHub
17 | {
18 |
19 | public:
20 | explicit WebDriverHub(QString host, int port, DesiredCapabilities *dc);
21 | ~WebDriverHub();
22 |
23 | DesiredCapabilities* capabilities(bool refresh);
24 |
25 | QJsonObject status();
26 | QJsonArray sessions();
27 |
28 | void startSession();
29 | void deleteSession();
30 |
31 | void setTimeouts(QString type, int ms);
32 | void setTimeoutsAsyncScript(int ms);
33 | void setTimeoutsImplicitWait(int ms);
34 |
35 | QString getWindowHandle();
36 | QStringList getWindowHandles();
37 |
38 | void setUrl(QString url);
39 | QString getUrl();
40 |
41 | void forward();
42 | void back();
43 | void refresh();
44 |
45 | QJsonObject executeJS(QString script, QStringList args);
46 | QJsonObject executeAsyncJS(QString script, QStringList args);
47 |
48 | QString getScreenshot();
49 |
50 | QStringList getImeAvailableEngines();
51 | QString getImeActiveEngine();
52 | bool isImeActivated();
53 | void imeDeactivate();
54 | void imeActivate(QString engine);
55 |
56 | void changeFrame(QString id);
57 | void changeFrame(int id);
58 | void changeFrame(QJsonObject id);
59 | void changeFrame();
60 | void changeFrameParent();
61 |
62 | void changeWindow(QString name);
63 | void deleteWindow();
64 | void setWindowSize(QString handle, int width, int height);
65 | QSize getWindowSize(QString handle);
66 | void setWindowPosition(QString handle, int x, int y);
67 | QPoint getWindowPosition(QString handle);
68 | void windowMaximize(QString handle);
69 |
70 | QList getAllCookie();
71 | void setCookie(QJsonObject cookie);
72 | void deleteAllCookie();
73 | void deleteCookie(QString name);
74 |
75 | QString getSource();
76 | QString getTitle();
77 |
78 | QString getElement(QString by, QString value);
79 | QStringList getElements(QString by, QString value);
80 | QString getElementActive();
81 | void elementId(QString id);//This command is reserved for future use; its return type is currently undefined.
82 | QString getElementByElement(QString id, QString by, QString value);
83 | QStringList getElementsByElement(QString id, QString by, QString value);
84 | void elementClick(QString id);
85 | void elementSubmit(QString id);
86 | QString getElementText(QString id);
87 | void elementValue(QString id, QStringList values);
88 | void keys(QString text);
89 | QString getElementTagName(QString id);
90 | void elementClear(QString id);
91 | bool isElementSelected(QString id);
92 | bool isElementEnabled(QString id);
93 | QString getElementAttributeValue(QString id, QString name);
94 | bool elementEqualsOther(QString id, QString other);
95 | bool isElementDisplayed(QString id);
96 | QPoint getElementLocation(QString id);
97 | QPoint getElementLocationInView(QString id);
98 | QSize getElementSize(QString id);
99 | QString getElementCssPropertyValue(QString id, QString propertyName);
100 |
101 | QString getOrientation();
102 | void setOrientation(QString orientation);
103 |
104 | QString getAlertText();
105 | void setAlertText(QString text);
106 | void acceptAlert();
107 | void dismissAlert();
108 |
109 | void mouseMoveTo(QString element);
110 | void mouseMoveTo(int xoffset, int yoffset);
111 | void mouseClick(int button);
112 | void mouseButtonDown(int button);
113 | void mouseButtonUp(int button);
114 | void mouseDoubleClick();
115 |
116 | void touchClick(QString element);
117 | void touchDown(int x, int y);
118 | void touchUp(int x, int y);
119 | void touchMove(int x, int y);
120 | void touchScroll(QString element, int xoffset, int yoffset);
121 | void touchScroll(int xoffset, int yoffset);
122 | void touchDoubleClick(QString element);
123 | void touchLongClick(QString element);
124 | void touchFlick(QString element, int xoffset, int yoffset, int speed);
125 | void touchFlick(int xspeed, int yspeed);
126 |
127 | QJsonObject getGeoLocation();
128 | void setGeoLocation(int latitude, int longtude, int alttude);
129 |
130 | QStringList getAllKeysLocalStorage();
131 | void setLocalStorageByKey(QString key, QString value);
132 | void deleteLocalStorage();
133 | QString getLocalStorageValueByKey(QString key);
134 | void deleteLocalStorageByKey(QString key);
135 | int getLocalStorageSize();
136 |
137 | QStringList getAllKeysSessionStorage();
138 | void setSessionStorageByKey(QString key, QString value);
139 | void deleteSessionStorage();
140 | QString getSessionStorageValueByKey(QString key);
141 | void deleteSessionStorageKey(QString key);
142 | int getSessionStorageSize();
143 |
144 | QList getLog(QString type);
145 | QStringList getLogTypes();
146 |
147 | int getApplicationCacheStatus();
148 |
149 | protected:
150 |
151 | void updateCapability(QJsonObject json);
152 |
153 | DesiredCapabilities* m_dc;
154 |
155 | };
156 |
157 | #endif // WEBDRIVERHUB_H
158 |
--------------------------------------------------------------------------------
/selenium/seleniumserverhub.cpp:
--------------------------------------------------------------------------------
1 | #include "seleniumserverhub.h"
2 |
3 | SeleniumServerHub::SeleniumServerHub(QString host, int port) :
4 | QObject()
5 | {
6 | m_result = "";
7 |
8 | buildUrl(host, port);
9 | }
10 |
11 | SeleniumServerHub::~SeleniumServerHub()
12 | {
13 | qDebug()<<"I am destructor SeleniumServerHub!";
14 | }
15 |
16 | QString SeleniumServerHub::host()
17 | {
18 | return m_host;
19 | }
20 |
21 | int SeleniumServerHub::port()
22 | {
23 | return m_port;
24 | }
25 |
26 | //####### PROTECTED #######
27 | void SeleniumServerHub::buildUrl(QString host, int port)
28 | {
29 | m_host = host.replace("http://", "");
30 | m_port = port;
31 |
32 | m_urlHub = "http://";
33 | m_urlHub.append(m_host).append(":").append(QString::number(m_port)).append("/wd/hub/");
34 | }
35 |
36 | QJsonObject SeleniumServerHub::exec(QString url, QByteArray rawBody, int method)
37 | {
38 | m_result = "";
39 | QJsonObject result;
40 |
41 | QUrl urlObject(m_urlHub + url);
42 | QNetworkRequest request(urlObject);
43 |
44 | QString contentType = "application/json";
45 |
46 | QNetworkAccessManager* manager = new QNetworkAccessManager(this);
47 |
48 | if(method == GET) {
49 |
50 | m_reply = manager->get(request);
51 |
52 | } else if(method == POST) {
53 |
54 | if(rawBody.isEmpty()) {
55 |
56 | request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
57 | m_reply = manager->post(request, "");
58 |
59 | } else {
60 |
61 | QByteArray postDataSize = QByteArray::number(rawBody.size());
62 | request.setRawHeader("Content-Type", contentType.toLatin1());
63 | request.setRawHeader("Content-Length", postDataSize);
64 |
65 | m_reply = manager->post(request, rawBody);
66 | }
67 |
68 | } else if(method == DELETE) {
69 |
70 | m_reply = manager->deleteResource(request);
71 |
72 | } else {
73 | throw (new QueleniumException("Unsupported method", 99));
74 | }
75 |
76 | connect(m_reply, SIGNAL(readyRead()), SLOT(slotReplyResponse()));
77 | connect(m_reply, SIGNAL(error(QNetworkReply::NetworkError)), SLOT(slotReplyError()));
78 | connect(m_reply, SIGNAL(finished()), SLOT(slotFinishRequest()));
79 |
80 | //this loop for synchronize requests
81 | QEventLoop loop;
82 | connect(m_reply, SIGNAL(error(QNetworkReply::NetworkError)), &loop, SLOT(quit()));
83 | connect(m_reply, SIGNAL(error(QNetworkReply::NetworkError)), &loop, SLOT(deleteLater()));
84 | connect(m_reply, SIGNAL(finished()), &loop, SLOT(quit()));
85 | loop.exec();
86 |
87 | if(m_result.trimmed().isEmpty()) {
88 | WebDriverException::throwException("Empty reply from server");
89 | }
90 |
91 | result = QJsonDocument::fromJson(m_result.toUtf8()).object();
92 |
93 | if(result["status"].toInt() != ResponseStatusCodes::SUCCESS) {
94 |
95 | QString message = result["state"].toString();
96 | if(result["value"].isObject() && result["value"].toObject()["message"].isString()) {
97 | message = result["value"].toObject()["message"].toString();
98 | }
99 |
100 | WebDriverException::throwException(message, result["status"].toInt());
101 | }
102 |
103 | return result;
104 | }
105 |
106 | QJsonObject SeleniumServerHub::post(QString url, QJsonObject rawBody)
107 | {
108 | QJsonDocument doc;
109 | doc.setObject(rawBody);
110 |
111 | return exec(url, doc.toJson(), POST);
112 | }
113 |
114 | QJsonObject SeleniumServerHub::post(QString url)
115 | {
116 | return exec(url, "", POST);
117 | }
118 |
119 | QJsonObject SeleniumServerHub::get(QString url)
120 | {
121 | return exec(url, "", GET);
122 | }
123 |
124 | QJsonObject SeleniumServerHub::deleteMethod(QString url)
125 | {
126 | return exec(url, "", DELETE);
127 | }
128 |
129 | QString SeleniumServerHub::getValueString(QString s)
130 | {
131 | QJsonObject result = get(s);
132 |
133 | QString value = "";
134 |
135 | if(result["value"].isString()) {
136 | value = result["value"].toString();
137 | } else {
138 | qDebug()<<"Error get string value "<manager()->deleteLater();
229 | m_reply->deleteLater();
230 | }
231 |
232 | //####### SLOTS #######
233 | void SeleniumServerHub::slotFinishRequest()
234 | {
235 | m_reply->close();
236 | releaseReplyResources();
237 |
238 | //qDebug()<<"result: "<readAll()));
244 | }
245 |
246 | void SeleniumServerHub::slotReplyError()
247 | {
248 | releaseReplyResources();
249 |
250 | //qDebug()<<"Error: "<errorString();
251 |
252 | if(m_result.isEmpty()) {
253 |
254 | QJsonObject error;
255 | error["status"] = -1;
256 | error["state"] = m_reply->errorString();
257 |
258 | QJsonDocument jsonDoc;
259 | jsonDoc.setObject(error);
260 |
261 | m_result = jsonDoc.toJson();
262 | }
263 |
264 | }
265 |
--------------------------------------------------------------------------------
/selenium/webdriverexception.h:
--------------------------------------------------------------------------------
1 | #ifndef WEBDRIVEREXCEPTION_H
2 | #define WEBDRIVEREXCEPTION_H
3 |
4 | #include
5 |
6 | #include "queleniumexception.h"
7 |
8 | class WebDriverException : public QueleniumException
9 | {
10 | public:
11 | explicit WebDriverException(QString message, int code = 0):
12 | QueleniumException(message, code)
13 | {}
14 | ~WebDriverException() throw() {}
15 |
16 | static void throwException(QString message, int code = 0);
17 |
18 | void raise() const { throw *this; }
19 | WebDriverException *clone() const { return new WebDriverException(*this); }
20 |
21 | };
22 |
23 | class NoSuchDriverException : public WebDriverException
24 | {
25 | public:
26 | explicit NoSuchDriverException(QString message, int code = 0):
27 | WebDriverException(message, code)
28 | {}
29 | ~NoSuchDriverException() throw() {}
30 | };
31 |
32 | class NoSuchElementException : public WebDriverException
33 | {
34 | public:
35 | explicit NoSuchElementException(QString message, int code = 0):
36 | WebDriverException(message, code)
37 | {}
38 | ~NoSuchElementException() throw() {}
39 | };
40 |
41 | class NoSuchFrameException : public WebDriverException
42 | {
43 | public:
44 | explicit NoSuchFrameException(QString message, int code = 0):
45 | WebDriverException(message, code)
46 | {}
47 | ~NoSuchFrameException() throw() {}
48 | };
49 |
50 | class UnknownCommandException : public WebDriverException
51 | {
52 | public:
53 | explicit UnknownCommandException(QString message, int code = 0):
54 | WebDriverException(message, code)
55 | {}
56 | ~UnknownCommandException() throw() {}
57 | };
58 |
59 | class StaleElementReferenceException : public WebDriverException
60 | {
61 | public:
62 | explicit StaleElementReferenceException(QString message, int code = 0):
63 | WebDriverException(message, code)
64 | {}
65 | ~StaleElementReferenceException() throw() {}
66 | };
67 |
68 | class ElementNotVisibleException : public WebDriverException
69 | {
70 | public:
71 | explicit ElementNotVisibleException(QString message, int code = 0):
72 | WebDriverException(message, code)
73 | {}
74 | ~ElementNotVisibleException() throw() {}
75 | };
76 |
77 | class InvalidElementStateException : public WebDriverException
78 | {
79 | public:
80 | explicit InvalidElementStateException(QString message, int code = 0):
81 | WebDriverException(message, code)
82 | {}
83 | ~InvalidElementStateException() throw() {}
84 | };
85 |
86 | class UnknownErrorException : public WebDriverException
87 | {
88 | public:
89 | explicit UnknownErrorException(QString message, int code = 0):
90 | WebDriverException(message, code)
91 | {}
92 | ~UnknownErrorException() throw() {}
93 | };
94 |
95 | class ElementIsNotSelectableException : public WebDriverException
96 | {
97 | public:
98 | explicit ElementIsNotSelectableException(QString message, int code = 0):
99 | WebDriverException(message, code)
100 | {}
101 | ~ElementIsNotSelectableException() throw() {}
102 | };
103 |
104 | class JavaScriptErrorException : public WebDriverException
105 | {
106 | public:
107 | explicit JavaScriptErrorException(QString message, int code = 0):
108 | WebDriverException(message, code)
109 | {}
110 | ~JavaScriptErrorException() throw() {}
111 | };
112 |
113 | class XpathLookupErrorException : public WebDriverException
114 | {
115 | public:
116 | explicit XpathLookupErrorException(QString message, int code = 0):
117 | WebDriverException(message, code)
118 | {}
119 | ~XpathLookupErrorException() throw() {}
120 | };
121 |
122 | class TimeoutException : public WebDriverException
123 | {
124 | public:
125 | explicit TimeoutException(QString message, int code = 0):
126 | WebDriverException(message, code)
127 | {}
128 | ~TimeoutException() throw() {}
129 | };
130 |
131 | class NoSuchWindowException : public WebDriverException
132 | {
133 | public:
134 | explicit NoSuchWindowException(QString message, int code = 0):
135 | WebDriverException(message, code)
136 | {}
137 | ~NoSuchWindowException() throw() {}
138 | };
139 |
140 | class InvalidCookieDomainException : public WebDriverException
141 | {
142 | public:
143 | explicit InvalidCookieDomainException(QString message, int code = 0):
144 | WebDriverException(message, code)
145 | {}
146 | ~InvalidCookieDomainException() throw() {}
147 | };
148 |
149 | class UnableToSetCookieException : public WebDriverException
150 | {
151 | public:
152 | explicit UnableToSetCookieException(QString message, int code = 0):
153 | WebDriverException(message, code)
154 | {}
155 | ~UnableToSetCookieException() throw() {}
156 | };
157 |
158 | class UnexpectedAlertOpenException : public WebDriverException
159 | {
160 | public:
161 | explicit UnexpectedAlertOpenException(QString message, int code = 0):
162 | WebDriverException(message, code)
163 | {}
164 | ~UnexpectedAlertOpenException() throw() {}
165 | };
166 |
167 | class NoAlertOpenErrorException : public WebDriverException
168 | {
169 | public:
170 | explicit NoAlertOpenErrorException(QString message, int code = 0):
171 | WebDriverException(message, code)
172 | {}
173 | ~NoAlertOpenErrorException() throw() {}
174 | };
175 |
176 | class ScriptTimeoutException : public WebDriverException
177 | {
178 | public:
179 | explicit ScriptTimeoutException(QString message, int code = 0):
180 | WebDriverException(message, code)
181 | {}
182 | ~ScriptTimeoutException() throw() {}
183 | };
184 |
185 | class InvalidElementCoordinatesException : public WebDriverException
186 | {
187 | public:
188 | explicit InvalidElementCoordinatesException(QString message, int code = 0):
189 | WebDriverException(message, code)
190 | {}
191 | ~InvalidElementCoordinatesException() throw() {}
192 | };
193 |
194 | class ImeNotAvailableException : public WebDriverException
195 | {
196 | public:
197 | explicit ImeNotAvailableException(QString message, int code = 0):
198 | WebDriverException(message, code)
199 | {}
200 | ~ImeNotAvailableException() throw() {}
201 | };
202 |
203 | class ImeEngineActivationFailedException : public WebDriverException
204 | {
205 | public:
206 | explicit ImeEngineActivationFailedException(QString message, int code = 0):
207 | WebDriverException(message, code)
208 | {}
209 | ~ImeEngineActivationFailedException() throw() {}
210 | };
211 |
212 | class InvalidSelectorException : public WebDriverException
213 | {
214 | public:
215 | explicit InvalidSelectorException(QString message, int code = 0):
216 | WebDriverException(message, code)
217 | {}
218 | ~InvalidSelectorException() throw() {}
219 | };
220 |
221 | class SessionNotCreatedException : public WebDriverException
222 | {
223 | public:
224 | explicit SessionNotCreatedException(QString message, int code = 0):
225 | WebDriverException(message, code)
226 | {}
227 | ~SessionNotCreatedException() throw() {}
228 | };
229 |
230 | class MoveTargetOutOfBoundsException : public WebDriverException
231 | {
232 | public:
233 | explicit MoveTargetOutOfBoundsException(QString message, int code = 0):
234 | WebDriverException(message, code)
235 | {}
236 | ~MoveTargetOutOfBoundsException() throw() {}
237 | };
238 |
239 | #endif // WEBDRIVEREXCEPTION_H
240 |
--------------------------------------------------------------------------------
/tests/queleniumtest.h:
--------------------------------------------------------------------------------
1 | #ifndef QUELENIUMTEST_H
2 | #define QUELENIUMTEST_H
3 |
4 | #include
5 | #include
6 |
7 | #include
8 | #include
9 | #include
10 |
11 | class QueleniumTest : public QObject
12 | {
13 | Q_OBJECT
14 | public:
15 | QueleniumTest();
16 |
17 | private:
18 |
19 | enum MOUSE_BUTTON_EVENTS {
20 | CLICK,
21 | DOWN,
22 | UP,
23 | CLICK_DOUBLE,
24 | };
25 |
26 | WebDriver* driver;
27 | typedef QList Elements;
28 |
29 | int checkAllCookies();
30 | void compareCookie(Cookie* original, Cookie* tested, QString defaultPath = "", QString defaultDomain = "");
31 | void notFoundWindow();
32 | void mouseButtonEvents(QString text, int event, int button = -1);
33 |
34 | QString m_testUrl;
35 | QString m_host;
36 | int m_port;
37 |
38 | private Q_SLOTS:
39 |
40 | /**
41 | * WebDriver Test Cases
42 | */
43 | void getCase1();
44 | void getCase2();
45 | void titleCase1();
46 | void pageSourceCase1();
47 | void windowHandleCase1();
48 | void windowHandlesCase1();
49 | void windowHandlesCase2();
50 | void findElementCase1();
51 | void findElementCase2();
52 | void findElementCase3();
53 | void findElementCase4();
54 | void findElementCase5();
55 | void findElementCase6();
56 | void findElementCase7();
57 | void findElementCase8();
58 | void findElementsCase1();
59 | //void closeCase1();//in future
60 |
61 | /**
62 | * Navigation Test Cases
63 | */
64 | void navigateBackCase();
65 | void navigateForwardCase();
66 | void navigateRefreshCase();
67 | void navigateToCase1();
68 | void navigateToCase2();
69 |
70 | /**
71 | * Manage Test Cases
72 | */
73 | void manageCookiesCase();
74 | void manageCookieNamedCase();
75 | void manageDeleteAllCookiesCase();
76 | void manageDeleteCookieCase();
77 | void manageDeleteCookieNamedCase();
78 | void manageAddCookieCase();
79 |
80 | /**
81 | * Window Test Cases
82 | */
83 | void windowSizeCase();
84 | void windowSetSizeCase1();
85 | void windowSetSizeCase2();
86 | void windowMaximizeCase();
87 | void windowPositionCase();
88 | void windowSetPositionCase1();
89 | void windowSetPositionCase2();
90 | //void windowCloseCase(); //in future
91 | //void windowOpenNewTabCase(); //in future
92 | //void windowOpenNewWindowCase();//in future
93 |
94 | /**
95 | * Timeouts Test Cases
96 | */
97 | void timeoutsSetScriptTimeoutCase();
98 | void timeoutsPageLoadTimeoutCase();
99 | void timeoutsImplicitlyWaitCase();
100 |
101 | /**
102 | * ImeHandler Test Cases
103 | */
104 | void imeGetAvailableEnginesCase();
105 | void imeGetActiveEngineCase();
106 | void imeActivateEngineCase();
107 | void imeDeactivateCase();
108 | void imeIsActivatedCase();
109 |
110 | /**
111 | * Logs Test Cases
112 | */
113 | void logsGetAvailableLogTypesCase();
114 | void logsGetCase();
115 |
116 | /**
117 | * Mouse Test Cases
118 | */
119 | void mouseMoveToCase1();
120 | void mouseMoveToCase2();
121 | void mouseMoveToCase3();
122 | void mouseClickCase1();
123 | void mouseClickCase2();
124 | void mouseClickCase3();
125 | void mouseClickCase4();
126 | void mouseButtonDownCase1();
127 | void mouseButtonDownCase2();
128 | void mouseButtonDownCase3();
129 | void mouseButtonDownCase4();
130 | void mouseButtonUpCase1();
131 | void mouseButtonUpCase2();
132 | void mouseButtonUpCase3();
133 | void mouseButtonUpCase4();
134 | void mouseDoubleClickCase1();
135 |
136 | /**
137 | * WebDriver Exceptions Test Cases
138 | */
139 | void getEmptyExceptionCase1();
140 | void getEmptyExceptionCase2();
141 | void getNoSuchWindowExceptionCase1();
142 | void getNoSuchWindowExceptionCase2();
143 | void titleNoSuchWindowExceptionCase1();
144 | void pageSourceNoSuchWindowExceptionCase1();
145 | void windowHandleNoSuchWindowExceptionCase1();
146 | void windowHandlesNoSuchWindowExceptionCase1();
147 | void findElementNoSuchWindowExceptionCase1();
148 | void findElementNoSuchWindowExceptionCase2();
149 | void findElementNoSuchWindowExceptionCase3();
150 | void findElementNoSuchWindowExceptionCase4();
151 | void findElementNoSuchWindowExceptionCase5();
152 | void findElementNoSuchWindowExceptionCase6();
153 | void findElementNoSuchWindowExceptionCase7();
154 | void findElementNoSuchWindowExceptionCase8();
155 | void findElementNoSuchElementExceptionCase1();
156 | void findElementNoSuchElementExceptionCase2();
157 | void findElementNoSuchElementExceptionCase3();
158 | void findElementNoSuchElementExceptionCase4();
159 | void findElementNoSuchElementExceptionCase5();
160 | void findElementNoSuchElementExceptionCase6();
161 | void findElementNoSuchElementExceptionCase7();
162 | void findElementNoSuchElementExceptionCase8();
163 | void findElementInvalidSelectorExceptionCase1();
164 | void findElementInvalidSelectorExceptionCase2();
165 |
166 | /**
167 | * Select Test Cases
168 | */
169 | void selectIsMultiCase1();
170 | void selectIsMultiCase2();
171 | void selectOptionsCase1();
172 | void selectAllSelectedOptionsCase1();
173 | void selectAllSelectedOptionsCase2();
174 | void selectFirstSelectedOptionCase1();
175 | void selectFirstSelectedOptionCase2();
176 | void selectByVisibleTextCase1();
177 | void selectByVisibleTextCase2();
178 | void selectByIndexCase1();
179 | void selectByIndexCase2();
180 | void selectByValueCase1();
181 | void selectByValueCase2();
182 | void selectDeselectAllCase1();
183 | void selectDeselectByValueCase1();
184 | void selectDeselectByIndexCase1();
185 | void selectDeselectByVisibleTextCase1();
186 |
187 | /**
188 | * Select Exceptions Test Cases
189 | */
190 | void selectWebDriverExceptionCase1();
191 | void selectFirstSelectedOptionNoSuchElementCase1();
192 | void selectByVisibleTextNoSuchElementCase1();
193 | void selectByVisibleTextNoSuchElementCase2();
194 | void selectByIndexNoSuchElementCase1();
195 | void selectByIndexNoSuchElementCase2();
196 | void selectByValueNoSuchElementCase1();
197 | void selectByValueNoSuchElementCase2();
198 | void selectDeselectAllWebDriverExceptionCase1();
199 | void selectDeselectByValueWebDriverExceptionCase1();
200 | void selectDeselectByIndexWebDriverExceptionCase1();
201 | void selectDeselectByVisibleTextWebDriverExceptionCase1();
202 |
203 | /**
204 | * Alert Test Cases
205 | */
206 | void alertDismissCase1();
207 | void alertDismissCase2();
208 | void alertAcceptCase1();
209 | void alertAcceptCase2();
210 | void alertTextCase1();
211 | void alertTextCase2();
212 | void alertSendKeysCase();
213 |
214 | /**
215 | * Alert Exceptions Test Cases
216 | */
217 | void alertDismissNoAlertPresentCase1();
218 | void alertAcceptNoAlertPresentCase1();
219 | void alertTextNoAlertPresentCase1();
220 | void alertSendKeysNoAlertPresentCase1();
221 | void alertSendKeysElementNotVisibleExceptionCase1();
222 |
223 | /**
224 | * Server Test Cases
225 | */
226 | void serverStatusCase();
227 | void serverSessionsCase();
228 |
229 | void init();
230 | void cleanup();
231 |
232 | };
233 |
234 | #endif // QUELENIUMTEST_H
235 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 2, June 1991
3 |
4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6 | Everyone is permitted to copy and distribute verbatim copies
7 | of this license document, but changing it is not allowed.
8 |
9 | Preamble
10 |
11 | The licenses for most software are designed to take away your
12 | freedom to share and change it. By contrast, the GNU General Public
13 | License is intended to guarantee your freedom to share and change free
14 | software--to make sure the software is free for all its users. This
15 | General Public License applies to most of the Free Software
16 | Foundation's software and to any other program whose authors commit to
17 | using it. (Some other Free Software Foundation software is covered by
18 | the GNU Lesser General Public License instead.) You can apply it to
19 | your programs, too.
20 |
21 | When we speak of free software, we are referring to freedom, not
22 | price. Our General Public Licenses are designed to make sure that you
23 | have the freedom to distribute copies of free software (and charge for
24 | this service if you wish), that you receive source code or can get it
25 | if you want it, that you can change the software or use pieces of it
26 | in new free programs; and that you know you can do these things.
27 |
28 | To protect your rights, we need to make restrictions that forbid
29 | anyone to deny you these rights or to ask you to surrender the rights.
30 | These restrictions translate to certain responsibilities for you if you
31 | distribute copies of the software, or if you modify it.
32 |
33 | For example, if you distribute copies of such a program, whether
34 | gratis or for a fee, you must give the recipients all the rights that
35 | you have. You must make sure that they, too, receive or can get the
36 | source code. And you must show them these terms so they know their
37 | rights.
38 |
39 | We protect your rights with two steps: (1) copyright the software, and
40 | (2) offer you this license which gives you legal permission to copy,
41 | distribute and/or modify the software.
42 |
43 | Also, for each author's protection and ours, we want to make certain
44 | that everyone understands that there is no warranty for this free
45 | software. If the software is modified by someone else and passed on, we
46 | want its recipients to know that what they have is not the original, so
47 | that any problems introduced by others will not reflect on the original
48 | authors' reputations.
49 |
50 | Finally, any free program is threatened constantly by software
51 | patents. We wish to avoid the danger that redistributors of a free
52 | program will individually obtain patent licenses, in effect making the
53 | program proprietary. To prevent this, we have made it clear that any
54 | patent must be licensed for everyone's free use or not licensed at all.
55 |
56 | The precise terms and conditions for copying, distribution and
57 | modification follow.
58 |
59 | GNU GENERAL PUBLIC LICENSE
60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61 |
62 | 0. This License applies to any program or other work which contains
63 | a notice placed by the copyright holder saying it may be distributed
64 | under the terms of this General Public License. The "Program", below,
65 | refers to any such program or work, and a "work based on the Program"
66 | means either the Program or any derivative work under copyright law:
67 | that is to say, a work containing the Program or a portion of it,
68 | either verbatim or with modifications and/or translated into another
69 | language. (Hereinafter, translation is included without limitation in
70 | the term "modification".) Each licensee is addressed as "you".
71 |
72 | Activities other than copying, distribution and modification are not
73 | covered by this License; they are outside its scope. The act of
74 | running the Program is not restricted, and the output from the Program
75 | is covered only if its contents constitute a work based on the
76 | Program (independent of having been made by running the Program).
77 | Whether that is true depends on what the Program does.
78 |
79 | 1. You may copy and distribute verbatim copies of the Program's
80 | source code as you receive it, in any medium, provided that you
81 | conspicuously and appropriately publish on each copy an appropriate
82 | copyright notice and disclaimer of warranty; keep intact all the
83 | notices that refer to this License and to the absence of any warranty;
84 | and give any other recipients of the Program a copy of this License
85 | along with the Program.
86 |
87 | You may charge a fee for the physical act of transferring a copy, and
88 | you may at your option offer warranty protection in exchange for a fee.
89 |
90 | 2. You may modify your copy or copies of the Program or any portion
91 | of it, thus forming a work based on the Program, and copy and
92 | distribute such modifications or work under the terms of Section 1
93 | above, provided that you also meet all of these conditions:
94 |
95 | a) You must cause the modified files to carry prominent notices
96 | stating that you changed the files and the date of any change.
97 |
98 | b) You must cause any work that you distribute or publish, that in
99 | whole or in part contains or is derived from the Program or any
100 | part thereof, to be licensed as a whole at no charge to all third
101 | parties under the terms of this License.
102 |
103 | c) If the modified program normally reads commands interactively
104 | when run, you must cause it, when started running for such
105 | interactive use in the most ordinary way, to print or display an
106 | announcement including an appropriate copyright notice and a
107 | notice that there is no warranty (or else, saying that you provide
108 | a warranty) and that users may redistribute the program under
109 | these conditions, and telling the user how to view a copy of this
110 | License. (Exception: if the Program itself is interactive but
111 | does not normally print such an announcement, your work based on
112 | the Program is not required to print an announcement.)
113 |
114 | These requirements apply to the modified work as a whole. If
115 | identifiable sections of that work are not derived from the Program,
116 | and can be reasonably considered independent and separate works in
117 | themselves, then this License, and its terms, do not apply to those
118 | sections when you distribute them as separate works. But when you
119 | distribute the same sections as part of a whole which is a work based
120 | on the Program, the distribution of the whole must be on the terms of
121 | this License, whose permissions for other licensees extend to the
122 | entire whole, and thus to each and every part regardless of who wrote it.
123 |
124 | Thus, it is not the intent of this section to claim rights or contest
125 | your rights to work written entirely by you; rather, the intent is to
126 | exercise the right to control the distribution of derivative or
127 | collective works based on the Program.
128 |
129 | In addition, mere aggregation of another work not based on the Program
130 | with the Program (or with a work based on the Program) on a volume of
131 | a storage or distribution medium does not bring the other work under
132 | the scope of this License.
133 |
134 | 3. You may copy and distribute the Program (or a work based on it,
135 | under Section 2) in object code or executable form under the terms of
136 | Sections 1 and 2 above provided that you also do one of the following:
137 |
138 | a) Accompany it with the complete corresponding machine-readable
139 | source code, which must be distributed under the terms of Sections
140 | 1 and 2 above on a medium customarily used for software interchange; or,
141 |
142 | b) Accompany it with a written offer, valid for at least three
143 | years, to give any third party, for a charge no more than your
144 | cost of physically performing source distribution, a complete
145 | machine-readable copy of the corresponding source code, to be
146 | distributed under the terms of Sections 1 and 2 above on a medium
147 | customarily used for software interchange; or,
148 |
149 | c) Accompany it with the information you received as to the offer
150 | to distribute corresponding source code. (This alternative is
151 | allowed only for noncommercial distribution and only if you
152 | received the program in object code or executable form with such
153 | an offer, in accord with Subsection b above.)
154 |
155 | The source code for a work means the preferred form of the work for
156 | making modifications to it. For an executable work, complete source
157 | code means all the source code for all modules it contains, plus any
158 | associated interface definition files, plus the scripts used to
159 | control compilation and installation of the executable. However, as a
160 | special exception, the source code distributed need not include
161 | anything that is normally distributed (in either source or binary
162 | form) with the major components (compiler, kernel, and so on) of the
163 | operating system on which the executable runs, unless that component
164 | itself accompanies the executable.
165 |
166 | If distribution of executable or object code is made by offering
167 | access to copy from a designated place, then offering equivalent
168 | access to copy the source code from the same place counts as
169 | distribution of the source code, even though third parties are not
170 | compelled to copy the source along with the object code.
171 |
172 | 4. You may not copy, modify, sublicense, or distribute the Program
173 | except as expressly provided under this License. Any attempt
174 | otherwise to copy, modify, sublicense or distribute the Program is
175 | void, and will automatically terminate your rights under this License.
176 | However, parties who have received copies, or rights, from you under
177 | this License will not have their licenses terminated so long as such
178 | parties remain in full compliance.
179 |
180 | 5. You are not required to accept this License, since you have not
181 | signed it. However, nothing else grants you permission to modify or
182 | distribute the Program or its derivative works. These actions are
183 | prohibited by law if you do not accept this License. Therefore, by
184 | modifying or distributing the Program (or any work based on the
185 | Program), you indicate your acceptance of this License to do so, and
186 | all its terms and conditions for copying, distributing or modifying
187 | the Program or works based on it.
188 |
189 | 6. Each time you redistribute the Program (or any work based on the
190 | Program), the recipient automatically receives a license from the
191 | original licensor to copy, distribute or modify the Program subject to
192 | these terms and conditions. You may not impose any further
193 | restrictions on the recipients' exercise of the rights granted herein.
194 | You are not responsible for enforcing compliance by third parties to
195 | this License.
196 |
197 | 7. If, as a consequence of a court judgment or allegation of patent
198 | infringement or for any other reason (not limited to patent issues),
199 | conditions are imposed on you (whether by court order, agreement or
200 | otherwise) that contradict the conditions of this License, they do not
201 | excuse you from the conditions of this License. If you cannot
202 | distribute so as to satisfy simultaneously your obligations under this
203 | License and any other pertinent obligations, then as a consequence you
204 | may not distribute the Program at all. For example, if a patent
205 | license would not permit royalty-free redistribution of the Program by
206 | all those who receive copies directly or indirectly through you, then
207 | the only way you could satisfy both it and this License would be to
208 | refrain entirely from distribution of the Program.
209 |
210 | If any portion of this section is held invalid or unenforceable under
211 | any particular circumstance, the balance of the section is intended to
212 | apply and the section as a whole is intended to apply in other
213 | circumstances.
214 |
215 | It is not the purpose of this section to induce you to infringe any
216 | patents or other property right claims or to contest validity of any
217 | such claims; this section has the sole purpose of protecting the
218 | integrity of the free software distribution system, which is
219 | implemented by public license practices. Many people have made
220 | generous contributions to the wide range of software distributed
221 | through that system in reliance on consistent application of that
222 | system; it is up to the author/donor to decide if he or she is willing
223 | to distribute software through any other system and a licensee cannot
224 | impose that choice.
225 |
226 | This section is intended to make thoroughly clear what is believed to
227 | be a consequence of the rest of this License.
228 |
229 | 8. If the distribution and/or use of the Program is restricted in
230 | certain countries either by patents or by copyrighted interfaces, the
231 | original copyright holder who places the Program under this License
232 | may add an explicit geographical distribution limitation excluding
233 | those countries, so that distribution is permitted only in or among
234 | countries not thus excluded. In such case, this License incorporates
235 | the limitation as if written in the body of this License.
236 |
237 | 9. The Free Software Foundation may publish revised and/or new versions
238 | of the General Public License from time to time. Such new versions will
239 | be similar in spirit to the present version, but may differ in detail to
240 | address new problems or concerns.
241 |
242 | Each version is given a distinguishing version number. If the Program
243 | specifies a version number of this License which applies to it and "any
244 | later version", you have the option of following the terms and conditions
245 | either of that version or of any later version published by the Free
246 | Software Foundation. If the Program does not specify a version number of
247 | this License, you may choose any version ever published by the Free Software
248 | Foundation.
249 |
250 | 10. If you wish to incorporate parts of the Program into other free
251 | programs whose distribution conditions are different, write to the author
252 | to ask for permission. For software which is copyrighted by the Free
253 | Software Foundation, write to the Free Software Foundation; we sometimes
254 | make exceptions for this. Our decision will be guided by the two goals
255 | of preserving the free status of all derivatives of our free software and
256 | of promoting the sharing and reuse of software generally.
257 |
258 | NO WARRANTY
259 |
260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268 | REPAIR OR CORRECTION.
269 |
270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278 | POSSIBILITY OF SUCH DAMAGES.
279 |
280 | END OF TERMS AND CONDITIONS
281 |
282 | How to Apply These Terms to Your New Programs
283 |
284 | If you develop a new program, and you want it to be of the greatest
285 | possible use to the public, the best way to achieve this is to make it
286 | free software which everyone can redistribute and change under these terms.
287 |
288 | To do so, attach the following notices to the program. It is safest
289 | to attach them to the start of each source file to most effectively
290 | convey the exclusion of warranty; and each file should have at least
291 | the "copyright" line and a pointer to where the full notice is found.
292 |
293 | {description}
294 | Copyright (C) {year} {fullname}
295 |
296 | This program is free software; you can redistribute it and/or modify
297 | it under the terms of the GNU General Public License as published by
298 | the Free Software Foundation; either version 2 of the License, or
299 | (at your option) any later version.
300 |
301 | This program is distributed in the hope that it will be useful,
302 | but WITHOUT ANY WARRANTY; without even the implied warranty of
303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
304 | GNU General Public License for more details.
305 |
306 | You should have received a copy of the GNU General Public License along
307 | with this program; if not, write to the Free Software Foundation, Inc.,
308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
309 |
310 | Also add information on how to contact you by electronic and paper mail.
311 |
312 | If the program is interactive, make it output a short notice like this
313 | when it starts in an interactive mode:
314 |
315 | Gnomovision version 69, Copyright (C) year name of author
316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
317 | This is free software, and you are welcome to redistribute it
318 | under certain conditions; type `show c' for details.
319 |
320 | The hypothetical commands `show w' and `show c' should show the appropriate
321 | parts of the General Public License. Of course, the commands you use may
322 | be called something other than `show w' and `show c'; they could even be
323 | mouse-clicks or menu items--whatever suits your program.
324 |
325 | You should also get your employer (if you work as a programmer) or your
326 | school, if any, to sign a "copyright disclaimer" for the program, if
327 | necessary. Here is a sample; alter the names:
328 |
329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program
330 | `Gnomovision' (which makes passes at compilers) written by James Hacker.
331 |
332 | {signature of Ty Coon}, 1 April 1989
333 | Ty Coon, President of Vice
334 |
335 | This General Public License does not permit incorporating your program into
336 | proprietary programs. If your program is a subroutine library, you may
337 | consider it more useful to permit linking proprietary applications with the
338 | library. If this is what you want to do, use the GNU Lesser General
339 | Public License instead of this License.
340 |
341 |
--------------------------------------------------------------------------------
/tests/queleniumtest.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | #include "queleniumtest.h"
5 |
6 | QueleniumTest::QueleniumTest()
7 | {
8 | }
9 |
10 | /**
11 | * Before Test Case
12 | */
13 | void QueleniumTest::init()
14 | {
15 | //This local web server for easy testing
16 | m_testUrl = "quelenium.local.test";
17 | m_host = "192.168.53.147";
18 | m_port = 4444;
19 |
20 | Proxy *proxy = new Proxy(Proxy::DIRECT);
21 | DesiredCapabilities *cap = new DesiredCapabilities(Browser::FIREFOX);
22 | cap->setProxy(proxy);
23 |
24 | try {
25 | driver = new WebDriver(m_host, m_port, cap);
26 | } catch (WebDriverException* e) {
27 | QFAIL(e->message().toUtf8());
28 | }
29 | }
30 |
31 | /**
32 | * After Test Case
33 | */
34 | void QueleniumTest::cleanup()
35 | {
36 | driver->quit();
37 | }
38 |
39 | /**
40 | * Check all cookies
41 | */
42 | int QueleniumTest::checkAllCookies()
43 | {
44 | QList list = driver->manage()->cookies();
45 |
46 | int result = 0;
47 | for(int i = 0; i < list.size(); i++) {
48 |
49 | result += ((list.at(i)->name() == "CookieTest1") ? 1 : 0);
50 | result += ((list.at(i)->name() == "CookieTest2") ? 1 : 0);
51 | result += ((list.at(i)->name() == "CookieTest3") ? 1 : 0);
52 | result += ((list.at(i)->name() == "TEST1") ? 1 : 0);
53 | result += ((list.at(i)->name() == "TEST2") ? 1 : 0);
54 | result += ((list.at(i)->name() == "TEST3") ? 1 : 0);
55 | result += ((list.at(i)->name() == "TEST4") ? 1 : 0);
56 | result += ((list.at(i)->name() == "TEST5") ? 1 : 0);
57 | result += ((list.at(i)->name() == "TEST6") ? 1 : 0);
58 | }
59 |
60 | return result;
61 | }
62 |
63 | void QueleniumTest::compareCookie(Cookie *original, Cookie *tested, QString defaultPath, QString defaultDomain)
64 | {
65 | qDebug()<name()<<" >> "<name();
66 |
67 | QCOMPARE(original->name(), tested->name());
68 | QCOMPARE(original->value(), tested->value());
69 | QCOMPARE(defaultPath.isEmpty() ? original->path(): defaultPath, tested->path());
70 | QCOMPARE(defaultDomain.isEmpty() ? original->domain(): defaultDomain, tested->domain());
71 | QCOMPARE(original->expiry(), tested->expiry());
72 | QCOMPARE(original->isHttpOnly(), tested->isHttpOnly());
73 | QCOMPARE(original->isSecure(), tested->isSecure());
74 | }
75 |
76 | void QueleniumTest::notFoundWindow()
77 | {
78 | QString windowHandle = driver->windowHandle();
79 | driver->switchTo()->window(windowHandle);
80 |
81 | WebElement* elm = driver->findElement(By::tagName("body"));
82 | elm->sendKeys(Keys::CONTROL + "n");//open new window
83 |
84 | driver->close();
85 | }
86 |
87 | void QueleniumTest::mouseButtonEvents(QString text, int event, int button)
88 | {
89 | driver->get(m_testUrl + "/mouse/click.html");
90 | driver->manage()->window()->maximize();
91 |
92 | //TODO change to WebDriver Wait in future
93 | QThread::sleep(2);
94 |
95 | WebElement* elm1 = driver->findElement(By::id("element1"));
96 | driver->actions()->mouse()->moveTo(elm1);
97 |
98 | switch (event) {
99 | case CLICK:
100 | if(button == -1) {
101 | driver->actions()->mouse()->click();
102 | } else {
103 | driver->actions()->mouse()->click(button);
104 | }
105 | break;
106 |
107 | case DOWN:
108 | if(button == -1) {
109 | driver->actions()->mouse()->buttondown();
110 | } else {
111 | driver->actions()->mouse()->buttondown(button);
112 |
113 | }
114 | break;
115 |
116 | case UP:
117 | if(button == -1) {
118 | driver->actions()->mouse()->buttondown();
119 | driver->actions()->mouse()->buttonup();
120 | } else {
121 | driver->actions()->mouse()->buttondown(button);
122 | driver->actions()->mouse()->buttonup(button);
123 |
124 | }
125 | break;
126 |
127 | case CLICK_DOUBLE:
128 | driver->actions()->mouse()->doubleclick();
129 | break;
130 | default:
131 | QFAIL(QString("Unknown button event").toUtf8());
132 | break;
133 | }
134 |
135 | WebElement* elm2 = driver->findElement(By::id("element2"));
136 | QCOMPARE(elm2->text(), QString(text));
137 | }
138 |
139 | /******** DRIVER TESTS ************************************************************************************************/
140 | /**
141 | * void driver->get(QString)
142 | */
143 | void QueleniumTest::getCase1()
144 | {
145 | driver->get(m_testUrl);
146 |
147 | QCOMPARE(driver->currentUrl(), "http://" + m_testUrl + "/");
148 | }
149 |
150 | /**
151 | * void driver->get(QUrl)
152 | */
153 | void QueleniumTest::getCase2()
154 | {
155 | QUrl url(m_testUrl);
156 | driver->get(url);
157 |
158 | QCOMPARE(driver->currentUrl(), "http://" + m_testUrl + "/");
159 | }
160 |
161 | /**
162 | * QString driver->title()
163 | */
164 | void QueleniumTest::titleCase1()
165 | {
166 | driver->get(m_testUrl);
167 |
168 | QCOMPARE(driver->title(), QString("Quelenium Local Test"));
169 | }
170 |
171 | /**
172 | * QString driver->pageSource()
173 | */
174 | void QueleniumTest::pageSourceCase1()
175 | {
176 | driver->get(m_testUrl + "/page_source/case1.html");
177 | QString source = driver->pageSource();
178 |
179 | QVERIFY(!source.isNull());
180 | QVERIFY(!source.isEmpty());
181 | QVERIFY(source.contains("Page Source - Case 1Test