├── Keys ├── Proxy ├── WebDriver ├── BrowserType ├── QueleniumException ├── WebDriverException ├── tests ├── html_for_tests │ ├── .gitignore │ ├── page_source │ │ └── case1.html │ ├── 404.html │ ├── navigate │ │ ├── back_forward.html │ │ └── refresh.html │ ├── cookie │ │ └── case.html │ ├── mouse │ │ ├── move_to.html │ │ └── click.html │ ├── alert │ │ └── alert.html │ └── index.html ├── tests.pro ├── queleniumtest.h └── queleniumtest.cpp ├── DesiredCapabilities ├── .gitignore ├── selenium ├── logentry.cpp ├── actions.cpp ├── actions.h ├── alert.cpp ├── alert.h ├── logs.h ├── imehandler.h ├── logentry.h ├── navigation.cpp ├── navigation.h ├── targetlocator.h ├── imehandler.cpp ├── by.h ├── timeouts.h ├── mouse.cpp ├── logs.cpp ├── mouse.h ├── window.h ├── window.cpp ├── queleniumexception.h ├── select.h ├── unexpectedalertbehaviour.h ├── options.h ├── webelement.h ├── touch.h ├── timeouts.cpp ├── targetlocator.cpp ├── desiredcapabilities.cpp ├── proxy.h ├── by.cpp ├── responsestatuscodes.h ├── cookie.h ├── selenium.pro ├── webdriver.h ├── platform.h ├── touch.cpp ├── seleniumserverhub.h ├── webelement.cpp ├── server.h ├── browser.h ├── keys.h ├── keys.cpp ├── proxy.cpp ├── options.cpp ├── cookie.cpp ├── server.cpp ├── webdriver.cpp ├── webdriverexception.cpp ├── desiredcapabilities.h ├── select.cpp ├── webdriverhub.h ├── seleniumserverhub.cpp └── webdriverexception.h ├── Quelenium.pro ├── README.md └── LICENSE /Keys: -------------------------------------------------------------------------------- 1 | #include "selenium/keys.h" -------------------------------------------------------------------------------- /Proxy: -------------------------------------------------------------------------------- 1 | #include "selenium/proxy.h" 2 | -------------------------------------------------------------------------------- /WebDriver: -------------------------------------------------------------------------------- 1 | #include "selenium/webdriver.h" -------------------------------------------------------------------------------- /BrowserType: -------------------------------------------------------------------------------- 1 | #include "selenium/browsertype.h" 2 | -------------------------------------------------------------------------------- /QueleniumException: -------------------------------------------------------------------------------- 1 | #include "selenium/queleniumexception.h" -------------------------------------------------------------------------------- /WebDriverException: -------------------------------------------------------------------------------- 1 | #include "selenium/webdriverexception.h" -------------------------------------------------------------------------------- /tests/html_for_tests/.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /DesiredCapabilities: -------------------------------------------------------------------------------- 1 | #include "selenium/desiredcapabilities.h" 2 | -------------------------------------------------------------------------------- /tests/html_for_tests/page_source/case1.html: -------------------------------------------------------------------------------- 1 | Page Source - Case 1Test -------------------------------------------------------------------------------- /tests/html_for_tests/404.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 404 5 | 6 | 7 | 404 8 | 9 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | bin/ 3 | build/ 4 | Makefile 5 | *.user 6 | *.a 7 | tests/bin/ 8 | tests/build/ 9 | tests/Makefile 10 | tests/*.user 11 | *.autosave 12 | -------------------------------------------------------------------------------- /tests/html_for_tests/navigate/back_forward.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | This navigateForwardCase navigateBackCase 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /selenium/logentry.cpp: -------------------------------------------------------------------------------- 1 | #include "logentry.h" 2 | 3 | LogEntry::LogEntry(QString level, int timestamp, QString message) : 4 | m_level(level), 5 | m_timestamp(timestamp), 6 | m_message(message) 7 | { 8 | } 9 | -------------------------------------------------------------------------------- /selenium/actions.cpp: -------------------------------------------------------------------------------- 1 | #include "actions.h" 2 | #include "webdriverhub.h" 3 | 4 | 5 | Mouse* Actions::mouse() 6 | { 7 | return new Mouse(m_hub); 8 | } 9 | 10 | Touch* Actions::touch() 11 | { 12 | return new Touch(m_hub); 13 | } 14 | -------------------------------------------------------------------------------- /Quelenium.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = subdirs 2 | SUBDIRS += selenium 3 | 4 | OTHER_FILES += \ 5 | BrowserType \ 6 | DesiredCapabilities \ 7 | Keys \ 8 | Proxy \ 9 | QueleniumException \ 10 | WebDriver \ 11 | WebDriverException \ 12 | README.md 13 | -------------------------------------------------------------------------------- /tests/html_for_tests/cookie/case.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Test cookie 5 | 6 | 7 | 12 | 13 | -------------------------------------------------------------------------------- /selenium/actions.h: -------------------------------------------------------------------------------- 1 | #ifndef ACTIONS_H 2 | #define ACTIONS_H 3 | 4 | #include "mouse.h" 5 | #include "touch.h" 6 | 7 | class WebDriverHub; 8 | class Actions 9 | { 10 | public: 11 | explicit Actions(WebDriverHub* hub) : m_hub(hub) {} 12 | 13 | Mouse* mouse(); 14 | Touch* touch(); 15 | 16 | private: 17 | WebDriverHub* m_hub; 18 | }; 19 | 20 | #endif // ACTIONS_H 21 | -------------------------------------------------------------------------------- /tests/html_for_tests/navigate/refresh.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Quelenium for Selenium Server Standalone 2 | Qt library for Selenium Server Standalone (http://www.seleniumhq.org/) 3 | 4 | ## Version 5 | 0.2b 6 | 7 | ## Using 8 | 9 | ``` 10 | #include 11 | #include 12 | ... 13 | WebDriver* driver = new WebDriver("127.0.0.1", 4444, Browser::FIREFOX); 14 | ``` 15 | For more use cases, please look tests directory 16 | -------------------------------------------------------------------------------- /selenium/alert.cpp: -------------------------------------------------------------------------------- 1 | #include "alert.h" 2 | #include "webdriverhub.h" 3 | 4 | void Alert::accept() 5 | { 6 | m_hub->acceptAlert(); 7 | } 8 | 9 | void Alert::dismiss() 10 | { 11 | m_hub->dismissAlert(); 12 | } 13 | 14 | QString Alert::text() 15 | { 16 | return m_hub->getAlertText(); 17 | } 18 | 19 | void Alert::sendKeys(QString text) 20 | { 21 | m_hub->setAlertText(text); 22 | } 23 | -------------------------------------------------------------------------------- /selenium/alert.h: -------------------------------------------------------------------------------- 1 | #ifndef ALERT_H 2 | #define ALERT_H 3 | 4 | #include 5 | 6 | class WebDriverHub; 7 | class Alert 8 | { 9 | public: 10 | explicit Alert(WebDriverHub *hub) : m_hub(hub) {} 11 | 12 | void dismiss(); 13 | void accept(); 14 | QString text(); 15 | void sendKeys(QString text); 16 | 17 | private: 18 | WebDriverHub* m_hub; 19 | }; 20 | 21 | #endif // ALERT_H 22 | -------------------------------------------------------------------------------- /selenium/logs.h: -------------------------------------------------------------------------------- 1 | #ifndef LOGS_H 2 | #define LOGS_H 3 | 4 | #include 5 | #include 6 | 7 | #include "logentry.h" 8 | 9 | class WebDriverHub; 10 | class Logs 11 | { 12 | public: 13 | Logs(WebDriverHub* hub); 14 | 15 | QStringList availableLogTypes(); 16 | QList get(QString type); 17 | 18 | private: 19 | WebDriverHub* m_hub; 20 | }; 21 | 22 | #endif // LOGS_H 23 | -------------------------------------------------------------------------------- /selenium/imehandler.h: -------------------------------------------------------------------------------- 1 | #ifndef IMEHANDLER_H 2 | #define IMEHANDLER_H 3 | 4 | #include 5 | 6 | class WebDriverHub; 7 | class ImeHandler 8 | { 9 | public: 10 | ImeHandler(WebDriverHub* hub); 11 | 12 | QStringList availableEngines(); 13 | QString activeEngine(); 14 | void activateEngine(QString engine); 15 | void deactivate(); 16 | bool isActivated(); 17 | 18 | private: 19 | WebDriverHub* m_hub; 20 | }; 21 | 22 | #endif // IMEHANDLER_H 23 | -------------------------------------------------------------------------------- /selenium/logentry.h: -------------------------------------------------------------------------------- 1 | #ifndef LOGENTRY_H 2 | #define LOGENTRY_H 3 | 4 | #include 5 | 6 | class LogEntry 7 | { 8 | public: 9 | LogEntry(QString level, int timestamp, QString message); 10 | 11 | int timestamp() { return m_timestamp; } 12 | QString level() { return m_level; } 13 | QString message() { return m_message; } 14 | 15 | private: 16 | QString m_level; 17 | int m_timestamp; 18 | QString m_message; 19 | }; 20 | 21 | #endif // LOGENTRY_H 22 | -------------------------------------------------------------------------------- /selenium/navigation.cpp: -------------------------------------------------------------------------------- 1 | #include "navigation.h" 2 | #include "webdriver.h" 3 | #include "webdriverhub.h" 4 | 5 | void Navigation::forward() 6 | { 7 | m_hub->forward(); 8 | } 9 | 10 | void Navigation::back() 11 | { 12 | m_hub->back(); 13 | } 14 | 15 | void Navigation::refresh() 16 | { 17 | m_hub->refresh(); 18 | } 19 | 20 | void Navigation::to(const QString& url) 21 | { 22 | m_driver->get(url); 23 | } 24 | 25 | void Navigation::to(QUrl url) 26 | { 27 | m_driver->get(url); 28 | } 29 | -------------------------------------------------------------------------------- /selenium/navigation.h: -------------------------------------------------------------------------------- 1 | #ifndef NAVIGATION_H 2 | #define NAVIGATION_H 3 | 4 | #include 5 | #include 6 | 7 | class WebDriver; 8 | class WebDriverHub; 9 | class Navigation 10 | { 11 | public: 12 | explicit Navigation(WebDriver* driver, WebDriverHub* hub) : m_driver(driver), m_hub(hub) {} 13 | 14 | void forward(); 15 | void back(); 16 | void refresh(); 17 | 18 | void to(const QString& url); 19 | void to(QUrl url); 20 | 21 | private: 22 | WebDriver* m_driver; 23 | WebDriverHub* m_hub; 24 | }; 25 | 26 | #endif // NAVIGATION_H 27 | -------------------------------------------------------------------------------- /selenium/targetlocator.h: -------------------------------------------------------------------------------- 1 | #ifndef TARGETLOCATOR_H 2 | #define TARGETLOCATOR_H 3 | 4 | #include 5 | 6 | #include "alert.h" 7 | 8 | class WebDriverHub; 9 | class WebElement; 10 | class TargetLocator 11 | { 12 | public: 13 | explicit TargetLocator(WebDriverHub* hub) : m_hub(hub) {} 14 | 15 | void frame(QString id); 16 | void frame(int id); 17 | void frame(WebElement *element); 18 | void parentFrame(); 19 | void defaultContent(); 20 | WebElement* activeElement(); 21 | void window(QString handle); 22 | Alert* alert(); 23 | 24 | private: 25 | WebDriverHub* m_hub; 26 | }; 27 | 28 | #endif // TARGETLOCATOR_H 29 | -------------------------------------------------------------------------------- /selenium/imehandler.cpp: -------------------------------------------------------------------------------- 1 | #include "imehandler.h" 2 | #include "webdriverhub.h" 3 | 4 | ImeHandler::ImeHandler(WebDriverHub *hub): 5 | m_hub(hub) 6 | { 7 | } 8 | 9 | QStringList ImeHandler::availableEngines() 10 | { 11 | return m_hub->getImeAvailableEngines(); 12 | } 13 | 14 | QString ImeHandler::activeEngine() 15 | { 16 | return m_hub->getImeActiveEngine(); 17 | } 18 | 19 | void ImeHandler::activateEngine(QString engine) 20 | { 21 | m_hub->imeActivate(engine); 22 | } 23 | 24 | void ImeHandler::deactivate() 25 | { 26 | m_hub->imeDeactivate(); 27 | } 28 | 29 | bool ImeHandler::isActivated() 30 | { 31 | return m_hub->isImeActivated(); 32 | } 33 | -------------------------------------------------------------------------------- /selenium/by.h: -------------------------------------------------------------------------------- 1 | #ifndef BY_H 2 | #define BY_H 3 | 4 | #include 5 | 6 | class By 7 | { 8 | By(QString strategy, QString value); 9 | public: 10 | static By* id(QString id); 11 | static By* linkText(QString linkText); 12 | static By* partialLinkText(QString linkText); 13 | static By* name(QString name); 14 | static By* tagName(QString tagName); 15 | static By* xpath(QString xpath); 16 | static By* className(QString className); 17 | static By* cssSelector(QString cssSelector); 18 | 19 | QString strategy(); 20 | QString value(); 21 | 22 | private: 23 | QString m_strategy; 24 | QString m_value; 25 | }; 26 | 27 | #endif // BY_H 28 | -------------------------------------------------------------------------------- /selenium/timeouts.h: -------------------------------------------------------------------------------- 1 | #ifndef TIMEOUTS_H 2 | #define TIMEOUTS_H 3 | 4 | #include 5 | 6 | class WebDriver; 7 | class WebDriverHub; 8 | 9 | class Timeouts 10 | { 11 | public: 12 | 13 | explicit Timeouts(WebDriver *driver, WebDriverHub *hub) : m_driver(driver), m_hub(hub) {} 14 | 15 | enum TIMEOUT_TYPE { 16 | SCRIPT, 17 | IMPLICIT, 18 | PAGE_LOAD 19 | }; 20 | 21 | static QString toString(int type); 22 | 23 | Timeouts* setScriptTimeout(long ms); 24 | Timeouts* pageLoadTimeout(long ms); 25 | Timeouts* implicitlyWait(long ms); 26 | 27 | private: 28 | WebDriver* m_driver; 29 | WebDriverHub* m_hub; 30 | }; 31 | 32 | #endif // TIMEOUTS_H 33 | -------------------------------------------------------------------------------- /selenium/mouse.cpp: -------------------------------------------------------------------------------- 1 | #include "mouse.h" 2 | #include "webdriverhub.h" 3 | 4 | void Mouse::moveTo(WebElement *element) 5 | { 6 | m_hub->mouseMoveTo(element->id()); 7 | } 8 | 9 | void Mouse::moveTo(int x, int y) 10 | { 11 | m_hub->mouseMoveTo(x, y); 12 | } 13 | 14 | void Mouse::moveTo(QPoint position) 15 | { 16 | moveTo(position.x(), position.y()); 17 | } 18 | 19 | void Mouse::click(int button) 20 | { 21 | m_hub->mouseClick(button); 22 | } 23 | 24 | void Mouse::buttondown(int button) 25 | { 26 | m_hub->mouseButtonDown(button); 27 | } 28 | 29 | void Mouse::buttonup(int button) 30 | { 31 | m_hub->mouseButtonUp(button); 32 | } 33 | 34 | void Mouse::doubleclick() 35 | { 36 | m_hub->mouseDoubleClick(); 37 | } 38 | -------------------------------------------------------------------------------- /selenium/logs.cpp: -------------------------------------------------------------------------------- 1 | #include "logs.h" 2 | #include "webdriverhub.h" 3 | 4 | Logs::Logs(WebDriverHub *hub): 5 | m_hub(hub) 6 | { 7 | } 8 | 9 | QStringList Logs::availableLogTypes() 10 | { 11 | return m_hub->getLogTypes(); 12 | } 13 | 14 | QList Logs::get(QString type) 15 | { 16 | QList logs; 17 | 18 | QList jsons = m_hub->getLog(type); 19 | for(int i = 0; i < jsons.size(); i++) 20 | { 21 | LogEntry* log = new LogEntry(jsons.at(i)["level"].toString(), 22 | jsons.at(i)["timestamp"].toInt(), 23 | jsons.at(i)["message"].toString()); 24 | logs.push_back(log); 25 | } 26 | 27 | return logs; 28 | } 29 | -------------------------------------------------------------------------------- /tests/html_for_tests/mouse/move_to.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Move To 6 | 7 | 8 | 26 | 27 |
28 |
29 |
30 | 31 | 32 | -------------------------------------------------------------------------------- /selenium/mouse.h: -------------------------------------------------------------------------------- 1 | #ifndef MOUSE_H 2 | #define MOUSE_H 3 | 4 | #include 5 | 6 | #include "webelement.h" 7 | 8 | class WebDriverHub; 9 | class Mouse 10 | { 11 | public: 12 | explicit Mouse(WebDriverHub* hub) : m_hub(hub) {} 13 | 14 | enum MOUSE_BUTTONS { 15 | LEFT = 0, 16 | MIDDLE = 1, 17 | RIGHT = 2 18 | }; 19 | 20 | void moveTo(WebElement* element); 21 | void moveTo(int x, int y); 22 | void moveTo(QPoint position); 23 | void click(int button = Mouse::LEFT); 24 | 25 | //TODO Not work in Selenium Server Standalone 2.x. Only default value (LEFT) 26 | void buttondown(int button = Mouse::LEFT); 27 | 28 | 29 | void buttonup(int button = Mouse::LEFT); 30 | void doubleclick(); 31 | 32 | private: 33 | WebDriverHub* m_hub; 34 | }; 35 | 36 | #endif // MOUSE_H 37 | -------------------------------------------------------------------------------- /selenium/window.h: -------------------------------------------------------------------------------- 1 | #ifndef WINDOW_H 2 | #define WINDOW_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | class WebDriverHub; 9 | class Window 10 | { 11 | public: 12 | explicit Window(QString windowHandle, WebDriverHub* hub) : m_windowHandle(windowHandle), m_hub(hub) {} 13 | 14 | void maximize(); 15 | QPoint position(); 16 | QSize size(); 17 | 18 | void setPosition(QPoint pos); 19 | void setPosition(int x, int y); 20 | 21 | void setSize(QSize size); 22 | void setSize(int width, int height); 23 | 24 | //void close(); //in future 25 | //void openNewTab(bool switchTo = false); //in future 26 | //void openNewWindow(bool switchTo = false);//in future 27 | 28 | private: 29 | QString m_windowHandle; 30 | WebDriverHub* m_hub; 31 | }; 32 | 33 | #endif // WINDOW_H 34 | -------------------------------------------------------------------------------- /selenium/window.cpp: -------------------------------------------------------------------------------- 1 | #include "window.h" 2 | #include "webdriverhub.h" 3 | 4 | void Window::maximize() 5 | { 6 | m_hub->windowMaximize(m_windowHandle); 7 | } 8 | 9 | QPoint Window::position() 10 | { 11 | return m_hub->getWindowPosition(m_windowHandle); 12 | } 13 | 14 | QSize Window::size() 15 | { 16 | return m_hub->getWindowSize(m_windowHandle); 17 | } 18 | 19 | void Window::setPosition(QPoint pos) 20 | { 21 | m_hub->setWindowPosition(m_windowHandle, pos.x(), pos.y()); 22 | } 23 | 24 | void Window::setPosition(int x, int y) 25 | { 26 | m_hub->setWindowPosition(m_windowHandle, x, y); 27 | } 28 | 29 | void Window::setSize(QSize size) 30 | { 31 | m_hub->setWindowSize(m_windowHandle, size.width(), size.height()); 32 | } 33 | 34 | void Window::setSize(int width, int height) 35 | { 36 | m_hub->setWindowSize(m_windowHandle, width, height); 37 | } 38 | -------------------------------------------------------------------------------- /selenium/queleniumexception.h: -------------------------------------------------------------------------------- 1 | #ifndef QUELENIUMEXCEPTION_H 2 | #define QUELENIUMEXCEPTION_H 3 | 4 | #include 5 | #include 6 | 7 | #include "responsestatuscodes.h" 8 | 9 | class QueleniumException : public QException 10 | { 11 | public: 12 | explicit QueleniumException(QString message, int code = 0): 13 | QException(), 14 | m_message(message), 15 | m_code(code) 16 | {} 17 | ~QueleniumException() throw() {} 18 | 19 | QString message() { return m_message; } 20 | int code() { return m_code; } 21 | 22 | const char* what() const throw() { return m_message.toUtf8();} 23 | void raise() const { throw *this; } 24 | QueleniumException *clone() const { return new QueleniumException(*this); } 25 | 26 | protected: 27 | QString m_message; 28 | int m_code; 29 | }; 30 | 31 | #endif // QUELENIUMEXCEPTION_H 32 | -------------------------------------------------------------------------------- /selenium/select.h: -------------------------------------------------------------------------------- 1 | #ifndef SELECT_H 2 | #define SELECT_H 3 | 4 | #include "webelement.h" 5 | #include "webdriverexception.h" 6 | 7 | class By; 8 | class Select 9 | { 10 | typedef QList SOptions; 11 | 12 | public: 13 | 14 | Select(WebElement* element); 15 | 16 | bool isMultiple(); 17 | 18 | SOptions options(); 19 | SOptions allSelectedOptions(); 20 | WebElement* firstSelectedOption(); 21 | 22 | void selectByVisibleText(QString text); 23 | void selectByIndex(int index); 24 | void selectByValue(QString value); 25 | 26 | void deselectAll(); 27 | void deselectByValue(QString value); 28 | void deselectByIndex(int index); 29 | void deselectByVisibleText(QString text); 30 | 31 | private: 32 | 33 | WebElement* m_element; 34 | bool m_isMulti; 35 | 36 | void setSelected(WebElement* option); 37 | }; 38 | 39 | #endif // SELECT_H 40 | -------------------------------------------------------------------------------- /selenium/unexpectedalertbehaviour.h: -------------------------------------------------------------------------------- 1 | #ifndef UNEXPECTEDALERTBEHAVIOUR_H 2 | #define UNEXPECTEDALERTBEHAVIOUR_H 3 | 4 | #include 5 | 6 | class UnexpectedAlertBehaviour 7 | { 8 | public: 9 | 10 | enum UNEXPECTED_ALERT_BEHAVIOUR { 11 | ACCEPT, 12 | DISMISS, 13 | IGNORE 14 | }; 15 | 16 | static QString toString(int type) 17 | { 18 | QString name = ""; 19 | 20 | switch (type) { 21 | 22 | case ACCEPT: 23 | name = "accept"; 24 | break; 25 | 26 | case DISMISS: 27 | name = "dismiss"; 28 | break; 29 | 30 | case IGNORE: 31 | name = "ignore"; 32 | break; 33 | 34 | default: 35 | name = "Unknown Type"; 36 | break; 37 | } 38 | 39 | return name; 40 | } 41 | }; 42 | 43 | #endif // UNEXPECTEDALERTBEHAVIOUR_H 44 | -------------------------------------------------------------------------------- /selenium/options.h: -------------------------------------------------------------------------------- 1 | #ifndef OPTIONS_H 2 | #define OPTIONS_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #include "timeouts.h" 9 | #include "window.h" 10 | #include "cookie.h" 11 | #include "imehandler.h" 12 | #include "logs.h" 13 | 14 | class WebDriver; 15 | class WebDriverHub; 16 | 17 | class Options 18 | { 19 | public: 20 | explicit Options(WebDriver* driver, WebDriverHub* hub) : m_driver(driver), m_hub(hub) {} 21 | 22 | void deleteAllCookies(); 23 | QList cookies(); 24 | Cookie* cookieNamed(QString name); 25 | void addCookie(Cookie* cookie); 26 | void deleteCookie(Cookie* cookie); 27 | void deleteCookieNamed(QString name); 28 | 29 | Timeouts* timeouts(); 30 | Window* window(); 31 | ImeHandler* ime(); 32 | Logs* logs(); 33 | 34 | private: 35 | WebDriver* m_driver; 36 | WebDriverHub* m_hub; 37 | }; 38 | 39 | #endif // OPTIONS_H 40 | -------------------------------------------------------------------------------- /selenium/webelement.h: -------------------------------------------------------------------------------- 1 | #ifndef WEBELEMENT_H 2 | #define WEBELEMENT_H 3 | 4 | #include 5 | 6 | class WebDriverHub; 7 | class By; 8 | 9 | class WebElement 10 | { 11 | public: 12 | WebElement(QString id, WebDriverHub* hub); 13 | virtual ~WebElement() {} 14 | 15 | void click(); 16 | void submit(); 17 | void sendKeys(QString text); 18 | QString text(); 19 | QString tagName(); 20 | void clear(); 21 | bool isSelected(); 22 | bool isEnabled(); 23 | bool isDisplayed(); 24 | QString attribute(QString name); 25 | bool equals(QString otherElementId); 26 | QPoint location(); 27 | QSize size(); 28 | QString cssValue(QString cssProperty); 29 | WebElement* findElement(By *by); 30 | QList findElements(By *by); 31 | 32 | QString id() { return m_id; } 33 | 34 | private: 35 | QString m_id; 36 | WebDriverHub* m_hub; 37 | }; 38 | 39 | #endif // WEBELEMENT_H 40 | -------------------------------------------------------------------------------- /selenium/touch.h: -------------------------------------------------------------------------------- 1 | #ifndef TOUCH_H 2 | #define TOUCH_H 3 | 4 | #include "webelement.h" 5 | 6 | class WebDriverHub; 7 | class Touch 8 | { 9 | public: 10 | explicit Touch(WebDriverHub* hub) : m_hub(hub) {} 11 | 12 | void click(WebElement* element); 13 | void down(int x, int y); 14 | void down(QPoint pos); 15 | void down(WebElement* element); 16 | void up(int x, int y); 17 | void up(QPoint pos); 18 | void up(WebElement* element); 19 | void move(int x, int y); 20 | void move(QPoint pos); 21 | void move(WebElement* element); 22 | void scroll(WebElement* element, int xoffset, int yoffset); 23 | void scroll(int xoffset, int yoffset); 24 | void doubleclick(WebElement* element); 25 | void longclick(WebElement* element); 26 | void flick(WebElement* element, int xoffset, int yoffset, int speed); 27 | void flick(int xspeed, int yspeed); 28 | 29 | private: 30 | WebDriverHub* m_hub; 31 | }; 32 | 33 | #endif // TOUCH_H 34 | -------------------------------------------------------------------------------- /selenium/timeouts.cpp: -------------------------------------------------------------------------------- 1 | #include "timeouts.h" 2 | #include "webdriver.h" 3 | #include "webdriverhub.h" 4 | 5 | Timeouts* Timeouts::setScriptTimeout(long ms) 6 | { 7 | m_hub->setTimeouts(toString(SCRIPT), ms); 8 | return this; 9 | } 10 | 11 | Timeouts* Timeouts::pageLoadTimeout(long ms) 12 | { 13 | m_hub->setTimeouts(toString(PAGE_LOAD), ms); 14 | return this; 15 | } 16 | 17 | Timeouts* Timeouts::implicitlyWait(long ms) 18 | { 19 | m_hub->setTimeouts(toString(IMPLICIT), ms); 20 | return this; 21 | } 22 | 23 | QString Timeouts::toString(int type) 24 | { 25 | QString name; 26 | 27 | switch(type) { 28 | 29 | case SCRIPT: 30 | name = "script"; 31 | break; 32 | 33 | case IMPLICIT: 34 | name = "implicit"; 35 | break; 36 | 37 | case PAGE_LOAD: 38 | name = "page load"; 39 | break; 40 | 41 | default: 42 | name = "Unknown Type"; 43 | break; 44 | } 45 | 46 | return name; 47 | } 48 | -------------------------------------------------------------------------------- /selenium/targetlocator.cpp: -------------------------------------------------------------------------------- 1 | #include "targetlocator.h" 2 | #include "webdriverhub.h" 3 | #include "webelement.h" 4 | 5 | void TargetLocator::frame(QString id) 6 | { 7 | m_hub->changeFrame(id); 8 | } 9 | 10 | void TargetLocator::frame(int id) 11 | { 12 | m_hub->changeFrame(id); 13 | } 14 | 15 | void TargetLocator::frame(WebElement* element) 16 | { 17 | QJsonObject json; 18 | json["ELEMENT"] = element->id(); 19 | 20 | m_hub->changeFrame(json); 21 | } 22 | 23 | void TargetLocator::parentFrame() 24 | { 25 | m_hub->changeFrameParent(); 26 | } 27 | 28 | void TargetLocator::defaultContent() 29 | { 30 | m_hub->changeFrame(); 31 | } 32 | 33 | void TargetLocator::window(QString handle) 34 | { 35 | m_hub->changeWindow(handle); 36 | } 37 | 38 | WebElement* TargetLocator::activeElement() 39 | { 40 | QString id = m_hub->getElementActive(); 41 | return new WebElement(id, m_hub); 42 | } 43 | 44 | Alert* TargetLocator::alert() 45 | { 46 | return new Alert(m_hub); 47 | } 48 | -------------------------------------------------------------------------------- /selenium/desiredcapabilities.cpp: -------------------------------------------------------------------------------- 1 | #include "desiredcapabilities.h" 2 | 3 | DesiredCapabilities::DesiredCapabilities(Browser::Type browser) 4 | { 5 | setTakesScreenshot(true); 6 | setHandlesAlerts(true); 7 | setCssSelectorsEnabled(true); 8 | 9 | m_proxy = 0; 10 | 11 | setBrowser(browser); 12 | } 13 | 14 | QVariant DesiredCapabilities::property(QString property) 15 | { 16 | if(!m_properties.value(property).isNull()) { 17 | return m_properties.value(property); 18 | } 19 | 20 | qDebug()<<"Property " << property << " is not initialize!"; 21 | return QVariant(); 22 | } 23 | 24 | void DesiredCapabilities::setProperty(QString property, QString value) 25 | { 26 | m_properties.insert(property, QJsonValue(value)); 27 | } 28 | 29 | void DesiredCapabilities::setProperty(QString property, bool value) 30 | { 31 | m_properties.insert(property, QJsonValue(value)); 32 | } 33 | 34 | void DesiredCapabilities::setProperty(QString property, int value) 35 | { 36 | m_properties.insert(property, QJsonValue(value)); 37 | } 38 | -------------------------------------------------------------------------------- /selenium/proxy.h: -------------------------------------------------------------------------------- 1 | #ifndef PROXY_H 2 | #define PROXY_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | class Proxy 9 | { 10 | public: 11 | 12 | enum PROXY_TYPE { 13 | DIRECT = 1, 14 | MANUAL, 15 | PAC, 16 | AUTODETECT, 17 | SYSTEM, 18 | UNKNOWN 19 | }; 20 | 21 | explicit Proxy(PROXY_TYPE proxyType); 22 | ~Proxy(); 23 | 24 | void setProxyType(PROXY_TYPE proxyType); 25 | void setAutoconfigUrl(QString url); 26 | void setSocksUsername(QString socksUsername); 27 | void setSocksPassword(QString socksPassword); 28 | 29 | int proxyType(); 30 | QString autoconfigUrl(); 31 | QString socksUsername(); 32 | QString socksPassword(); 33 | 34 | static QString toString(int type); 35 | static PROXY_TYPE toProxyType(QString text); 36 | 37 | protected: 38 | 39 | PROXY_TYPE m_proxyType; 40 | QString m_proxyAutoconfigUrl; 41 | QString m_socksUsername; 42 | QString m_socksPassword; 43 | 44 | }; 45 | 46 | #endif // PROXY_H 47 | -------------------------------------------------------------------------------- /selenium/by.cpp: -------------------------------------------------------------------------------- 1 | #include "by.h" 2 | 3 | By::By(QString strategy, QString value): 4 | m_strategy(strategy), 5 | m_value(value) 6 | { 7 | } 8 | 9 | By* By::id(QString id) 10 | { 11 | return new By("id", id); 12 | } 13 | 14 | By* By::linkText(QString linkText) 15 | { 16 | return new By("link text", linkText); 17 | } 18 | 19 | By* By::partialLinkText(QString linkText) 20 | { 21 | return new By("partial link text", linkText); 22 | } 23 | 24 | By* By::name(QString name) 25 | { 26 | return new By("name", name); 27 | } 28 | 29 | By* By::tagName(QString tagName) 30 | { 31 | return new By("tag name", tagName); 32 | } 33 | 34 | By* By::xpath(QString xpath) 35 | { 36 | return new By("xpath", xpath); 37 | } 38 | 39 | By* By::className(QString className) 40 | { 41 | return new By("class name", className); 42 | } 43 | 44 | By* By::cssSelector(QString cssSelector) 45 | { 46 | return new By("css selector", cssSelector); 47 | } 48 | 49 | QString By::strategy() 50 | { 51 | return m_strategy; 52 | } 53 | 54 | QString By::value() 55 | { 56 | return m_value; 57 | } 58 | -------------------------------------------------------------------------------- /tests/tests.pro: -------------------------------------------------------------------------------- 1 | #------------------------------------------------- 2 | # 3 | # Project created by QtCreator 4 | # linotex.m@gmail.com 5 | # 6 | #------------------------------------------------- 7 | 8 | QT += core network testlib 9 | 10 | QT -= gui 11 | 12 | TARGET = bin/seleniumtest 13 | CONFIG += console 14 | CONFIG -= app_bundle exception 15 | 16 | TEMPLATE = app 17 | 18 | OBJECTS_DIR = build 19 | MOC_DIR = build 20 | UI_DIR = build 21 | RCC_DIR = build 22 | 23 | SOURCES += \ 24 | queleniumtest.cpp 25 | DEFINES += SRCDIR=\\\"$$PWD/\\\" 26 | 27 | HEADERS += \ 28 | queleniumtest.h 29 | 30 | win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../release/ -lQuelenium 31 | else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../debug/ -lQuelenium 32 | else:unix: LIBS += -L$$PWD/../ -lQuelenium 33 | 34 | INCLUDEPATH += $$PWD/../ 35 | DEPENDPATH += $$PWD/../ 36 | 37 | win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/../release/libQuelenium.a 38 | else:win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/../debug/libQuelenium.a 39 | else:win32:!win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/../release/Quelenium.lib 40 | else:win32:!win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/../debug/Quelenium.lib 41 | else:unix: PRE_TARGETDEPS += $$PWD/../libQuelenium.a 42 | -------------------------------------------------------------------------------- /tests/html_for_tests/alert/alert.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Alert Test 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /selenium/responsestatuscodes.h: -------------------------------------------------------------------------------- 1 | #ifndef RESPONSESTATUSCODES_H 2 | #define RESPONSESTATUSCODES_H 3 | 4 | class ResponseStatusCodes 5 | { 6 | public: 7 | enum { 8 | SUCCESS = 0, 9 | NO_SUCH_DRIVER = 6, 10 | NO_SUCH_ELEMENT = 7, 11 | NO_SUCH_FRAME = 8, 12 | UNKNOWN_COMMAND = 9, 13 | STALE_ELEMENT_REFERENCE = 10, 14 | ELEMENT_NOT_VISIBLE = 11, 15 | INVALID_ELEMENT_STATE = 12, 16 | UNKNOWN_ERROR = 13, 17 | ELEMENT_IS_NOT_SELECTABLE = 15, 18 | JAVA_SCRIPT_ERROR = 17, 19 | XPATH_LOOKUP_ERROR = 19, 20 | TIMEOUT = 21, 21 | NO_SUCH_WINDOW = 23, 22 | INVALID_COOKIE_DOMAIN = 24, 23 | UNABLE_TO_SET_COOKIE = 25, 24 | UNEXPECTED_ALERT_OPEN = 26, 25 | NO_ALERT_OPEN_ERROR = 27, 26 | SCRIPT_TIMEOUT = 28, 27 | INVALID_ELEMENT_COORDINATES = 29, 28 | IME_NOT_AVAILABLE = 30, 29 | IME_ENGINE_ACTIVATION_FAILED = 31, 30 | INVALID_SELECTOR = 32, 31 | SESSION_NOT_CREATED_EXCEPTION = 33, 32 | MOVE_TARGET_OUT_OF_BOUNDS = 34, 33 | }; 34 | }; 35 | 36 | #endif // RESPONSESTATUSCODES_H 37 | -------------------------------------------------------------------------------- /tests/html_for_tests/mouse/click.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Move To 6 | 7 | 8 | 20 | 21 |
22 |
23 | 24 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /selenium/cookie.h: -------------------------------------------------------------------------------- 1 | #ifndef COOKIE_H 2 | #define COOKIE_H 3 | 4 | #include 5 | #include 6 | 7 | class Cookie 8 | { 9 | public: 10 | explicit Cookie(QString name, QString value); 11 | Cookie(QString name, QString value, QString path); 12 | Cookie(QString name, QString value, QString path, QDateTime expiry); 13 | Cookie(QString name, QString value, QString path, QString domain, QDateTime expiry); 14 | Cookie(QString name, QString value, QString path, QString domain, QDateTime expiry, bool isSecure); 15 | Cookie(QString name, QString value, QString path, QString domain, QDateTime expiry, bool isSecure, bool isHttpOnly); 16 | 17 | QString name(); 18 | QString value(); 19 | QString path(); 20 | QString domain(); 21 | bool isSecure(); 22 | bool isHttpOnly(); 23 | QDateTime expiry(); 24 | int hashCode(); 25 | 26 | void setHashCode(int hashCode); 27 | 28 | private: 29 | 30 | void init(QString name, QString value, QString path, QString domain, bool secure, bool httpOnly, QDateTime expiry); 31 | 32 | void setName(QString name); 33 | void setValue(QString value); 34 | void setPath(QString path); 35 | void setDomain(QString domain); 36 | void setSecure(bool secure); 37 | void setHttpOnly(bool only); 38 | void setExpiry(QDateTime expiry); 39 | 40 | QDateTime getDefaultTime(); 41 | 42 | QString m_name; 43 | QString m_value; 44 | QString m_path; 45 | QString m_domain; 46 | bool m_secure; 47 | bool m_httpOnly; 48 | QDateTime m_expiry; 49 | int m_hashCode; 50 | }; 51 | 52 | #endif // COOKIE_H 53 | -------------------------------------------------------------------------------- /selenium/selenium.pro: -------------------------------------------------------------------------------- 1 | QT += network 2 | 3 | QT -= gui 4 | 5 | 6 | TARGET = ../Quelenium 7 | TEMPLATE = lib 8 | CONFIG += staticlib 9 | 10 | OBJECTS_DIR = ../build 11 | MOC_DIR = ../build 12 | UI_DIR = ../build 13 | RCC_DIR = ../build 14 | 15 | DEFINES += QTSELENIUM_DEBUG 16 | 17 | 18 | SOURCES += \ 19 | desiredcapabilities.cpp \ 20 | webdriver.cpp \ 21 | seleniumserverhub.cpp \ 22 | webdriverhub.cpp \ 23 | navigation.cpp \ 24 | options.cpp \ 25 | timeouts.cpp \ 26 | window.cpp \ 27 | cookie.cpp \ 28 | imehandler.cpp \ 29 | logs.cpp \ 30 | logentry.cpp \ 31 | webelement.cpp \ 32 | by.cpp \ 33 | targetlocator.cpp \ 34 | alert.cpp \ 35 | webdriverexception.cpp \ 36 | keys.cpp \ 37 | proxy.cpp \ 38 | actions.cpp \ 39 | mouse.cpp \ 40 | touch.cpp \ 41 | select.cpp \ 42 | server.cpp 43 | 44 | HEADERS += \ 45 | desiredcapabilities.h \ 46 | browser.h \ 47 | platform.h \ 48 | unexpectedalertbehaviour.h \ 49 | webdriver.h \ 50 | seleniumserverhub.h \ 51 | webdriverhub.h \ 52 | proxy.h \ 53 | responsestatuscodes.h \ 54 | navigation.h \ 55 | options.h \ 56 | timeouts.h \ 57 | window.h \ 58 | cookie.h \ 59 | imehandler.h \ 60 | logs.h \ 61 | logentry.h \ 62 | webelement.h \ 63 | by.h \ 64 | targetlocator.h \ 65 | alert.h \ 66 | webdriverexception.h \ 67 | queleniumexception.h \ 68 | keys.h \ 69 | actions.h \ 70 | mouse.h \ 71 | touch.h \ 72 | select.h \ 73 | server.h 74 | #unix { 75 | # target.path = /usr/lib 76 | # INSTALLS += target 77 | #} 78 | -------------------------------------------------------------------------------- /selenium/webdriver.h: -------------------------------------------------------------------------------- 1 | #ifndef WEBDRIVER_H 2 | #define WEBDRIVER_H 3 | 4 | #include 5 | #include 6 | 7 | #include "browser.h" 8 | #include "desiredcapabilities.h" 9 | #include "navigation.h" 10 | #include "options.h" 11 | #include "webelement.h" 12 | #include "select.h" 13 | #include "by.h" 14 | #include "targetlocator.h" 15 | #include "actions.h" 16 | #include "server.h" 17 | 18 | class WebDriverHub; 19 | 20 | class WebDriver 21 | { 22 | 23 | public: 24 | explicit WebDriver(QString host, int port, Browser::Type browser, QString url); 25 | WebDriver(QString host, int port, DesiredCapabilities* desiredCapabilities, QString url); 26 | 27 | WebDriver(QString host, int port, Browser::Type browser); 28 | WebDriver(QString host, int port, DesiredCapabilities* desiredCapabilities); 29 | 30 | ~WebDriver(); 31 | 32 | DesiredCapabilities* capabilities(bool refresh = false) ; 33 | 34 | void get(const QString& url); 35 | void get(QUrl url); 36 | 37 | void quit(); 38 | void close(); 39 | 40 | QString currentUrl(); 41 | QString title(); 42 | QString pageSource(); 43 | QString windowHandle(); 44 | QStringList windowHandles(); 45 | 46 | WebElement* findElement(By* by); 47 | QList findElements(By* by); 48 | 49 | Navigation* navigate(); 50 | Options* manage(); 51 | TargetLocator* switchTo(); 52 | Actions* actions(); 53 | Server* server(); 54 | 55 | protected: 56 | void init(QString host, int port, DesiredCapabilities* dc, QString url); 57 | void init(QString host, int port, DesiredCapabilities* dc); 58 | WebDriverHub* getHub(); 59 | 60 | private: 61 | WebDriverHub* m_wdh; 62 | }; 63 | 64 | #endif // WEBDRIVER_H 65 | -------------------------------------------------------------------------------- /selenium/platform.h: -------------------------------------------------------------------------------- 1 | #ifndef PLATFORM_H 2 | #define PLATFORM_H 3 | 4 | #include 5 | 6 | class Platform 7 | { 8 | public: 9 | enum Type { 10 | WINDOWS, 11 | XP, 12 | VISTA, 13 | MAC, 14 | LINUX, 15 | UNIX, 16 | ANDROID, 17 | UNKNOWN 18 | }; 19 | 20 | static QString toString(Platform::Type platform) 21 | { 22 | QString name = ""; 23 | 24 | switch (platform) { 25 | 26 | case WINDOWS: 27 | name = "WINDOWS"; 28 | break; 29 | 30 | case XP: 31 | name = "XP"; 32 | break; 33 | 34 | case VISTA: 35 | name = "VISTA"; 36 | break; 37 | 38 | case MAC: 39 | name = "MAC"; 40 | break; 41 | 42 | case LINUX: 43 | name = "LINUX"; 44 | break; 45 | 46 | case UNIX: 47 | name = "UNIX"; 48 | break; 49 | 50 | case ANDROID: 51 | name = "ANDROID"; 52 | break; 53 | 54 | default: 55 | name = "Unknown Platform"; 56 | break; 57 | } 58 | 59 | return name; 60 | } 61 | 62 | Platform::Type static fromString(QString platform) 63 | { 64 | Platform::Type id = UNKNOWN; 65 | 66 | if(platform == "WINDOWS") { id = WINDOWS; } 67 | else if(platform == "XP") { id = XP; } 68 | else if(platform == "VISTA") { id = VISTA; } 69 | else if(platform == "MAC") { id = MAC; } 70 | else if(platform == "LINUX") { id = LINUX; } 71 | else if(platform == "UNIX") { id = UNIX; } 72 | else if(platform == "ANDROID") { id = ANDROID; } 73 | 74 | return id; 75 | } 76 | }; 77 | 78 | #endif // PLATFORM_H 79 | -------------------------------------------------------------------------------- /selenium/touch.cpp: -------------------------------------------------------------------------------- 1 | #include "touch.h" 2 | #include "webdriverhub.h" 3 | 4 | void Touch::click(WebElement *element) 5 | { 6 | m_hub->touchClick(element->id()); 7 | } 8 | 9 | void Touch::down(int x, int y) 10 | { 11 | m_hub->touchDown(x, y); 12 | } 13 | 14 | void Touch::down(QPoint pos) 15 | { 16 | down(pos.x(), pos.y()); 17 | } 18 | 19 | void Touch::down(WebElement* element) 20 | { 21 | QPoint p = element->location(); 22 | down(p.x(), p.y()); 23 | } 24 | 25 | void Touch::up(int x, int y) 26 | { 27 | m_hub->touchUp(x, y); 28 | } 29 | 30 | void Touch::up(QPoint pos) 31 | { 32 | up(pos.x(), pos.y()); 33 | } 34 | 35 | void Touch::up(WebElement* element) 36 | { 37 | QPoint p = element->location(); 38 | up(p.x(), p.y()); 39 | } 40 | 41 | void Touch::move(int x, int y) 42 | { 43 | m_hub->touchMove(x, y); 44 | } 45 | 46 | void Touch::move(QPoint pos) 47 | { 48 | move(pos.x(), pos.y()); 49 | } 50 | 51 | void Touch::move(WebElement* element) 52 | { 53 | QPoint p = element->location(); 54 | move(p.x(), p.y()); 55 | } 56 | 57 | void Touch::scroll(WebElement* element, int xoffset, int yoffset) 58 | { 59 | m_hub->touchScroll(element->id(), xoffset, yoffset); 60 | } 61 | 62 | void Touch::scroll(int xoffset, int yoffset) 63 | { 64 | m_hub->touchScroll(xoffset, yoffset); 65 | } 66 | 67 | void Touch::doubleclick(WebElement* element) 68 | { 69 | m_hub->touchDoubleClick(element->id()); 70 | } 71 | 72 | void Touch::longclick(WebElement* element) 73 | { 74 | m_hub->touchLongClick(element->id()); 75 | } 76 | 77 | void Touch::flick(WebElement* element, int xoffset, int yoffset, int speed) 78 | { 79 | m_hub->touchFlick(element->id(), xoffset, yoffset, speed); 80 | } 81 | 82 | void Touch::flick(int xspeed, int yspeed) 83 | { 84 | m_hub->touchFlick(xspeed, yspeed); 85 | } 86 | -------------------------------------------------------------------------------- /selenium/seleniumserverhub.h: -------------------------------------------------------------------------------- 1 | #ifndef SELENIUMSERVERHUB_H 2 | #define SELENIUMSERVERHUB_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | #include "responsestatuscodes.h" 17 | #include "webdriverexception.h" 18 | 19 | class WebDriverException; 20 | class SeleniumServerHub : public QObject 21 | { 22 | Q_OBJECT 23 | public: 24 | explicit SeleniumServerHub(QString host, int port); 25 | ~SeleniumServerHub(); 26 | 27 | enum HTTP_METHOD { 28 | GET, 29 | POST, 30 | PUT, 31 | DELETE 32 | }; 33 | 34 | QString host(); 35 | int port(); 36 | 37 | protected: 38 | void buildUrl(QString host, int port); 39 | 40 | QString getValueString(QString s); 41 | QStringList getValueArrayString(QString s); 42 | bool getValueBool(QString s); 43 | QJsonObject getValueObject(QString s); 44 | QJsonArray getValueArray(QString s); 45 | int getValueInt(QString s); 46 | 47 | QJsonObject exec(QString url, QByteArray rawBody, int method); 48 | QJsonObject post(QString url, QJsonObject rawBody); 49 | QJsonObject post(QString url); 50 | QJsonObject get(QString url); 51 | QJsonObject deleteMethod(QString url); 52 | void releaseReplyResources(); 53 | 54 | QString m_host; 55 | int m_port; 56 | QString m_urlHub; 57 | 58 | QNetworkReply *m_reply; 59 | 60 | QString m_result; 61 | QString m_sessionId; 62 | 63 | signals: 64 | 65 | public slots: 66 | void slotFinishRequest(); 67 | void slotReplyResponse(); 68 | void slotReplyError(); 69 | 70 | }; 71 | 72 | #endif // SELENIUMSERVERHUB_H 73 | -------------------------------------------------------------------------------- /selenium/webelement.cpp: -------------------------------------------------------------------------------- 1 | #include "webelement.h" 2 | #include "webdriverhub.h" 3 | #include "by.h" 4 | 5 | WebElement::WebElement(QString id, WebDriverHub *hub): 6 | m_id(id), 7 | m_hub(hub) 8 | { 9 | } 10 | 11 | void WebElement::click() 12 | { 13 | m_hub->elementClick(m_id); 14 | } 15 | 16 | void WebElement::submit() 17 | { 18 | m_hub->elementSubmit(m_id); 19 | } 20 | 21 | QString WebElement::text() 22 | { 23 | return m_hub->getElementText(m_id); 24 | } 25 | 26 | void WebElement::sendKeys(QString text) 27 | { 28 | m_hub->elementValue(m_id, QStringList(text)); 29 | } 30 | 31 | QString WebElement::tagName() 32 | { 33 | return m_hub->getElementTagName(m_id); 34 | } 35 | 36 | void WebElement::clear() 37 | { 38 | m_hub->elementClear(m_id); 39 | } 40 | 41 | bool WebElement::isSelected() 42 | { 43 | return m_hub->isElementSelected(m_id); 44 | } 45 | 46 | bool WebElement::isEnabled() 47 | { 48 | return m_hub->isElementEnabled(m_id); 49 | } 50 | 51 | QString WebElement::attribute(QString name) 52 | { 53 | return m_hub->getElementAttributeValue(m_id, name); 54 | } 55 | 56 | bool WebElement::equals(QString otherElementId) 57 | { 58 | return m_hub->elementEqualsOther(m_id, otherElementId); 59 | } 60 | 61 | bool WebElement::isDisplayed() 62 | { 63 | return m_hub->isElementDisplayed(m_id); 64 | } 65 | 66 | QPoint WebElement::location() 67 | { 68 | return m_hub->getElementLocation(m_id); 69 | } 70 | 71 | QSize WebElement::size() 72 | { 73 | return m_hub->getElementSize(m_id); 74 | } 75 | 76 | QString WebElement::cssValue(QString cssProperty) 77 | { 78 | return m_hub->getElementCssPropertyValue(m_id, cssProperty); 79 | } 80 | 81 | WebElement* WebElement::findElement(By *by) 82 | { 83 | QString id = m_hub->getElementByElement(m_id, by->strategy(), by->value()); 84 | return new WebElement(id, m_hub); 85 | } 86 | 87 | QList WebElement::findElements(By *by) 88 | { 89 | QStringList ids = m_hub->getElementsByElement(m_id, by->strategy(), by->value()); 90 | QList elements; 91 | for(int i = 0; i < ids.size(); i++) { 92 | elements.push_back(new WebElement(ids.at(i), m_hub)); 93 | } 94 | 95 | return elements; 96 | } 97 | -------------------------------------------------------------------------------- /selenium/server.h: -------------------------------------------------------------------------------- 1 | #ifndef SERVER_H 2 | #define SERVER_H 3 | 4 | #include 5 | #include 6 | 7 | #include "desiredcapabilities.h" 8 | #include "browser.h" 9 | 10 | // Server build 11 | struct Build { 12 | 13 | public: 14 | Build(QJsonObject build) : m_build(build) {} 15 | 16 | QString revision(){ return m_build["revision"].toString(); } 17 | QString time() { return m_build["time"].toString(); } 18 | QString version() { return m_build["version"].toString(); } 19 | 20 | private: 21 | QJsonObject m_build; 22 | }; 23 | 24 | // Server OS 25 | struct Os { 26 | 27 | public: 28 | Os(QJsonObject os) : m_os(os) {} 29 | 30 | QString arch() { return m_os["arch"].toString(); } 31 | QString name() { return m_os["name"].toString(); } 32 | QString version() { return m_os["version"].toString(); } 33 | 34 | private: 35 | QJsonObject m_os; 36 | }; 37 | 38 | // Server Java 39 | struct Java { 40 | 41 | public: 42 | Java(QJsonObject java) : m_java(java) {} 43 | 44 | QString version() { return m_java["version"].toString(); } 45 | 46 | private: 47 | QJsonObject m_java; 48 | }; 49 | 50 | // Server status 51 | struct Status 52 | { 53 | public: 54 | Status(Os* os, Build* build, Java* java = 0) : m_os(os), m_build(build), m_java(java) 55 | {} 56 | 57 | Os* os() { return m_os; } 58 | Build* build() { return m_build; } 59 | Java* java() { return m_java; } 60 | 61 | private: 62 | Os* m_os; 63 | Build* m_build; 64 | Java* m_java; 65 | }; 66 | 67 | struct Session 68 | { 69 | public: 70 | Session(QString id, DesiredCapabilities* cap) : m_id(id), m_cap(cap) {} 71 | 72 | QString id() { return m_id; } 73 | DesiredCapabilities* capabilities() { return m_cap; } 74 | 75 | private: 76 | QString m_id; 77 | DesiredCapabilities* m_cap; 78 | 79 | }; 80 | 81 | class WebDriverHub; 82 | class Server 83 | { 84 | public: 85 | explicit Server(WebDriverHub* hub); 86 | 87 | Status* status(); 88 | QList sessions(); 89 | 90 | private: 91 | WebDriverHub* m_hub; 92 | }; 93 | 94 | #endif // SERVER_H 95 | -------------------------------------------------------------------------------- /selenium/browser.h: -------------------------------------------------------------------------------- 1 | #ifndef BROWSER_H 2 | #define BROWSER_H 3 | 4 | #include 5 | 6 | class Browser 7 | { 8 | public: 9 | 10 | enum Type { 11 | FIREFOX, 12 | CHROME, 13 | OPERA, 14 | IE, 15 | ANDROID, 16 | IPHONE, 17 | IPAD, 18 | HTMLUNIT, 19 | SAFARI, 20 | UNKNOWN 21 | }; 22 | 23 | static QString toString(int type) 24 | { 25 | QString name = ""; 26 | 27 | switch (type) { 28 | 29 | case FIREFOX: 30 | name = "firefox"; 31 | break; 32 | 33 | case CHROME: 34 | name = "chrome"; 35 | break; 36 | 37 | case OPERA: 38 | name = "opera"; 39 | break; 40 | 41 | case IE: 42 | name = "internet explorer"; 43 | break; 44 | 45 | case ANDROID: 46 | name = "android"; 47 | break; 48 | 49 | case IPHONE: 50 | name = "iphone"; 51 | break; 52 | 53 | case IPAD: 54 | name = "ipad"; 55 | break; 56 | 57 | case HTMLUNIT: 58 | name = "htmlunit"; 59 | break; 60 | 61 | case SAFARI: 62 | name = "safari"; 63 | break; 64 | 65 | default: 66 | name = "Unknown Name"; 67 | break; 68 | } 69 | 70 | return name; 71 | } 72 | 73 | static Type fromString(QString text) 74 | { 75 | Type browser = UNKNOWN; 76 | 77 | text = text.toLower(); 78 | 79 | if(text == "firefox") { 80 | browser = FIREFOX; 81 | 82 | } else if(text == "chrome") { 83 | browser = CHROME; 84 | 85 | } else if(text == "internet explorer") { 86 | browser = IE; 87 | 88 | } else if(text == "android") { 89 | browser = ANDROID; 90 | 91 | } else if(text == "iphone") { 92 | browser = IPHONE; 93 | 94 | } else if(text == "ipad") { 95 | browser = IPAD; 96 | 97 | } else if(text == "htmlunit") { 98 | browser = HTMLUNIT; 99 | 100 | } else if(text == "safari") { 101 | browser = SAFARI; 102 | } 103 | 104 | return browser; 105 | } 106 | }; 107 | 108 | #endif // BROWSER_H 109 | -------------------------------------------------------------------------------- /selenium/keys.h: -------------------------------------------------------------------------------- 1 | #ifndef KEYS_H 2 | #define KEYS_H 3 | 4 | #include 5 | 6 | class Keys 7 | { 8 | //Keys(); 9 | public: 10 | static const QString NULL_KEY ; 11 | static const QString CANCEL ; 12 | static const QString HELP ; 13 | static const QString BACK_SPACE ; 14 | static const QString TAB ; 15 | static const QString CLEAR ; 16 | static const QString RETURN ; 17 | static const QString ENTER ; 18 | static const QString SHIFT ; 19 | static const QString CONTROL ; 20 | static const QString ALT ; 21 | static const QString PAUSE ; 22 | static const QString ESCAPE ; 23 | static const QString SPACE ; 24 | static const QString PAGEUP ; 25 | static const QString PAGEDOWN ; 26 | static const QString END ; 27 | static const QString HOME ; 28 | static const QString LEFT_ARROW ; 29 | static const QString UP_ARROW ; 30 | static const QString RIGHT_ARROW; 31 | static const QString DOWN_ARROW ; 32 | static const QString INSERT ; 33 | static const QString DELETE ; 34 | static const QString SEMICOLON ; 35 | static const QString EQUALS ; 36 | static const QString NUMPAD_0 ; 37 | static const QString NUMPAD_1 ; 38 | static const QString NUMPAD_2 ; 39 | static const QString NUMPAD_3 ; 40 | static const QString NUMPAD_4 ; 41 | static const QString NUMPAD_5 ; 42 | static const QString NUMPAD_6 ; 43 | static const QString NUMPAD_7 ; 44 | static const QString NUMPAD_8 ; 45 | static const QString NUMPAD_9 ; 46 | static const QString MULTIPLY ; 47 | static const QString ADD ; 48 | static const QString SEPARATOR ; 49 | static const QString SUBTRACT ; 50 | static const QString DECIMAL ; 51 | static const QString DIVIDE ; 52 | static const QString F1 ; 53 | static const QString F2 ; 54 | static const QString F3 ; 55 | static const QString F4 ; 56 | static const QString F5 ; 57 | static const QString F6 ; 58 | static const QString F7 ; 59 | static const QString F8 ; 60 | static const QString F9 ; 61 | static const QString F10 ; 62 | static const QString F11 ; 63 | static const QString F12 ; 64 | static const QString COMMAND ; 65 | static const QString META ; 66 | }; 67 | 68 | #endif // KEYS_H 69 | -------------------------------------------------------------------------------- /selenium/keys.cpp: -------------------------------------------------------------------------------- 1 | #include "keys.h" 2 | const QString Keys::NULL_KEY = "\ue000"; 3 | const QString Keys::CANCEL = "\ue001"; 4 | const QString Keys::HELP = "\ue002"; 5 | const QString Keys::BACK_SPACE = "\ue003"; 6 | const QString Keys::TAB = "\ue004"; 7 | const QString Keys::CLEAR = "\ue005"; 8 | const QString Keys::RETURN = "\ue006"; 9 | const QString Keys::ENTER = "\ue007"; 10 | const QString Keys::SHIFT = "\ue008"; 11 | const QString Keys::CONTROL = "\ue009"; 12 | const QString Keys::ALT = "\ue00A"; 13 | const QString Keys::PAUSE = "\ue00B"; 14 | const QString Keys::ESCAPE = "\ue00C"; 15 | const QString Keys::SPACE = "\ue00D"; 16 | const QString Keys::PAGEUP = "\ue00E"; 17 | const QString Keys::PAGEDOWN = "\ue00F"; 18 | const QString Keys::END = "\ue010"; 19 | const QString Keys::HOME = "\ue011"; 20 | const QString Keys::LEFT_ARROW = "\ue012"; 21 | const QString Keys::UP_ARROW = "\ue013"; 22 | const QString Keys::RIGHT_ARROW = "\ue014"; 23 | const QString Keys::DOWN_ARROW = "\ue015"; 24 | const QString Keys::INSERT = "\ue016"; 25 | const QString Keys::DELETE = "\ue017"; 26 | const QString Keys::SEMICOLON = "\ue018"; 27 | const QString Keys::EQUALS = "\ue019"; 28 | const QString Keys::NUMPAD_0 = "\ue01A"; 29 | const QString Keys::NUMPAD_1 = "\ue01B"; 30 | const QString Keys::NUMPAD_2 = "\ue01C"; 31 | const QString Keys::NUMPAD_3 = "\ue01D"; 32 | const QString Keys::NUMPAD_4 = "\ue01E"; 33 | const QString Keys::NUMPAD_5 = "\ue01F"; 34 | const QString Keys::NUMPAD_6 = "\ue020"; 35 | const QString Keys::NUMPAD_7 = "\ue021"; 36 | const QString Keys::NUMPAD_8 = "\ue022"; 37 | const QString Keys::NUMPAD_9 = "\ue023"; 38 | const QString Keys::MULTIPLY = "\ue024"; 39 | const QString Keys::ADD = "\ue025"; 40 | const QString Keys::SEPARATOR = "\ue026"; 41 | const QString Keys::SUBTRACT = "\ue027"; 42 | const QString Keys::DECIMAL = "\ue028"; 43 | const QString Keys::DIVIDE = "\ue029"; 44 | const QString Keys::F1 = "\ue031"; 45 | const QString Keys::F2 = "\ue032"; 46 | const QString Keys::F3 = "\ue033"; 47 | const QString Keys::F4 = "\ue034"; 48 | const QString Keys::F5 = "\ue035"; 49 | const QString Keys::F6 = "\ue036"; 50 | const QString Keys::F7 = "\ue037"; 51 | const QString Keys::F8 = "\ue038"; 52 | const QString Keys::F9 = "\ue039"; 53 | const QString Keys::F10 = "\ue03A"; 54 | const QString Keys::F11 = "\ue03B"; 55 | const QString Keys::F12 = "\ue03C"; 56 | const QString Keys::COMMAND = "\ue03D"; 57 | const QString Keys::META = COMMAND; 58 | -------------------------------------------------------------------------------- /selenium/proxy.cpp: -------------------------------------------------------------------------------- 1 | #include "proxy.h" 2 | 3 | Proxy::Proxy(PROXY_TYPE proxyType) 4 | { 5 | setProxyType(proxyType); 6 | } 7 | 8 | Proxy::~Proxy() 9 | { 10 | qDebug()<<"I am destructor ProxyObject!"; 11 | } 12 | 13 | void Proxy::setProxyType(PROXY_TYPE proxyType) 14 | { 15 | m_proxyType = proxyType; 16 | } 17 | 18 | int Proxy::proxyType() 19 | { 20 | return m_proxyType; 21 | } 22 | 23 | /** 24 | * Required for PAC proxy type, Ignored otherwise 25 | */ 26 | void Proxy::setAutoconfigUrl(QString url) 27 | { 28 | if(m_proxyType == PAC) { 29 | 30 | m_proxyAutoconfigUrl = url; 31 | 32 | } else { 33 | qDebug()<<"Required only for PAC proxy type"; 34 | } 35 | } 36 | 37 | QString Proxy::autoconfigUrl() 38 | { 39 | return m_proxyAutoconfigUrl; 40 | } 41 | 42 | /** 43 | * Optional only MANUAL proxy type 44 | */ 45 | void Proxy::setSocksUsername(QString socksUsername) 46 | { 47 | if(m_proxyType == Proxy::MANUAL) { 48 | m_socksUsername = socksUsername; 49 | } else { 50 | qDebug()<<"Optional only MANUAL proxy type"; 51 | } 52 | } 53 | 54 | QString Proxy::socksUsername() 55 | { 56 | return m_socksUsername; 57 | } 58 | 59 | void Proxy::setSocksPassword(QString socksPassword) 60 | { 61 | if(m_proxyType == Proxy::MANUAL) { 62 | m_socksPassword = socksPassword; 63 | } else { 64 | qDebug()<<"Optional only MANUAL proxy type"; 65 | } 66 | } 67 | 68 | QString Proxy::socksPassword() 69 | { 70 | return m_socksPassword; 71 | } 72 | 73 | QString Proxy::toString(int type) 74 | { 75 | QString name; 76 | 77 | switch (type) { 78 | 79 | case DIRECT: 80 | name = "direct"; 81 | break; 82 | 83 | case MANUAL: 84 | name = "manual"; 85 | break; 86 | 87 | case PAC: 88 | name = "pac"; 89 | break; 90 | 91 | case AUTODETECT: 92 | name = "autodetect"; 93 | break; 94 | 95 | case SYSTEM: 96 | name = "system"; 97 | break; 98 | 99 | default: 100 | name = "unknown"; 101 | break; 102 | } 103 | 104 | return name; 105 | } 106 | 107 | Proxy::PROXY_TYPE Proxy::toProxyType(QString text) 108 | { 109 | PROXY_TYPE proxy = UNKNOWN; 110 | 111 | text = text.toLower(); 112 | 113 | if(text == "direct") { 114 | proxy = DIRECT; 115 | 116 | } else if(text == "manual") { 117 | proxy = MANUAL; 118 | 119 | } else if(text == "pac") { 120 | proxy = PAC; 121 | 122 | } else if(text == "autodetect") { 123 | proxy = AUTODETECT; 124 | 125 | } else if(text == "system") { 126 | proxy = SYSTEM; 127 | } 128 | 129 | return proxy; 130 | } 131 | 132 | -------------------------------------------------------------------------------- /selenium/options.cpp: -------------------------------------------------------------------------------- 1 | #include "options.h" 2 | #include "webdriver.h" 3 | #include "webdriverhub.h" 4 | 5 | void Options::deleteAllCookies() 6 | { 7 | m_hub->deleteAllCookie(); 8 | } 9 | 10 | QList Options::cookies() 11 | { 12 | QList cks; 13 | 14 | QList listCookies = m_hub->getAllCookie(); 15 | for(int i = 0; i < listCookies.size(); i++) 16 | { 17 | QJsonObject c = listCookies.at(i); 18 | 19 | QString name = c["name"].toString(); 20 | QString value = c["value"].toString(); 21 | QString path = c["path"].isString() ? c["path"].toString() : ""; 22 | QString domain = c["domain"].isString() ? c["domain"].toString() : ""; 23 | 24 | int time = c["expiry"].isDouble() ? c["expiry"].toInt() : 0; 25 | QDateTime expiry = QDateTime::fromTime_t(time); 26 | 27 | bool isSecure = c["secure"].isBool() ? c["secure"].toBool() : false; 28 | bool isHttpOnly = c["httpOnly"].isBool() ? c["httpOnly"].toBool() : false; 29 | 30 | int hCode = c["hCode"].isDouble() ? c["hCode"].toInt() : 0; 31 | 32 | Cookie *cookie = new Cookie(name, value, path, domain, expiry, isSecure, isHttpOnly); 33 | cookie->setHashCode(hCode); 34 | 35 | cks.push_back(cookie); 36 | } 37 | 38 | return cks; 39 | } 40 | 41 | Cookie* Options::cookieNamed(QString name) 42 | { 43 | QList cks = cookies(); 44 | Cookie* cookie = 0; 45 | for(int i = 0; i < cks.size(); i++) 46 | { 47 | if(cks.at(i)->name() == name) { 48 | cookie = cks.at(i); 49 | break; 50 | } 51 | } 52 | 53 | return cookie; 54 | } 55 | 56 | void Options::addCookie(Cookie *cookie) 57 | { 58 | QJsonObject json; 59 | json["name"] = QString(cookie->name()); 60 | json["value"] = QString(cookie->value()); 61 | json["secure"] = cookie->isSecure(); 62 | json["httpOnly"] = cookie->isHttpOnly(); 63 | json["expiry"] = (int)(cookie->expiry().toTime_t()); 64 | 65 | if(!cookie->path().isEmpty()) { 66 | json["path"] = cookie->path(); 67 | } 68 | 69 | if(!cookie->domain().isEmpty()) { 70 | json["domain"] = cookie->domain(); 71 | } 72 | 73 | m_hub->setCookie(json); 74 | } 75 | 76 | void Options::deleteCookie(Cookie *cookie) 77 | { 78 | deleteCookieNamed(cookie->name()); 79 | } 80 | 81 | void Options::deleteCookieNamed(QString name) 82 | { 83 | m_hub->deleteCookie(name); 84 | } 85 | 86 | Timeouts* Options::timeouts() 87 | { 88 | return new Timeouts(m_driver, m_hub); 89 | } 90 | 91 | Window* Options::window() 92 | { 93 | return new Window(m_driver->windowHandle(), m_hub); 94 | } 95 | 96 | ImeHandler* Options::ime() 97 | { 98 | return new ImeHandler(m_hub); 99 | } 100 | 101 | Logs* Options::logs() 102 | { 103 | return new Logs(m_hub); 104 | } 105 | -------------------------------------------------------------------------------- /selenium/cookie.cpp: -------------------------------------------------------------------------------- 1 | #include "cookie.h" 2 | 3 | Cookie::Cookie(QString name, QString value) 4 | { 5 | init(name, value, "", "", false, false, getDefaultTime()); 6 | } 7 | 8 | Cookie::Cookie(QString name, QString value, QString path) 9 | { 10 | init(name, value, path, "", false, false, getDefaultTime()); 11 | } 12 | 13 | Cookie::Cookie(QString name, QString value, QString path, QDateTime expiry) 14 | { 15 | init(name, value, path, "", false, false, expiry); 16 | } 17 | 18 | Cookie::Cookie(QString name, QString value, QString path, QString domain, QDateTime expiry) 19 | { 20 | init(name, value, path, domain, false, false, expiry); 21 | } 22 | 23 | Cookie::Cookie(QString name, QString value, QString path, QString domain, QDateTime expiry, bool isSecure) 24 | { 25 | init(name, value, path, domain, isSecure, false, expiry); 26 | } 27 | 28 | Cookie::Cookie(QString name, QString value, QString path, QString domain, QDateTime expiry, bool isSecure, bool isHttpOnly) 29 | { 30 | init(name, value, path, domain, isSecure, isHttpOnly, expiry); 31 | } 32 | 33 | void Cookie::init(QString name, QString value, QString path, QString domain, bool secure, bool httpOnly, QDateTime expiry) 34 | { 35 | setName(name); 36 | setValue(value); 37 | setPath(path); 38 | setDomain(domain); 39 | setSecure(secure); 40 | setHttpOnly(httpOnly); 41 | setExpiry(expiry); 42 | setHashCode(0); 43 | } 44 | 45 | QString Cookie::name() 46 | { 47 | return m_name; 48 | } 49 | 50 | QString Cookie::value() 51 | { 52 | return m_value; 53 | } 54 | 55 | QString Cookie::path() 56 | { 57 | return m_path; 58 | } 59 | 60 | QString Cookie::domain() 61 | { 62 | return m_domain; 63 | } 64 | 65 | bool Cookie::isSecure() 66 | { 67 | return m_secure; 68 | } 69 | 70 | bool Cookie::isHttpOnly() 71 | { 72 | return m_httpOnly; 73 | } 74 | 75 | QDateTime Cookie::expiry() 76 | { 77 | return m_expiry; 78 | } 79 | 80 | int Cookie::hashCode() 81 | { 82 | return m_hashCode; 83 | } 84 | 85 | void Cookie::setName(QString name) 86 | { 87 | m_name = name; 88 | } 89 | 90 | void Cookie::setValue(QString value) 91 | { 92 | m_value = value; 93 | } 94 | 95 | void Cookie::setPath(QString path) 96 | { 97 | m_path = path; 98 | } 99 | 100 | void Cookie::setDomain(QString domain) 101 | { 102 | m_domain = domain; 103 | } 104 | 105 | void Cookie::setSecure(bool secure) 106 | { 107 | m_secure = secure; 108 | } 109 | 110 | void Cookie::setHttpOnly(bool only) 111 | { 112 | m_httpOnly = only; 113 | } 114 | 115 | 116 | void Cookie::setExpiry(QDateTime expiry) 117 | { 118 | m_expiry = expiry; 119 | } 120 | 121 | void Cookie::setHashCode(int hashCode) 122 | { 123 | m_hashCode = hashCode; 124 | } 125 | 126 | QDateTime Cookie::getDefaultTime() 127 | { 128 | return QDateTime::fromTime_t(QDateTime::currentDateTime().toTime_t() + 3600); 129 | } 130 | -------------------------------------------------------------------------------- /selenium/server.cpp: -------------------------------------------------------------------------------- 1 | #include "server.h" 2 | #include "webdriverhub.h" 3 | 4 | Server::Server(WebDriverHub* hub) 5 | { 6 | m_hub = new WebDriverHub(hub->host(), hub->port(), hub->capabilities(false)); 7 | } 8 | 9 | Status* Server::status() 10 | { 11 | QJsonObject jsonStatus = m_hub->status(); 12 | 13 | Os* os = new Os(jsonStatus["os"].toObject()); 14 | Build* build = new Build(jsonStatus["build"].toObject()); 15 | 16 | Java* java = 0; 17 | if(jsonStatus["java"].isObject()) { 18 | java = new Java(jsonStatus["java"].toObject()); 19 | } 20 | 21 | return new Status(os, build, java); 22 | } 23 | 24 | QList Server::sessions() 25 | { 26 | QJsonArray jsonSessions = m_hub->sessions(); 27 | 28 | QList list; 29 | 30 | for(int i = 0; i < jsonSessions.size(); i++) { 31 | QJsonObject jsonSession = jsonSessions.at(i).toObject(); 32 | QJsonObject jsonCap = jsonSession["capabilities"].toObject(); 33 | 34 | DesiredCapabilities* c = new DesiredCapabilities(Browser::fromString(jsonCap["browserName"].toString())); 35 | c->setPlatform(Platform::fromString(jsonCap["platform"].toString())); 36 | c->setVersion(jsonCap["version"].toString()); 37 | 38 | if(jsonCap["acceptSslCerts"].isBool()) { 39 | c->setAcceptSslCerts(jsonCap["acceptSslCerts"].toBool()); 40 | } 41 | 42 | if(jsonCap["applicationCacheEnabled"].isBool()) { 43 | c->setApplicationCacheEnabled(jsonCap["applicationCacheEnabled"].toBool()); 44 | } 45 | 46 | if(jsonCap["cssSelectorsEnabled"].isBool()) { 47 | c->setCssSelectorsEnabled(jsonCap["cssSelectorsEnabled"].toBool()); 48 | } 49 | 50 | if(jsonCap["databaseEnabled"].isBool()) { 51 | c->setDatabaseEnabled(jsonCap["databaseEnabled"].toBool()); 52 | } 53 | 54 | if(jsonCap["handlesAlerts"].isBool()) { 55 | c->setHandlesAlerts(jsonCap["handlesAlerts"].toBool()); 56 | } 57 | 58 | if(jsonCap["javascriptEnabled"].isBool()) { 59 | c->setJavascriptEnabled(jsonCap["javascriptEnabled"].toBool()); 60 | } 61 | 62 | if(jsonCap["locationContextEnabled"].isBool()) { 63 | c->setLocationContextEnabled(jsonCap["locationContextEnabled"].toBool()); 64 | } 65 | 66 | if(jsonCap["nativeEvents"].isBool()) { 67 | c->setNativeEvents(jsonCap["nativeEvents"].toBool()); 68 | } 69 | 70 | if(jsonCap["rotatable"].isBool()) { 71 | c->setRotatable(jsonCap["rotatable"].toBool()); 72 | } 73 | 74 | if(jsonCap["takesScreenshot"].isBool()) { 75 | c->setTakesScreenshot(jsonCap["takesScreenshot"].toBool()); 76 | } 77 | 78 | if(jsonCap["webStorageEnabled"].isBool()) { 79 | c->setWebStorageEnabled(jsonCap["webStorageEnabled"].toBool()); 80 | } 81 | 82 | list.push_back(new Session(jsonSession["id"].toString(), c)); 83 | } 84 | 85 | return list; 86 | } 87 | -------------------------------------------------------------------------------- /selenium/webdriver.cpp: -------------------------------------------------------------------------------- 1 | #include "webdriver.h" 2 | #include "webdriverhub.h" 3 | 4 | WebDriver::WebDriver(QString host, int port, Browser::Type browser, QString url) 5 | { 6 | DesiredCapabilities *dc = new DesiredCapabilities(browser); 7 | 8 | init(host, port, dc, url); 9 | } 10 | 11 | WebDriver::WebDriver(QString host, int port, DesiredCapabilities* desiredCapabilities, QString url) 12 | { 13 | init(host, port, desiredCapabilities, url); 14 | } 15 | 16 | WebDriver::WebDriver(QString host, int port, Browser::Type browser) 17 | { 18 | DesiredCapabilities *dc = new DesiredCapabilities(browser); 19 | init(host, port, dc); 20 | } 21 | 22 | WebDriver::WebDriver(QString host, int port, DesiredCapabilities *desiredCapabilities) 23 | { 24 | init(host, port, desiredCapabilities); 25 | } 26 | 27 | WebDriver::~WebDriver() 28 | { 29 | qDebug()<<"I am destructor WebDriver!"; 30 | } 31 | 32 | /** 33 | * Init WebDriverHub 34 | */ 35 | void WebDriver::init(QString host, int port, DesiredCapabilities *dc, QString url) 36 | { 37 | init(host, port, dc); 38 | get(url); 39 | } 40 | 41 | void WebDriver::init(QString host, int port, DesiredCapabilities *dc) 42 | { 43 | m_wdh = new WebDriverHub(host, port, dc); 44 | m_wdh->startSession(); 45 | } 46 | 47 | WebDriverHub* WebDriver::getHub() 48 | { 49 | return m_wdh; 50 | } 51 | 52 | /** 53 | * Get driver capabilities 54 | */ 55 | DesiredCapabilities* WebDriver::capabilities(bool refresh) 56 | { 57 | return m_wdh->capabilities(refresh); 58 | } 59 | 60 | void WebDriver::get(const QString &url) 61 | { 62 | m_wdh->setUrl(url); 63 | } 64 | 65 | void WebDriver::get(QUrl url) 66 | { 67 | get(url.url()); 68 | } 69 | 70 | void WebDriver::quit() 71 | { 72 | m_wdh->deleteSession(); 73 | } 74 | 75 | void WebDriver::close() 76 | { 77 | m_wdh->deleteWindow(); 78 | } 79 | 80 | QString WebDriver::currentUrl() 81 | { 82 | return m_wdh->getUrl(); 83 | } 84 | QString WebDriver::title() 85 | { 86 | return m_wdh->getTitle(); 87 | } 88 | 89 | QString WebDriver::pageSource() 90 | { 91 | return m_wdh->getSource(); 92 | } 93 | 94 | QString WebDriver::windowHandle() 95 | { 96 | return m_wdh->getWindowHandle(); 97 | } 98 | 99 | QStringList WebDriver::windowHandles() 100 | { 101 | return m_wdh->getWindowHandles(); 102 | } 103 | 104 | WebElement* WebDriver::findElement(By *by) 105 | { 106 | QString id = m_wdh->getElement(by->strategy(), by->value()); 107 | return new WebElement(id, m_wdh); 108 | } 109 | 110 | QList WebDriver::findElements(By *by) 111 | { 112 | QStringList ids = m_wdh->getElements(by->strategy(), by->value()); 113 | QList elements; 114 | for(int i = 0; i < ids.size(); i++) { 115 | elements.push_back(new WebElement(ids.at(i), m_wdh)); 116 | } 117 | 118 | return elements; 119 | } 120 | 121 | Navigation* WebDriver::navigate() 122 | { 123 | return new Navigation(this, getHub()); 124 | } 125 | 126 | Options* WebDriver::manage() 127 | { 128 | return new Options(this, getHub()); 129 | } 130 | 131 | TargetLocator* WebDriver::switchTo() 132 | { 133 | return new TargetLocator(getHub()); 134 | } 135 | 136 | Actions* WebDriver::actions() 137 | { 138 | return new Actions(getHub()); 139 | } 140 | 141 | Server* WebDriver::server() 142 | { 143 | return new Server(getHub()); 144 | } 145 | -------------------------------------------------------------------------------- /selenium/webdriverexception.cpp: -------------------------------------------------------------------------------- 1 | #include "webdriverexception.h" 2 | 3 | void WebDriverException::throwException(QString message, int code) 4 | { 5 | switch (code) { 6 | 7 | case ResponseStatusCodes::NO_SUCH_DRIVER: 8 | throw (new NoSuchDriverException(message, code)); 9 | break; 10 | 11 | case ResponseStatusCodes::NO_SUCH_ELEMENT: 12 | throw (new NoSuchElementException(message, code)); 13 | break; 14 | 15 | case ResponseStatusCodes::NO_SUCH_FRAME: 16 | throw (new NoSuchFrameException(message, code)); 17 | break; 18 | 19 | case ResponseStatusCodes::UNKNOWN_COMMAND: 20 | throw (new UnknownCommandException(message, code)); 21 | break; 22 | 23 | case ResponseStatusCodes::STALE_ELEMENT_REFERENCE: 24 | throw (new StaleElementReferenceException(message, code)); 25 | break; 26 | 27 | case ResponseStatusCodes::ELEMENT_NOT_VISIBLE: 28 | throw (new ElementNotVisibleException(message, code)); 29 | break; 30 | 31 | case ResponseStatusCodes::INVALID_ELEMENT_STATE: 32 | throw (new InvalidElementStateException(message, code)); 33 | break; 34 | 35 | case ResponseStatusCodes::UNKNOWN_ERROR: 36 | throw (new UnknownErrorException(message, code)); 37 | break; 38 | 39 | case ResponseStatusCodes::ELEMENT_IS_NOT_SELECTABLE: 40 | throw (new ElementIsNotSelectableException(message, code)); 41 | break; 42 | 43 | case ResponseStatusCodes::JAVA_SCRIPT_ERROR: 44 | throw (new JavaScriptErrorException(message, code)); 45 | break; 46 | 47 | case ResponseStatusCodes::XPATH_LOOKUP_ERROR: 48 | throw (new XpathLookupErrorException(message, code)); 49 | break; 50 | 51 | case ResponseStatusCodes::TIMEOUT: 52 | throw (new TimeoutException(message, code)); 53 | break; 54 | 55 | case ResponseStatusCodes::NO_SUCH_WINDOW: 56 | throw (new NoSuchWindowException(message, code)); 57 | break; 58 | 59 | case ResponseStatusCodes::INVALID_COOKIE_DOMAIN: 60 | throw (new InvalidCookieDomainException(message, code)); 61 | break; 62 | 63 | case ResponseStatusCodes::UNABLE_TO_SET_COOKIE: 64 | throw (new UnableToSetCookieException(message, code)); 65 | break; 66 | 67 | case ResponseStatusCodes::UNEXPECTED_ALERT_OPEN: 68 | throw (new UnexpectedAlertOpenException(message, code)); 69 | break; 70 | 71 | case ResponseStatusCodes::NO_ALERT_OPEN_ERROR: 72 | throw (new NoAlertOpenErrorException(message, code)); 73 | break; 74 | 75 | case ResponseStatusCodes::SCRIPT_TIMEOUT: 76 | throw (new ScriptTimeoutException(message, code)); 77 | break; 78 | 79 | case ResponseStatusCodes::INVALID_ELEMENT_COORDINATES: 80 | throw (new InvalidElementCoordinatesException(message, code)); 81 | break; 82 | 83 | case ResponseStatusCodes::IME_NOT_AVAILABLE: 84 | throw (new ImeNotAvailableException(message, code)); 85 | break; 86 | 87 | case ResponseStatusCodes::IME_ENGINE_ACTIVATION_FAILED: 88 | throw (new ImeEngineActivationFailedException(message, code)); 89 | break; 90 | 91 | case ResponseStatusCodes::INVALID_SELECTOR: 92 | throw (new InvalidSelectorException(message, code)); 93 | break; 94 | 95 | case ResponseStatusCodes::SESSION_NOT_CREATED_EXCEPTION: 96 | throw (new SessionNotCreatedException(message, code)); 97 | break; 98 | 99 | case ResponseStatusCodes::MOVE_TARGET_OUT_OF_BOUNDS: 100 | throw (new MoveTargetOutOfBoundsException(message, code)); 101 | break; 102 | 103 | default: 104 | throw (new WebDriverException(message, code)); 105 | break; 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /tests/html_for_tests/index.html: -------------------------------------------------------------------------------- 1 | 2 | Quelenium Local Test 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 17 | 18 | 19 | 20 | 23 | 24 | 25 | 26 | 29 | 30 | 31 | 32 | 35 | 36 | 37 | 38 | 41 | 42 | 43 | 44 | 47 | 48 | 49 | 50 | 53 | 54 | 55 | 56 | 59 | 60 | 61 | 62 | 67 | 68 | 69 | 70 | 82 | 83 | 84 | 85 | 98 | 99 | 100 |
CaseData
findElementCase1 15 |
findElementCase1 link text
16 |
findElementCase2 21 | findElementCase2 link text 22 |
findElementCase3 27 | findElementCase3 link text 28 |
findElementCase4 33 |
findElementCase4 link text
34 |
findElementCase5 39 | 40 |
findElementCase6 45 | 46 |
findElementCase7 51 |
findElementCase7
52 |
findElementCase8 57 |
findElementCase8
58 |
findElementCase9 63 |
64 |
65 |
66 |
selectIsMultiCase1 71 | 81 |
selectIsMultiCase2 86 | 97 |
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")); 182 | } 183 | 184 | /** 185 | * QString driver->windowHandle() 186 | */ 187 | void QueleniumTest::windowHandleCase1() 188 | { 189 | driver->get(m_testUrl); 190 | QString handle = driver->windowHandle(); 191 | 192 | QVERIFY(!handle.isNull()); 193 | QVERIFY(!handle.isEmpty()); 194 | } 195 | 196 | /** 197 | * QStringList driver->windowHandles() 198 | */ 199 | void QueleniumTest::windowHandlesCase1() 200 | { 201 | driver->get(m_testUrl); 202 | 203 | QString handle = driver->windowHandle(); 204 | QStringList handles = driver->windowHandles(); 205 | 206 | QCOMPARE(handles.size(), 1); 207 | QVERIFY(handles.contains(handle)); 208 | } 209 | 210 | /** 211 | * QStringList driver->windowHandles() 212 | */ 213 | void QueleniumTest::windowHandlesCase2() 214 | { 215 | driver->get(m_testUrl); 216 | 217 | QString handle = driver->windowHandle(); 218 | 219 | WebElement* elm = driver->findElement(By::tagName("body")); 220 | elm->sendKeys(Keys::CONTROL + "n"); 221 | elm->sendKeys(Keys::CONTROL + "n"); 222 | elm->sendKeys(Keys::CONTROL + "n"); 223 | 224 | QStringList handles = driver->windowHandles(); 225 | 226 | QCOMPARE(handles.size(), 4); 227 | QVERIFY(handles.contains(handle)); 228 | } 229 | 230 | /** 231 | * WebElement* driver->findElement(By:id) 232 | */ 233 | void QueleniumTest::findElementCase1() 234 | { 235 | driver->get(m_testUrl); 236 | 237 | WebElement* elm = driver->findElement(By::id("findElementCase1")); 238 | 239 | QVERIFY(!elm->id().isEmpty()); 240 | QCOMPARE(elm->attribute("class"), QString("findElementCase1-css-class")); 241 | } 242 | 243 | /** 244 | * WebElement* driver->findElement(By:linkText) 245 | */ 246 | void QueleniumTest::findElementCase2() 247 | { 248 | driver->get(m_testUrl); 249 | 250 | WebElement* elm = driver->findElement(By::linkText("findElementCase2 link text")); 251 | 252 | QVERIFY(!elm->id().isEmpty()); 253 | QCOMPARE(elm->attribute("class"), QString("findElementCase2-css-class")); 254 | QCOMPARE(elm->text(), QString("findElementCase2 link text")); 255 | } 256 | 257 | /** 258 | * WebElement* driver->findElement(By:partialLinkText) 259 | */ 260 | void QueleniumTest::findElementCase3() 261 | { 262 | driver->get(m_testUrl); 263 | 264 | WebElement* elm = driver->findElement(By::partialLinkText("Case3 link")); 265 | 266 | QVERIFY(!elm->id().isEmpty()); 267 | QCOMPARE(elm->attribute("class"), QString("findElementCase3-css-class")); 268 | QCOMPARE(elm->text(), QString("findElementCase3 link text")); 269 | } 270 | 271 | /** 272 | * WebElement* driver->findElement(By:name) 273 | */ 274 | void QueleniumTest::findElementCase4() 275 | { 276 | driver->get(m_testUrl); 277 | 278 | WebElement* elm = driver->findElement(By::name("findElementCase4")); 279 | 280 | QVERIFY(!elm->id().isEmpty()); 281 | QCOMPARE(elm->attribute("class"), QString("findElementCase4-css-class")); 282 | } 283 | 284 | /** 285 | * WebElement* driver->findElement(By:tagName) 286 | */ 287 | void QueleniumTest::findElementCase5() 288 | { 289 | driver->get(m_testUrl); 290 | 291 | WebElement* elm = driver->findElement(By::tagName("input")); 292 | 293 | QVERIFY(!elm->id().isEmpty()); 294 | QCOMPARE(elm->attribute("name"), QString("findElementCase5")); 295 | } 296 | 297 | /** 298 | * WebElement* driver->findElement(By:xpath) 299 | */ 300 | void QueleniumTest::findElementCase6() 301 | { 302 | driver->get(m_testUrl); 303 | 304 | WebElement* elm = driver->findElement(By::xpath("//input[@id='findElementCase6']")); 305 | 306 | QVERIFY(!elm->id().isEmpty()); 307 | QCOMPARE(elm->attribute("class"), QString("findElementCase6-css-class")); 308 | } 309 | 310 | /** 311 | * WebElement* driver->findElement(By:className) 312 | */ 313 | void QueleniumTest::findElementCase7() 314 | { 315 | driver->get(m_testUrl); 316 | 317 | WebElement* elm = driver->findElement(By::className("findElementCase7-css-class")); 318 | 319 | QVERIFY(!elm->id().isEmpty()); 320 | QCOMPARE(elm->attribute("id"), QString("findElementCase7")); 321 | } 322 | 323 | /** 324 | * WebElement* driver->findElement(By:cssSelector) 325 | */ 326 | void QueleniumTest::findElementCase8() 327 | { 328 | driver->get(m_testUrl); 329 | 330 | WebElement* elm = driver->findElement(By::cssSelector("tr#tr-findElementCase8 > td >.findElementCase8-css-class")); 331 | 332 | QVERIFY(!elm->id().isEmpty()); 333 | QCOMPARE(elm->attribute("id"), QString("findElementCase8")); 334 | } 335 | 336 | /** 337 | * QList driver->findElements(By* by) 338 | */ 339 | void QueleniumTest::findElementsCase1() 340 | { 341 | driver->get(m_testUrl); 342 | 343 | Elements elms = driver->findElements(By::className("findElementCase9-css-class")); 344 | QCOMPARE(elms.size(), 3); 345 | } 346 | /******** NAVIGATION TESTS ********************************************************************************************/ 347 | 348 | /** 349 | * driver->navigate()->back() 350 | */ 351 | void QueleniumTest::navigateBackCase() 352 | { 353 | driver->get(m_testUrl); 354 | driver->get(m_testUrl + "/navigate/back_forward.html"); 355 | 356 | driver->navigate()->back(); 357 | 358 | QCOMPARE(driver->title(), QString("Quelenium Local Test")); 359 | } 360 | 361 | /** 362 | * void driver->navigate()->forward() 363 | */ 364 | void QueleniumTest::navigateForwardCase() 365 | { 366 | driver->get(m_testUrl); 367 | driver->get(m_testUrl + "/navigate/back_forward.html"); 368 | 369 | driver->navigate()->back(); 370 | driver->navigate()->forward(); 371 | 372 | QCOMPARE(driver->title(), QString("This navigateForwardCase navigateBackCase")); 373 | } 374 | 375 | /** 376 | * void driver->navigate()->refresh() 377 | */ 378 | void QueleniumTest::navigateRefreshCase() 379 | { 380 | driver->get(m_testUrl + "/navigate/refresh.html"); 381 | 382 | int time = driver->findElement(By::id("time"))->text().toInt(); 383 | 384 | QThread::sleep(2); 385 | 386 | driver->navigate()->refresh(); 387 | 388 | int time2 = driver->findElement(By::id("time"))->text().toInt(); 389 | 390 | QVERIFY(time2 - time >= 2); 391 | } 392 | 393 | /** 394 | * void driver->navigate()->to(QString) 395 | */ 396 | void QueleniumTest::navigateToCase1() 397 | { 398 | driver->navigate()->to(m_testUrl); 399 | 400 | QCOMPARE(driver->title(), QString("Quelenium Local Test")); 401 | } 402 | 403 | /** 404 | * void driver->navigate()->to(QUrl) 405 | */ 406 | void QueleniumTest::navigateToCase2() 407 | { 408 | QUrl url(m_testUrl+"/404page.html"); 409 | driver->navigate()->to(url); 410 | 411 | QCOMPARE(driver->title(), QString("404")); 412 | } 413 | 414 | /******** MANAGE TESTS ************************************************************************************************/ 415 | 416 | /** 417 | * QList driver->manage()->cookies() 418 | */ 419 | void QueleniumTest::manageCookiesCase() 420 | { 421 | driver->get(m_testUrl + "/cookie/case.html"); 422 | 423 | int result = checkAllCookies(); 424 | 425 | QCOMPARE(result, 3); 426 | } 427 | 428 | /** 429 | * Cookie* driver-manage()->cookieNamed(QString) 430 | */ 431 | void QueleniumTest::manageCookieNamedCase() 432 | { 433 | driver->get(m_testUrl + "/cookie/case.html"); 434 | Cookie* cookie = driver->manage()->cookieNamed("CookieTest2"); 435 | 436 | QCOMPARE(cookie->name(), QString("CookieTest2")); 437 | QCOMPARE(cookie->domain(), m_testUrl); 438 | } 439 | 440 | /** 441 | * void driver->manage()->deleteAllCookies() 442 | */ 443 | void QueleniumTest::manageDeleteAllCookiesCase() 444 | { 445 | driver->get(m_testUrl + "/cookie/case.html"); 446 | driver->manage()->deleteAllCookies(); 447 | 448 | QList list = driver->manage()->cookies(); 449 | QCOMPARE(list.size(), 0); 450 | } 451 | 452 | /** 453 | * void driver->manage()->deleteCookie(Cookie*) 454 | */ 455 | void QueleniumTest::manageDeleteCookieCase() 456 | { 457 | driver->get(m_testUrl + "/cookie/case.html"); 458 | 459 | Cookie* cookie = new Cookie("CookieTest3", ""); 460 | driver->manage()->deleteCookie(cookie); 461 | 462 | int result = checkAllCookies(); 463 | 464 | QCOMPARE(result, 2); 465 | } 466 | 467 | /** 468 | * void driver->manage()->deleteCookie(QString) 469 | */ 470 | void QueleniumTest::manageDeleteCookieNamedCase() 471 | { 472 | driver->get(m_testUrl + "/cookie/case.html"); 473 | driver->manage()->deleteCookieNamed("CookieTest1"); 474 | 475 | int result = checkAllCookies(); 476 | 477 | QCOMPARE(result, 2); 478 | } 479 | 480 | /** 481 | * void driver->manage()->addCookie(Cookie*) 482 | */ 483 | void QueleniumTest::manageAddCookieCase() 484 | { 485 | driver->get(m_testUrl + "/cookie/case.html"); 486 | 487 | QDateTime expiry = QDateTime::fromString("2020-01-02 03:04:05","yyyy-MM-dd HH:mm:ss"); 488 | 489 | //****************************************************************************************************************** 490 | Cookie* cookie1 = new Cookie("TEST1", "VALUE1"); 491 | driver->manage()->addCookie(cookie1); 492 | 493 | Cookie* cookie11 = driver->manage()->cookieNamed("TEST1"); 494 | compareCookie(cookie1, cookie11, "/", m_testUrl); 495 | //****************************************************************************************************************** 496 | 497 | Cookie* cookie2 = new Cookie("TEST2", "VALUE2", "/"); 498 | driver->manage()->addCookie(cookie2); 499 | 500 | Cookie* cookie21 = driver->manage()->cookieNamed("TEST2"); 501 | compareCookie(cookie2, cookie21, "", m_testUrl); 502 | //****************************************************************************************************************** 503 | 504 | Cookie* cookie3 = new Cookie("TEST3", "VALUE3", "/", expiry); 505 | driver->manage()->addCookie(cookie3); 506 | 507 | Cookie* cookie31 = driver->manage()->cookieNamed("TEST3"); 508 | compareCookie(cookie3, cookie31, "", m_testUrl); 509 | //****************************************************************************************************************** 510 | 511 | Cookie* cookie4 = new Cookie("TEST4", "VALUE4", "/", m_testUrl, expiry); 512 | driver->manage()->addCookie(cookie4); 513 | 514 | Cookie* cookie41 = driver->manage()->cookieNamed("TEST4"); 515 | compareCookie(cookie4, cookie41); 516 | //****************************************************************************************************************** 517 | 518 | Cookie* cookie5 = new Cookie("TEST5", "VALUE5", "/", m_testUrl, expiry, true); 519 | driver->manage()->addCookie(cookie5); 520 | 521 | Cookie* cookie51 = driver->manage()->cookieNamed("TEST5"); 522 | compareCookie(cookie5, cookie51); 523 | //****************************************************************************************************************** 524 | 525 | Cookie* cookie6 = new Cookie("TEST6", "VALUE6", "/", m_testUrl, expiry, true, false); 526 | driver->manage()->addCookie(cookie6); 527 | 528 | Cookie* cookie61 = driver->manage()->cookieNamed("TEST6"); 529 | compareCookie(cookie6, cookie61); 530 | 531 | int result = checkAllCookies(); 532 | QCOMPARE(result, 9); 533 | 534 | driver->manage()->deleteCookieNamed("TEST1"); 535 | 536 | result = checkAllCookies(); 537 | QCOMPARE(result, 8); 538 | 539 | driver->manage()->deleteCookie(cookie2); 540 | result = checkAllCookies(); 541 | QCOMPARE(result, 7); 542 | 543 | driver->manage()->deleteAllCookies(); 544 | QList list = driver->manage()->cookies(); 545 | 546 | QCOMPARE(list.size(), 0); 547 | } 548 | 549 | /******** WINDOW TESTS ************************************************************************************************/ 550 | 551 | /** 552 | * Screen FullHD KDE 553 | */ 554 | 555 | /** 556 | * QSize driver->manage()->window()->size() 557 | */ 558 | void QueleniumTest::windowSizeCase() 559 | { 560 | QSize size = driver->manage()->window()->size(); 561 | QCOMPARE(size.width(), 1440); 562 | QCOMPARE(size.height(), 782); 563 | } 564 | 565 | /** 566 | * void driver->manage()->window()->setSize(int, int) 567 | */ 568 | void QueleniumTest::windowSetSizeCase1() 569 | { 570 | driver->manage()->window()->setSize(1350, 698); 571 | 572 | QSize size = driver->manage()->window()->size(); 573 | 574 | QCOMPARE(size.width(), 1350); 575 | QCOMPARE(size.height(), 698); 576 | } 577 | 578 | /** 579 | * void driver->manage()->window()->setSize(QSize) 580 | */ 581 | void QueleniumTest::windowSetSizeCase2() 582 | { 583 | QSize size(1569, 300); 584 | driver->manage()->window()->setSize(size); 585 | 586 | QSize size1 = driver->manage()->window()->size(); 587 | 588 | QCOMPARE(size, size1); 589 | } 590 | 591 | /** 592 | * void driver->manage()->window()->maximize() 593 | */ 594 | void QueleniumTest::windowMaximizeCase() 595 | { 596 | QSize size1 = driver->manage()->window()->size(); 597 | 598 | driver->manage()->window()->maximize(); 599 | driver->get(m_testUrl); 600 | 601 | QSize size2 = driver->manage()->window()->size(); 602 | 603 | QVERIFY(size2.width() > size1.width()); 604 | QVERIFY(size2.height() > size1.height()); 605 | 606 | QCOMPARE(size2.width(), 1920); 607 | QCOMPARE(size2.height(), 1025); 608 | } 609 | 610 | /** 611 | * QPoint driver->manage()->window()->position() 612 | */ 613 | void QueleniumTest::windowPositionCase() 614 | { 615 | driver->get(m_testUrl); 616 | QPoint pos = driver->manage()->window()->position(); 617 | 618 | QCOMPARE(pos.x(), -2); 619 | QCOMPARE(pos.y(), 236); 620 | } 621 | 622 | /** 623 | * void driver->manage()->window()->setPosition(int, int) 624 | */ 625 | void QueleniumTest::windowSetPositionCase1() 626 | { 627 | driver->manage()->window()->setSize(200,200); 628 | driver->get(m_testUrl); 629 | 630 | driver->manage()->window()->setPosition(500,500); 631 | driver->navigate()->refresh(); 632 | 633 | QPoint pos = driver->manage()->window()->position(); 634 | 635 | QCOMPARE(pos.x(), 500); 636 | QCOMPARE(pos.y(), 500); 637 | } 638 | 639 | /** 640 | * void driver->manage()->window()->setPosition(QPoint) 641 | */ 642 | void QueleniumTest::windowSetPositionCase2() 643 | { 644 | driver->manage()->window()->setSize(200,200); 645 | driver->get(m_testUrl); 646 | 647 | QPoint pos(10,24); 648 | 649 | driver->manage()->window()->setPosition(pos); 650 | driver->navigate()->refresh(); 651 | 652 | QPoint pos1 = driver->manage()->window()->position(); 653 | 654 | QCOMPARE(pos, pos1); 655 | } 656 | 657 | /******** TIMEOUTS TESTS **********************************************************************************************/ 658 | /** 659 | * void driver->manage()->timeouts()->setScriptTimeout(long) 660 | */ 661 | void QueleniumTest::timeoutsSetScriptTimeoutCase() 662 | { 663 | driver->get(m_testUrl); 664 | driver->manage()->timeouts()->setScriptTimeout(10000); 665 | } 666 | 667 | /** 668 | * void driver->manage()->timeouts()->pageLoadTimeout(long) 669 | */ 670 | void QueleniumTest::timeoutsPageLoadTimeoutCase() 671 | { 672 | driver->get(m_testUrl); 673 | driver->manage()->timeouts()->pageLoadTimeout(10000); 674 | } 675 | 676 | /** 677 | * void driver->manage()->timeouts()->implicitlyWait(long) 678 | */ 679 | void QueleniumTest::timeoutsImplicitlyWaitCase() 680 | { 681 | driver->get(m_testUrl); 682 | driver->manage()->timeouts()->implicitlyWait(10000); 683 | } 684 | 685 | /******** IMEHANDLER TESTS ********************************************************************************************/ 686 | /** 687 | * QStringList driver->manage()->ime()->availableEngines() 688 | */ 689 | void QueleniumTest::imeGetAvailableEnginesCase() 690 | { 691 | try { 692 | /*QStringList list = */driver->manage()->ime()->availableEngines(); 693 | } catch(UnknownErrorException* e) { 694 | QFAIL(e->message().toUtf8()); 695 | } 696 | } 697 | 698 | /** 699 | * QString driver->manage()->ime()->activeEngine() 700 | */ 701 | void QueleniumTest::imeGetActiveEngineCase() 702 | { 703 | try { 704 | /*QString engine = */driver->manage()->ime()->activeEngine(); 705 | } catch(UnknownErrorException* e) { 706 | QFAIL(e->message().toUtf8()); 707 | } 708 | } 709 | 710 | /** 711 | * void driver->manage()->ime()->activateEngine(QString) 712 | */ 713 | void QueleniumTest::imeActivateEngineCase() 714 | { 715 | try{ 716 | driver->manage()->ime()->activateEngine(""); 717 | } catch(UnknownErrorException* e) { 718 | QFAIL(e->message().toUtf8()); 719 | } 720 | } 721 | 722 | /** 723 | * void driver->manage()->ime()->deactivate() 724 | */ 725 | void QueleniumTest::imeDeactivateCase() 726 | { 727 | try { 728 | driver->manage()->ime()->deactivate(); 729 | } catch(UnknownErrorException* e) { 730 | QFAIL(e->message().toUtf8()); 731 | } 732 | } 733 | 734 | /** 735 | * bool driver->manage()->ime()->isActivated() 736 | */ 737 | void QueleniumTest::imeIsActivatedCase() 738 | { 739 | try { 740 | /*bool activated = */driver->manage()->ime()->isActivated(); 741 | } catch(UnknownErrorException* e) { 742 | QFAIL(e->message().toUtf8()); 743 | } 744 | } 745 | 746 | /******** LOGS TESTS **************************************************************************************************/ 747 | /** 748 | * QStringList driver->manage()->logs()->availableLogTypes() 749 | */ 750 | void QueleniumTest::logsGetAvailableLogTypesCase() 751 | { 752 | QStringList list = driver->manage()->logs()->availableLogTypes(); 753 | 754 | QCOMPARE(list.size(), 4); 755 | } 756 | 757 | /** 758 | * QList driver->manage()->logs()->get(QString); 759 | */ 760 | void QueleniumTest::logsGetCase() 761 | { 762 | driver->get(m_testUrl); 763 | driver->manage()->window()->setSize(-1,-1); 764 | 765 | QStringList listTypes = driver->manage()->logs()->availableLogTypes(); 766 | 767 | for(int i = 0; i < listTypes.size(); i++) 768 | { 769 | QList logs = driver->manage()->logs()->get(listTypes.at(i)); 770 | QVERIFY(logs.size() >= 0); 771 | } 772 | } 773 | 774 | /******** MOUSE TESTS *************************************************************************************************/ 775 | /** 776 | * void driver->actions()->mouse()->moveTo(WebElement*) 777 | */ 778 | void QueleniumTest::mouseMoveToCase1() 779 | { 780 | driver->get(m_testUrl + "/mouse/move_to.html"); 781 | driver->manage()->window()->maximize(); 782 | 783 | //TODO change to WebDriver Wait in future 784 | QThread::sleep(2); 785 | 786 | WebElement* elm1 = driver->findElement(By::id("element1")); 787 | 788 | driver->actions()->mouse()->moveTo(elm1); 789 | 790 | WebElement* elm2 = driver->findElement(By::id("element2")); 791 | QVERIFY(elm2->isDisplayed()); 792 | } 793 | 794 | /** 795 | * void driver->actions()->mouse()->moveTo(int, int) 796 | */ 797 | void QueleniumTest::mouseMoveToCase2() 798 | { 799 | driver->get(m_testUrl + "/mouse/move_to.html"); 800 | driver->manage()->window()->maximize(); 801 | 802 | //TODO change to WebDriver Wait in future 803 | QThread::sleep(2); 804 | 805 | driver->actions()->mouse()->moveTo(10, 10); 806 | 807 | WebElement* elm = driver->findElement(By::id("element2")); 808 | QVERIFY(elm->isDisplayed()); 809 | } 810 | 811 | /** 812 | * void driver->actions()->mouse()->moveTo(QPoint) 813 | */ 814 | void QueleniumTest::mouseMoveToCase3() 815 | { 816 | driver->get(m_testUrl + "/mouse/move_to.html"); 817 | driver->manage()->window()->maximize(); 818 | 819 | //TODO change to WebDriver Wait in future 820 | QThread::sleep(2); 821 | 822 | driver->actions()->mouse()->moveTo(QPoint(10, 10)); 823 | 824 | WebElement* elm = driver->findElement(By::id("element2")); 825 | QVERIFY(elm->isDisplayed()); 826 | } 827 | 828 | /** 829 | * void driver->actions()->mouse()->click() 830 | */ 831 | void QueleniumTest::mouseClickCase1() 832 | { 833 | mouseButtonEvents("click - 1", CLICK); 834 | } 835 | 836 | /** 837 | * void driver->actions()->mouse()->click(Mouse::LEFT) 838 | */ 839 | void QueleniumTest::mouseClickCase2() 840 | { 841 | mouseButtonEvents("click - 1", CLICK, Mouse::LEFT); 842 | } 843 | 844 | /** 845 | * void driver->actions()->mouse()->click(Mouse::MIDDLE) 846 | */ 847 | void QueleniumTest::mouseClickCase3() 848 | { 849 | mouseButtonEvents("click - 2", CLICK, Mouse::MIDDLE); 850 | } 851 | 852 | /** 853 | * void driver->actions()->mouse()->click(Mouse::RIGHT) 854 | */ 855 | void QueleniumTest::mouseClickCase4() 856 | { 857 | mouseButtonEvents("contextmenu - 3", CLICK, Mouse::RIGHT); 858 | } 859 | 860 | /** 861 | * void driver->actions()->mouse()->buttondown() 862 | */ 863 | void QueleniumTest::mouseButtonDownCase1() 864 | { 865 | mouseButtonEvents("mousedown - 1", DOWN); 866 | } 867 | 868 | /** 869 | * void driver->actions()->mouse()->buttondown(Mouse::LEFT) 870 | */ 871 | void QueleniumTest::mouseButtonDownCase2() 872 | { 873 | mouseButtonEvents("mousedown - 1", DOWN, Mouse::LEFT); 874 | } 875 | 876 | /** 877 | * void driver->actions()->mouse()->buttondown(Mouse::RIGHT) 878 | */ 879 | void QueleniumTest::mouseButtonDownCase3() 880 | { 881 | //TODO Not work in Selenium Server Standalone 2.x. Only default value (LEFT) 882 | mouseButtonEvents("mousedown - 3", DOWN, Mouse::RIGHT); 883 | } 884 | 885 | /** 886 | * void driver->actions()->mouse()->buttondown(Mouse::MIDDLE) 887 | */ 888 | void QueleniumTest::mouseButtonDownCase4() 889 | { 890 | //TODO Not work in Selenium Server Standalone 2.x. Only default value (LEFT) 891 | mouseButtonEvents("mousedown - 2", DOWN, Mouse::MIDDLE); 892 | } 893 | 894 | /** 895 | * void driver->actions()->mouse()->buttonup() 896 | */ 897 | void QueleniumTest::mouseButtonUpCase1() 898 | { 899 | mouseButtonEvents("click - 1", UP); 900 | } 901 | 902 | /** 903 | * void driver->actions()->mouse()->buttonup(Mouse::LEFT) 904 | */ 905 | void QueleniumTest::mouseButtonUpCase2() 906 | { 907 | mouseButtonEvents("click - 1", UP, Mouse::LEFT); 908 | } 909 | 910 | /** 911 | * void driver->actions()->mouse()->buttonup(Mouse::RIGHT) 912 | */ 913 | void QueleniumTest::mouseButtonUpCase3() 914 | { 915 | mouseButtonEvents("click - 1", UP, Mouse::RIGHT); 916 | } 917 | 918 | /** 919 | * void driver->actions()->mouse()->buttonup(Mouse::MIDDLE) 920 | */ 921 | void QueleniumTest::mouseButtonUpCase4() 922 | { 923 | mouseButtonEvents("mouseup - 1", UP, Mouse::MIDDLE); 924 | } 925 | 926 | /** 927 | * void driver->actions()->mouse()->doubleclick() 928 | */ 929 | void QueleniumTest::mouseDoubleClickCase1() 930 | { 931 | mouseButtonEvents("dblclick - 1", CLICK_DOUBLE); 932 | } 933 | 934 | /******** WEBDRIVER EXCEPTIONS TESTS **********************************************************************************/ 935 | /** 936 | * UnknownErrorException 937 | * 938 | * void driver->get(QString) 939 | */ 940 | void QueleniumTest::getEmptyExceptionCase1() 941 | { 942 | try { 943 | driver->get(""); 944 | } catch (UnknownErrorException* e) { 945 | QVERIFY(e->code() != 0); 946 | QVERIFY(!e->message().isEmpty()); 947 | } catch(...) { 948 | QFAIL("Not UnknownErrorException"); 949 | } 950 | } 951 | 952 | /** 953 | * UnknownErrorException 954 | * 955 | * void driver->get(QUrl) 956 | */ 957 | void QueleniumTest::getEmptyExceptionCase2() 958 | { 959 | try { 960 | QUrl url; 961 | driver->get(url); 962 | } catch (UnknownErrorException* e) { 963 | QVERIFY(e->code() != 0); 964 | QVERIFY(!e->message().isEmpty()); 965 | } catch(...) { 966 | QFAIL("Not UnknownErrorException"); 967 | } 968 | } 969 | 970 | /** 971 | * NoSuchWindowException 972 | * 973 | * void driver->get(QString) 974 | */ 975 | void QueleniumTest::getNoSuchWindowExceptionCase1() 976 | { 977 | notFoundWindow(); 978 | 979 | try { 980 | getCase1(); 981 | } catch (NoSuchWindowException* e) { 982 | QVERIFY(e->code() != 0); 983 | QVERIFY(!e->message().isEmpty()); 984 | } catch(...) { 985 | QFAIL("Not NoSuchWindowException"); 986 | } 987 | } 988 | 989 | /** 990 | * NoSuchWindowException 991 | * 992 | * void driver->get(QUrl) 993 | */ 994 | void QueleniumTest::getNoSuchWindowExceptionCase2() 995 | { 996 | notFoundWindow(); 997 | 998 | try { 999 | getCase2(); 1000 | } catch (NoSuchWindowException* e) { 1001 | QVERIFY(e->code() != 0); 1002 | QVERIFY(!e->message().isEmpty()); 1003 | } catch(...) { 1004 | QFAIL("Not NoSuchWindowException"); 1005 | } 1006 | } 1007 | 1008 | /** 1009 | * NoSuchWindowException 1010 | * 1011 | * QString driver->getTitle() 1012 | */ 1013 | void QueleniumTest::titleNoSuchWindowExceptionCase1() 1014 | { 1015 | notFoundWindow(); 1016 | 1017 | try { 1018 | titleCase1(); 1019 | } catch (NoSuchWindowException* e) { 1020 | QVERIFY(e->code() != 0); 1021 | QVERIFY(!e->message().isEmpty()); 1022 | } catch(...) { 1023 | QFAIL("Not NoSuchWindowException"); 1024 | } 1025 | } 1026 | 1027 | /** 1028 | * NoSuchWindowException 1029 | * 1030 | * QString driver->getPageSource() 1031 | */ 1032 | void QueleniumTest::pageSourceNoSuchWindowExceptionCase1() 1033 | { 1034 | notFoundWindow(); 1035 | 1036 | try { 1037 | pageSourceCase1(); 1038 | } catch (NoSuchWindowException* e) { 1039 | QVERIFY(e->code() != 0); 1040 | QVERIFY(!e->message().isEmpty()); 1041 | } catch(...) { 1042 | QFAIL("Not NoSuchWindowException"); 1043 | } 1044 | } 1045 | 1046 | /** 1047 | * NoSuchWindowException 1048 | * 1049 | * QString driver->getWindowHandle() 1050 | */ 1051 | void QueleniumTest::windowHandleNoSuchWindowExceptionCase1() 1052 | { 1053 | notFoundWindow(); 1054 | 1055 | try { 1056 | windowHandleCase1(); 1057 | } catch (NoSuchWindowException* e) { 1058 | QVERIFY(e->code() != 0); 1059 | QVERIFY(!e->message().isEmpty()); 1060 | } catch(...) { 1061 | QFAIL("Not NoSuchWindowException"); 1062 | } 1063 | } 1064 | 1065 | /** 1066 | * NoSuchWindowException 1067 | * 1068 | * QStringList driver->getWindowHandles() 1069 | */ 1070 | void QueleniumTest::windowHandlesNoSuchWindowExceptionCase1() 1071 | { 1072 | notFoundWindow(); 1073 | 1074 | try { 1075 | windowHandlesCase1(); 1076 | } catch (NoSuchWindowException* e) { 1077 | QVERIFY(e->code() != 0); 1078 | QVERIFY(!e->message().isEmpty()); 1079 | } catch(...) { 1080 | QFAIL("Not NoSuchWindowException"); 1081 | } 1082 | } 1083 | 1084 | /** 1085 | * NoSuchWindowException 1086 | * 1087 | * WebElement* driver->findElement(By::id) 1088 | */ 1089 | void QueleniumTest::findElementNoSuchWindowExceptionCase1() 1090 | { 1091 | notFoundWindow(); 1092 | 1093 | try { 1094 | findElementCase1(); 1095 | } catch (NoSuchWindowException* e) { 1096 | QVERIFY(e->code() != 0); 1097 | QVERIFY(!e->message().isEmpty()); 1098 | } catch(...) { 1099 | QFAIL("Not NoSuchWindowException"); 1100 | } 1101 | } 1102 | 1103 | /** 1104 | * NoSuchWindowException 1105 | * 1106 | * WebElement* driver->findElement(By::linkText) 1107 | */ 1108 | void QueleniumTest::findElementNoSuchWindowExceptionCase2() 1109 | { 1110 | notFoundWindow(); 1111 | 1112 | try { 1113 | findElementCase2(); 1114 | } catch (NoSuchWindowException* e) { 1115 | QVERIFY(e->code() != 0); 1116 | QVERIFY(!e->message().isEmpty()); 1117 | } catch(...) { 1118 | QFAIL("Not NoSuchWindowException"); 1119 | } 1120 | } 1121 | 1122 | /** 1123 | * NoSuchWindowException 1124 | * 1125 | * WebElement* driver->findElement(By::partialLinkText) 1126 | */ 1127 | void QueleniumTest::findElementNoSuchWindowExceptionCase3() 1128 | { 1129 | notFoundWindow(); 1130 | 1131 | try { 1132 | findElementCase3(); 1133 | } catch (NoSuchWindowException* e) { 1134 | QVERIFY(e->code() != 0); 1135 | QVERIFY(!e->message().isEmpty()); 1136 | } catch(...) { 1137 | QFAIL("Not NoSuchWindowException"); 1138 | } 1139 | } 1140 | 1141 | /** 1142 | * NoSuchWindowException 1143 | * 1144 | * WebElement* driver->findElement(By::name) 1145 | */ 1146 | void QueleniumTest::findElementNoSuchWindowExceptionCase4() 1147 | { 1148 | notFoundWindow(); 1149 | 1150 | try { 1151 | findElementCase4(); 1152 | } catch (NoSuchWindowException* e) { 1153 | QVERIFY(e->code() != 0); 1154 | QVERIFY(!e->message().isEmpty()); 1155 | } catch(...) { 1156 | QFAIL("Not NoSuchWindowException"); 1157 | } 1158 | } 1159 | 1160 | /** 1161 | * NoSuchWindowException 1162 | * 1163 | * WebElement* driver->findElement(By::tagName) 1164 | */ 1165 | void QueleniumTest::findElementNoSuchWindowExceptionCase5() 1166 | { 1167 | notFoundWindow(); 1168 | 1169 | try { 1170 | findElementCase5(); 1171 | } catch (NoSuchWindowException* e) { 1172 | QVERIFY(e->code() != 0); 1173 | QVERIFY(!e->message().isEmpty()); 1174 | } catch(...) { 1175 | QFAIL("Not NoSuchWindowException"); 1176 | } 1177 | } 1178 | 1179 | /** 1180 | * NoSuchWindowException 1181 | * 1182 | * WebElement* driver->findElement(By::xpath) 1183 | */ 1184 | void QueleniumTest::findElementNoSuchWindowExceptionCase6() 1185 | { 1186 | notFoundWindow(); 1187 | 1188 | try { 1189 | findElementCase6(); 1190 | } catch (NoSuchWindowException* e) { 1191 | QVERIFY(e->code() != 0); 1192 | QVERIFY(!e->message().isEmpty()); 1193 | } catch(...) { 1194 | QFAIL("Not NoSuchWindowException"); 1195 | } 1196 | } 1197 | 1198 | /** 1199 | * NoSuchWindowException 1200 | * 1201 | * WebElement* driver->findElement(By::className) 1202 | */ 1203 | void QueleniumTest::findElementNoSuchWindowExceptionCase7() 1204 | { 1205 | notFoundWindow(); 1206 | 1207 | try { 1208 | findElementCase7(); 1209 | } catch (NoSuchWindowException* e) { 1210 | QVERIFY(e->code() != 0); 1211 | QVERIFY(!e->message().isEmpty()); 1212 | } catch(...) { 1213 | QFAIL("Not NoSuchWindowException"); 1214 | } 1215 | } 1216 | 1217 | /** 1218 | * NoSuchWindowException 1219 | * 1220 | * WebElement* driver->findElement(By::cssSelector) 1221 | */ 1222 | void QueleniumTest::findElementNoSuchWindowExceptionCase8() 1223 | { 1224 | notFoundWindow(); 1225 | 1226 | try { 1227 | findElementCase8(); 1228 | } catch (NoSuchWindowException* e) { 1229 | QVERIFY(e->code() != 0); 1230 | QVERIFY(!e->message().isEmpty()); 1231 | } catch(...) { 1232 | QFAIL("Not NoSuchWindowException"); 1233 | } 1234 | } 1235 | 1236 | /** 1237 | * NoSuchElementException 1238 | * 1239 | * WebElement* driver->findElement(By::id) 1240 | */ 1241 | void QueleniumTest::findElementNoSuchElementExceptionCase1() 1242 | { 1243 | try { 1244 | driver->findElement(By::id("qwertyuiop")); 1245 | } catch(NoSuchElementException* e) { 1246 | QVERIFY(e->code() != 0); 1247 | QVERIFY(!e->message().isEmpty()); 1248 | } catch(...) { 1249 | QFAIL("Not NoSuchElementException"); 1250 | } 1251 | } 1252 | 1253 | /** 1254 | * NoSuchElementException 1255 | * 1256 | * WebElement* driver->findElement(By::linkText) 1257 | */ 1258 | void QueleniumTest::findElementNoSuchElementExceptionCase2() 1259 | { 1260 | try { 1261 | driver->findElement(By::linkText("qwertyuiop")); 1262 | } catch(NoSuchElementException* e) { 1263 | QVERIFY(e->code() != 0); 1264 | QVERIFY(!e->message().isEmpty()); 1265 | } catch(...) { 1266 | QFAIL("Not NoSuchElementException"); 1267 | } 1268 | } 1269 | 1270 | /** 1271 | * NoSuchElementException 1272 | * 1273 | * WebElement* driver->findElement(By::partialLinkText) 1274 | */ 1275 | void QueleniumTest::findElementNoSuchElementExceptionCase3() 1276 | { 1277 | try { 1278 | driver->findElement(By::partialLinkText("qwertyuiop")); 1279 | } catch(NoSuchElementException* e) { 1280 | QVERIFY(e->code() != 0); 1281 | QVERIFY(!e->message().isEmpty()); 1282 | } catch(...) { 1283 | QFAIL("Not NoSuchElementException"); 1284 | } 1285 | } 1286 | 1287 | /** 1288 | * NoSuchElementException 1289 | * 1290 | * WebElement* driver->findElement(By::name) 1291 | */ 1292 | void QueleniumTest::findElementNoSuchElementExceptionCase4() 1293 | { 1294 | try { 1295 | driver->findElement(By::name("qwertyuiop")); 1296 | } catch(NoSuchElementException* e) { 1297 | QVERIFY(e->code() != 0); 1298 | QVERIFY(!e->message().isEmpty()); 1299 | } catch(...) { 1300 | QFAIL("Not NoSuchElementException"); 1301 | } 1302 | } 1303 | 1304 | /** 1305 | * NoSuchElementException 1306 | * 1307 | * WebElement* driver->findElement(By::tagName) 1308 | */ 1309 | void QueleniumTest::findElementNoSuchElementExceptionCase5() 1310 | { 1311 | try { 1312 | driver->findElement(By::tagName("qwertyuiop")); 1313 | } catch(NoSuchElementException* e) { 1314 | QVERIFY(e->code() != 0); 1315 | QVERIFY(!e->message().isEmpty()); 1316 | } catch(...) { 1317 | QFAIL("Not NoSuchElementException"); 1318 | } 1319 | } 1320 | 1321 | /** 1322 | * NoSuchElementException 1323 | * 1324 | * WebElement* driver->findElement(By::xpath) 1325 | */ 1326 | void QueleniumTest::findElementNoSuchElementExceptionCase6() 1327 | { 1328 | try { 1329 | driver->findElement(By::xpath("//input[@id='qwertyuiop']")); 1330 | } catch(NoSuchElementException* e) { 1331 | QVERIFY(e->code() != 0); 1332 | QVERIFY(!e->message().isEmpty()); 1333 | } catch(...) { 1334 | QFAIL("Not NoSuchElementException"); 1335 | } 1336 | } 1337 | 1338 | /** 1339 | * NoSuchElementException 1340 | * 1341 | * WebElement* driver->findElement(By::className) 1342 | */ 1343 | void QueleniumTest::findElementNoSuchElementExceptionCase7() 1344 | { 1345 | try { 1346 | driver->findElement(By::className("qwertyuiop")); 1347 | } catch(NoSuchElementException* e) { 1348 | QVERIFY(e->code() != 0); 1349 | QVERIFY(!e->message().isEmpty()); 1350 | } catch(...) { 1351 | QFAIL("Not NoSuchElementException"); 1352 | } 1353 | } 1354 | 1355 | /** 1356 | * NoSuchElementException 1357 | * 1358 | * WebElement* driver->findElement(By::cssSelector) 1359 | */ 1360 | void QueleniumTest::findElementNoSuchElementExceptionCase8() 1361 | { 1362 | try { 1363 | driver->findElement(By::cssSelector("#qwertyuiop > .ssssssss")); 1364 | } catch(NoSuchElementException* e) { 1365 | QVERIFY(e->code() != 0); 1366 | QVERIFY(!e->message().isEmpty()); 1367 | } catch(...) { 1368 | QFAIL("Not NoSuchElementException"); 1369 | } 1370 | } 1371 | 1372 | /** 1373 | * InvalidSelectorException 1374 | * 1375 | * WebElement* driver->findElement(By::xpath) 1376 | */ 1377 | void QueleniumTest::findElementInvalidSelectorExceptionCase1() 1378 | { 1379 | try { 1380 | driver->findElement(By::xpath("//input[ddddd")); 1381 | } catch(InvalidSelectorException* e) { 1382 | QVERIFY(e->code() != 0); 1383 | QVERIFY(!e->message().isEmpty()); 1384 | } catch(...) { 1385 | QFAIL("Not InvalidSelectorException"); 1386 | } 1387 | } 1388 | 1389 | /** 1390 | * InvalidSelectorException 1391 | * 1392 | * WebElement* driver->findElement(By::cssSelector) 1393 | */ 1394 | void QueleniumTest::findElementInvalidSelectorExceptionCase2() 1395 | { 1396 | try { 1397 | driver->findElement(By::cssSelector("border:bugaga;")); 1398 | } catch(InvalidSelectorException* e) { 1399 | QVERIFY(e->code() != 0); 1400 | QVERIFY(!e->message().isEmpty()); 1401 | } catch(...) { 1402 | QFAIL("Not InvalidSelectorException"); 1403 | } 1404 | } 1405 | 1406 | /******** SELECT TESTS **********************************************************************************/ 1407 | /** 1408 | * bool element->isMultiple() 1409 | */ 1410 | void QueleniumTest::selectIsMultiCase1() 1411 | { 1412 | driver->get(m_testUrl); 1413 | 1414 | Select* elm = new Select(driver->findElement(By::id("selectIsMultiCase1"))); 1415 | QVERIFY(!elm->isMultiple()); 1416 | } 1417 | 1418 | /** 1419 | * bool element->isMultiple() 1420 | */ 1421 | void QueleniumTest::selectIsMultiCase2() 1422 | { 1423 | driver->get(m_testUrl); 1424 | 1425 | Select* elm = new Select(driver->findElement(By::id("selectIsMultiCase2"))); 1426 | QVERIFY(elm->isMultiple()); 1427 | } 1428 | 1429 | /** 1430 | * QList element->options() 1431 | */ 1432 | void QueleniumTest::selectOptionsCase1() 1433 | { 1434 | driver->get(m_testUrl); 1435 | 1436 | Select* elm1 = new Select(driver->findElement(By::id("selectIsMultiCase1"))); 1437 | Elements opts1 = elm1->options(); 1438 | 1439 | QCOMPARE(opts1.size(), 6); 1440 | /*****************************************************************************************************/ 1441 | 1442 | Select* elm2 = new Select(driver->findElement(By::id("selectIsMultiCase2"))); 1443 | Elements opts2 = elm2->options(); 1444 | 1445 | QCOMPARE(opts2.size(), 7); 1446 | } 1447 | 1448 | /** 1449 | * QList element->allSelectedOptions() 1450 | */ 1451 | void QueleniumTest::selectAllSelectedOptionsCase1() 1452 | { 1453 | driver->get(m_testUrl); 1454 | 1455 | Select* elm = new Select(driver->findElement(By::id("selectIsMultiCase1"))); 1456 | Elements opts = elm->allSelectedOptions(); 1457 | 1458 | QCOMPARE(opts.size(), 1); 1459 | } 1460 | 1461 | /** 1462 | * QList element->allSelectedOptions() 1463 | */ 1464 | void QueleniumTest::selectAllSelectedOptionsCase2() 1465 | { 1466 | driver->get(m_testUrl); 1467 | 1468 | Select* elm = new Select(driver->findElement(By::id("selectIsMultiCase2"))); 1469 | Elements opts = elm->allSelectedOptions(); 1470 | 1471 | QCOMPARE(opts.size(), 4); 1472 | } 1473 | 1474 | /** 1475 | * WebElement* element->firstSelectedOption() 1476 | */ 1477 | void QueleniumTest::selectFirstSelectedOptionCase1() 1478 | { 1479 | driver->get(m_testUrl); 1480 | 1481 | Select* elm = new Select(driver->findElement(By::id("selectIsMultiCase1"))); 1482 | WebElement* opt = elm->firstSelectedOption(); 1483 | 1484 | QCOMPARE(opt->attribute("value"), QString("item3")); 1485 | } 1486 | 1487 | /** 1488 | * WebElement* element->firstSelectedOption() 1489 | */ 1490 | void QueleniumTest::selectFirstSelectedOptionCase2() 1491 | { 1492 | driver->get(m_testUrl); 1493 | 1494 | Select* elm = new Select(driver->findElement(By::id("selectIsMultiCase2"))); 1495 | WebElement* opt = elm->firstSelectedOption(); 1496 | 1497 | QCOMPARE(opt->attribute("value"), QString("item2")); 1498 | } 1499 | 1500 | /** 1501 | * void element->selectByVisibleText(QString) 1502 | */ 1503 | void QueleniumTest::selectByVisibleTextCase1() 1504 | { 1505 | driver->get(m_testUrl); 1506 | 1507 | Select* elm = new Select(driver->findElement(By::id("selectIsMultiCase1"))); 1508 | elm->selectByVisibleText("SUBITEM2"); 1509 | 1510 | WebElement* opt = elm->firstSelectedOption(); 1511 | QCOMPARE(opt->attribute("value"), QString("subitem2")); 1512 | } 1513 | 1514 | /** 1515 | * void element->selectByVisibleText(QString) 1516 | */ 1517 | void QueleniumTest::selectByVisibleTextCase2() 1518 | { 1519 | driver->get(m_testUrl); 1520 | 1521 | Select* elm = new Select(driver->findElement(By::id("selectIsMultiCase2"))); 1522 | elm->selectByVisibleText("SUBITEM1"); 1523 | elm->selectByVisibleText("SUBITEM2"); 1524 | 1525 | Elements opts = elm->allSelectedOptions(); 1526 | QCOMPARE(opts.size(), 6); 1527 | } 1528 | 1529 | /** 1530 | * void element->selectByIndex(int) 1531 | */ 1532 | void QueleniumTest::selectByIndexCase1() 1533 | { 1534 | driver->get(m_testUrl); 1535 | 1536 | Select* elm = new Select(driver->findElement(By::id("selectIsMultiCase1"))); 1537 | elm->selectByIndex(5); 1538 | 1539 | WebElement* opt = elm->firstSelectedOption(); 1540 | QCOMPARE(opt->attribute("value"), QString("subitem3")); 1541 | } 1542 | 1543 | /** 1544 | * void element->selectByIndex(int) 1545 | */ 1546 | void QueleniumTest::selectByIndexCase2() 1547 | { 1548 | driver->get(m_testUrl); 1549 | 1550 | Select* elm = new Select(driver->findElement(By::id("selectIsMultiCase2"))); 1551 | elm->selectByIndex(0); 1552 | elm->selectByIndex(3); 1553 | 1554 | Elements opts = elm->allSelectedOptions(); 1555 | QCOMPARE(opts.size(), 6); 1556 | } 1557 | 1558 | /** 1559 | * void element->selectByValue(QString) 1560 | */ 1561 | void QueleniumTest::selectByValueCase1() 1562 | { 1563 | driver->get(m_testUrl); 1564 | 1565 | Select* elm = new Select(driver->findElement(By::id("selectIsMultiCase1"))); 1566 | elm->selectByValue("subitem1"); 1567 | 1568 | WebElement* opt = elm->firstSelectedOption(); 1569 | QCOMPARE(opt->attribute("value"), QString("subitem1")); 1570 | } 1571 | 1572 | /** 1573 | * void element->selectByValue(QString) 1574 | */ 1575 | void QueleniumTest::selectByValueCase2() 1576 | { 1577 | driver->get(m_testUrl); 1578 | 1579 | Select* elm = new Select(driver->findElement(By::id("selectIsMultiCase2"))); 1580 | elm->selectByValue("subitem1"); 1581 | elm->selectByValue("subitem3"); 1582 | 1583 | Elements opts = elm->allSelectedOptions(); 1584 | QCOMPARE(opts.size(), 5); 1585 | } 1586 | 1587 | /** 1588 | * void element->deselectAll() 1589 | */ 1590 | void QueleniumTest::selectDeselectAllCase1() 1591 | { 1592 | driver->get(m_testUrl); 1593 | 1594 | Select* elm = new Select(driver->findElement(By::id("selectIsMultiCase2"))); 1595 | elm->deselectAll(); 1596 | 1597 | Elements opts = elm->allSelectedOptions(); 1598 | QCOMPARE(opts.size(), 0); 1599 | } 1600 | 1601 | /** 1602 | * void element->deselectByValue(QString) 1603 | */ 1604 | void QueleniumTest::selectDeselectByValueCase1() 1605 | { 1606 | driver->get(m_testUrl); 1607 | 1608 | Select* elm = new Select(driver->findElement(By::id("selectIsMultiCase2"))); 1609 | elm->deselectByValue("subitem4"); 1610 | elm->deselectByValue("item3"); 1611 | 1612 | Elements opts = elm->allSelectedOptions(); 1613 | QCOMPARE(opts.size(), 2); 1614 | } 1615 | 1616 | /** 1617 | * void element->deselectByValue(2) 1618 | */ 1619 | void QueleniumTest::selectDeselectByIndexCase1() 1620 | { 1621 | driver->get(m_testUrl); 1622 | 1623 | Select* elm = new Select(driver->findElement(By::id("selectIsMultiCase2"))); 1624 | elm->deselectByIndex(6); 1625 | elm->deselectByIndex(2); 1626 | 1627 | Elements opts = elm->allSelectedOptions(); 1628 | QCOMPARE(opts.size(), 2); 1629 | } 1630 | 1631 | /** 1632 | * void element->deselectByVisibleText(QString) 1633 | */ 1634 | void QueleniumTest::selectDeselectByVisibleTextCase1() 1635 | { 1636 | driver->get(m_testUrl); 1637 | 1638 | Select* elm = new Select(driver->findElement(By::id("selectIsMultiCase2"))); 1639 | elm->deselectByVisibleText("SUBITEM3"); 1640 | elm->deselectByVisibleText("SUBITEM4"); 1641 | 1642 | Elements opts = elm->allSelectedOptions(); 1643 | QCOMPARE(opts.size(), 2); 1644 | } 1645 | 1646 | /******** SELECT EXCEPTIONS TESTS **********************************************************************************/ 1647 | /** 1648 | * WebDriverException 1649 | * 1650 | * Element is not select 1651 | */ 1652 | void QueleniumTest::selectWebDriverExceptionCase1() 1653 | { 1654 | driver->get(m_testUrl); 1655 | 1656 | try { 1657 | 1658 | new Select(driver->findElement(By::id("findElementCase1"))); 1659 | 1660 | } catch(WebDriverException* e) { 1661 | QCOMPARE(e->message(), QString("Element is not select")); 1662 | } catch( ... ) { 1663 | QFAIL(QString("Not WebDriverException").toUtf8()); 1664 | } 1665 | } 1666 | 1667 | /** 1668 | * NoSuchElementException 1669 | * 1670 | * WebElement* element->firstSelectedOption() 1671 | */ 1672 | void QueleniumTest::selectFirstSelectedOptionNoSuchElementCase1() 1673 | { 1674 | driver->get(m_testUrl); 1675 | 1676 | Select* elm = new Select(driver->findElement(By::id("selectIsMultiCase2"))); 1677 | elm->deselectAll(); 1678 | 1679 | try { 1680 | 1681 | elm->firstSelectedOption(); 1682 | 1683 | } catch(NoSuchElementException* e) { 1684 | QCOMPARE(e->message(), QString("No options are selected")); 1685 | } catch( ... ) { 1686 | QFAIL(QString("Not NoSuchElementException").toUtf8()); 1687 | } 1688 | } 1689 | 1690 | /** 1691 | * NoSuchElementException 1692 | * 1693 | * element->selectByVisibleText(QString) 1694 | */ 1695 | void QueleniumTest::selectByVisibleTextNoSuchElementCase1() 1696 | { 1697 | driver->get(m_testUrl); 1698 | 1699 | Select* elm = new Select(driver->findElement(By::id("selectIsMultiCase1"))); 1700 | 1701 | try { 1702 | 1703 | elm->selectByVisibleText("BUGAGA"); 1704 | 1705 | } catch(NoSuchElementException* e) { 1706 | QCOMPARE(e->message(), QString("Cannot locate option with text: BUGAGA")); 1707 | } catch( ... ) { 1708 | QFAIL(QString("Not NoSuchElementException").toUtf8()); 1709 | } 1710 | } 1711 | 1712 | /** 1713 | * NoSuchElementException 1714 | * 1715 | * void element->selectByVisibleText(QString) 1716 | */ 1717 | void QueleniumTest::selectByVisibleTextNoSuchElementCase2() 1718 | { 1719 | driver->get(m_testUrl); 1720 | 1721 | Select* elm = new Select(driver->findElement(By::id("selectIsMultiCase2"))); 1722 | 1723 | try { 1724 | 1725 | elm->selectByVisibleText("ITEM1"); 1726 | elm->selectByVisibleText("BUGAGA"); 1727 | elm->selectByVisibleText("ITEM111"); 1728 | 1729 | } catch(NoSuchElementException* e) { 1730 | QCOMPARE(e->message(), QString("Cannot locate option with text: BUGAGA")); 1731 | } catch( ... ) { 1732 | QFAIL(QString("Not NoSuchElementException").toUtf8()); 1733 | } 1734 | } 1735 | 1736 | /** 1737 | * NoSuchElementException 1738 | * 1739 | * void element->selectByIndex(int) 1740 | */ 1741 | void QueleniumTest::selectByIndexNoSuchElementCase1() 1742 | { 1743 | driver->get(m_testUrl); 1744 | 1745 | Select* elm = new Select(driver->findElement(By::id("selectIsMultiCase1"))); 1746 | 1747 | try { 1748 | 1749 | elm->selectByIndex(100); 1750 | 1751 | } catch(NoSuchElementException* e) { 1752 | QCOMPARE(e->message(), QString("Cannot locate option with index: 100")); 1753 | } catch( ... ) { 1754 | QFAIL(QString("Not NoSuchElementException").toUtf8()); 1755 | } 1756 | } 1757 | 1758 | /** 1759 | * NoSuchElementException 1760 | * 1761 | * void element->selectByIndex(int) 1762 | */ 1763 | void QueleniumTest::selectByIndexNoSuchElementCase2() 1764 | { 1765 | driver->get(m_testUrl); 1766 | 1767 | Select* elm = new Select(driver->findElement(By::id("selectIsMultiCase2"))); 1768 | 1769 | try { 1770 | 1771 | elm->selectByIndex(3); 1772 | elm->selectByIndex(100); 1773 | elm->selectByIndex(4); 1774 | 1775 | } catch(NoSuchElementException* e) { 1776 | QCOMPARE(e->message(), QString("Cannot locate option with index: 100")); 1777 | } catch( ... ) { 1778 | QFAIL(QString("Not NoSuchElementException").toUtf8()); 1779 | } 1780 | } 1781 | 1782 | /** 1783 | * NoSuchElementException 1784 | * 1785 | * void element->selectByValue(QString) 1786 | */ 1787 | void QueleniumTest::selectByValueNoSuchElementCase1() 1788 | { 1789 | driver->get(m_testUrl); 1790 | 1791 | Select* elm = new Select(driver->findElement(By::id("selectIsMultiCase1"))); 1792 | 1793 | try { 1794 | 1795 | elm->selectByValue("BUGAGA"); 1796 | 1797 | } catch(NoSuchElementException* e) { 1798 | QCOMPARE(e->message(), QString("Cannot locate option with value: BUGAGA")); 1799 | } catch( ... ) { 1800 | QFAIL(QString("Not NoSuchElementException").toUtf8()); 1801 | } 1802 | } 1803 | 1804 | /** 1805 | * NoSuchElementException 1806 | * 1807 | * void element->selectByValue(QString) 1808 | */ 1809 | void QueleniumTest::selectByValueNoSuchElementCase2() 1810 | { 1811 | driver->get(m_testUrl); 1812 | 1813 | Select* elm = new Select(driver->findElement(By::id("selectIsMultiCase2"))); 1814 | 1815 | try { 1816 | 1817 | elm->selectByValue("subitem2"); 1818 | elm->selectByValue("BUGAGA"); 1819 | elm->selectByValue("subitem1"); 1820 | 1821 | } catch(NoSuchElementException* e) { 1822 | QCOMPARE(e->message(), QString("Cannot locate option with value: BUGAGA")); 1823 | } catch( ... ) { 1824 | QFAIL(QString("Not NoSuchElementException").toUtf8()); 1825 | } 1826 | } 1827 | 1828 | /** 1829 | * WebDriverException 1830 | * 1831 | * void element->deselectAll() 1832 | */ 1833 | void QueleniumTest::selectDeselectAllWebDriverExceptionCase1() 1834 | { 1835 | driver->get(m_testUrl); 1836 | 1837 | Select* elm = new Select(driver->findElement(By::id("selectIsMultiCase1"))); 1838 | 1839 | try { 1840 | 1841 | elm->deselectAll(); 1842 | 1843 | } catch(WebDriverException* e) { 1844 | QCOMPARE(e->message(), QString("You may only deselect all options of a multi-select")); 1845 | } catch( ... ) { 1846 | QFAIL(QString("Not WebDriverException").toUtf8()); 1847 | } 1848 | } 1849 | 1850 | /** 1851 | * WebDriverException 1852 | * 1853 | * void element->deselectByValue(QString) 1854 | */ 1855 | void QueleniumTest::selectDeselectByValueWebDriverExceptionCase1() 1856 | { 1857 | driver->get(m_testUrl); 1858 | 1859 | Select* elm = new Select(driver->findElement(By::id("selectIsMultiCase1"))); 1860 | 1861 | try { 1862 | 1863 | elm->deselectByValue("item3"); 1864 | 1865 | } catch(WebDriverException* e) { 1866 | QCOMPARE(e->message(), QString("You may only deselect option of a multi-select")); 1867 | } catch( ... ) { 1868 | QFAIL(QString("Not WebDriverException").toUtf8()); 1869 | } 1870 | } 1871 | 1872 | /** 1873 | * WebDriverException 1874 | * 1875 | * void element->deselectByIndex(int) 1876 | */ 1877 | void QueleniumTest::selectDeselectByIndexWebDriverExceptionCase1() 1878 | { 1879 | driver->get(m_testUrl); 1880 | 1881 | Select* elm = new Select(driver->findElement(By::id("selectIsMultiCase1"))); 1882 | 1883 | try { 1884 | 1885 | elm->deselectByIndex(2); 1886 | 1887 | } catch(WebDriverException* e) { 1888 | QCOMPARE(e->message(), QString("You may only deselect option of a multi-select")); 1889 | } catch( ... ) { 1890 | QFAIL(QString("Not WebDriverException").toUtf8()); 1891 | } 1892 | } 1893 | 1894 | /** 1895 | * WebDriverException 1896 | * 1897 | * void element->deselectByVisibleText(QString) 1898 | */ 1899 | void QueleniumTest::selectDeselectByVisibleTextWebDriverExceptionCase1() 1900 | { 1901 | driver->get(m_testUrl); 1902 | 1903 | Select* elm = new Select(driver->findElement(By::id("selectIsMultiCase1"))); 1904 | 1905 | try { 1906 | 1907 | elm->deselectByVisibleText("ITEM3"); 1908 | 1909 | } catch(WebDriverException* e) { 1910 | QCOMPARE(e->message(), QString("You may only deselect option of a multi-select")); 1911 | } catch( ... ) { 1912 | QFAIL(QString("Not WebDriverException").toUtf8()); 1913 | } 1914 | } 1915 | 1916 | /******** ALERT TESTS **********************************************************************************/ 1917 | /** 1918 | * void alert->dismiss() 1919 | */ 1920 | void QueleniumTest::alertDismissCase1() 1921 | { 1922 | driver->get(m_testUrl + "/alert/alert.html"); 1923 | 1924 | WebElement* btn = driver->findElement(By::id("alert_confirm")); 1925 | btn->click(); 1926 | 1927 | Alert* alert = driver->switchTo()->alert(); 1928 | alert->dismiss(); 1929 | 1930 | WebElement* result = driver->findElement(By::id("result")); 1931 | QCOMPARE(result->text(), QString("Dismiss")); 1932 | } 1933 | 1934 | /** 1935 | * void alert->dismiss() 1936 | */ 1937 | void QueleniumTest::alertDismissCase2() 1938 | { 1939 | driver->get(m_testUrl + "/alert/alert.html"); 1940 | 1941 | WebElement* btn = driver->findElement(By::id("alert_prompt")); 1942 | btn->click(); 1943 | 1944 | Alert* alert = driver->switchTo()->alert(); 1945 | alert->dismiss(); 1946 | 1947 | WebElement* result = driver->findElement(By::id("result")); 1948 | QCOMPARE(result->text(), QString("Dismiss Prompt")); 1949 | } 1950 | 1951 | /** 1952 | * void alert->accept() 1953 | */ 1954 | void QueleniumTest::alertAcceptCase1() 1955 | { 1956 | driver->get(m_testUrl + "/alert/alert.html"); 1957 | 1958 | WebElement* btn = driver->findElement(By::id("alert_confirm")); 1959 | btn->click(); 1960 | 1961 | Alert* alert = driver->switchTo()->alert(); 1962 | alert->accept(); 1963 | 1964 | WebElement* result = driver->findElement(By::id("result")); 1965 | QCOMPARE(result->text(), QString("Accept")); 1966 | } 1967 | 1968 | /** 1969 | * void alert->accept() 1970 | */ 1971 | void QueleniumTest::alertAcceptCase2() 1972 | { 1973 | driver->get(m_testUrl + "/alert/alert.html"); 1974 | 1975 | WebElement* btn = driver->findElement(By::id("alert_prompt")); 1976 | btn->click(); 1977 | 1978 | Alert* alert = driver->switchTo()->alert(); 1979 | alert->accept(); 1980 | 1981 | WebElement* result = driver->findElement(By::id("result")); 1982 | QCOMPARE(result->text(), QString("Accept Prompt")); 1983 | } 1984 | 1985 | /** 1986 | * QString alert->text() 1987 | */ 1988 | void QueleniumTest::alertTextCase1() 1989 | { 1990 | driver->get(m_testUrl + "/alert/alert.html"); 1991 | 1992 | WebElement* btn = driver->findElement(By::id("alert_confirm")); 1993 | btn->click(); 1994 | 1995 | Alert* alert = driver->switchTo()->alert(); 1996 | QString text = alert->text(); 1997 | alert->accept(); 1998 | 1999 | QCOMPARE(text, QString("Alert Confirm")); 2000 | } 2001 | 2002 | /** 2003 | * QString alert->text() 2004 | */ 2005 | void QueleniumTest::alertTextCase2() 2006 | { 2007 | driver->get(m_testUrl + "/alert/alert.html"); 2008 | 2009 | WebElement* btn = driver->findElement(By::id("alert_prompt")); 2010 | btn->click(); 2011 | 2012 | Alert* alert = driver->switchTo()->alert(); 2013 | QString text = alert->text(); 2014 | alert->accept(); 2015 | 2016 | QCOMPARE(text, QString("Alert Prompt")); 2017 | } 2018 | 2019 | /** 2020 | * void alert->sendKeys(QString) 2021 | */ 2022 | void QueleniumTest::alertSendKeysCase() 2023 | { 2024 | driver->get(m_testUrl + "/alert/alert.html"); 2025 | 2026 | WebElement* btn = driver->findElement(By::id("alert_prompt_text")); 2027 | btn->click(); 2028 | 2029 | Alert* alert = driver->switchTo()->alert(); 2030 | alert->sendKeys("Test Prompt"); 2031 | alert->accept(); 2032 | 2033 | WebElement* result = driver->findElement(By::id("result")); 2034 | QCOMPARE(result->text(), QString("Test Prompt")); 2035 | } 2036 | 2037 | /******** ALERT EXCEPTIONS TESTS **********************************************************************************/ 2038 | /** 2039 | * NoAlertOpenErrorException 2040 | * 2041 | * void alert->dismiss() 2042 | */ 2043 | void QueleniumTest::alertDismissNoAlertPresentCase1() 2044 | { 2045 | try { 2046 | 2047 | driver->get(m_testUrl + "/alert/alert.html"); 2048 | 2049 | Alert* alert = driver->switchTo()->alert(); 2050 | alert->dismiss(); 2051 | 2052 | } catch(NoAlertOpenErrorException* e) { 2053 | QVERIFY(e->code() != 0); 2054 | QVERIFY(!e->message().isEmpty()); 2055 | } catch( ... ) { 2056 | QFAIL(QString("Not NoAlertOpenErrorException").toUtf8()); 2057 | } 2058 | } 2059 | 2060 | /** 2061 | * NoAlertOpenErrorException 2062 | * 2063 | * void alert->accept() 2064 | */ 2065 | void QueleniumTest::alertAcceptNoAlertPresentCase1() 2066 | { 2067 | try { 2068 | 2069 | driver->get(m_testUrl + "/alert/alert.html"); 2070 | 2071 | Alert* alert = driver->switchTo()->alert(); 2072 | alert->accept(); 2073 | 2074 | } catch(NoAlertOpenErrorException* e) { 2075 | QVERIFY(e->code() != 0); 2076 | QVERIFY(!e->message().isEmpty()); 2077 | } catch( ... ) { 2078 | QFAIL(QString("Not NoAlertOpenErrorException").toUtf8()); 2079 | } 2080 | } 2081 | 2082 | /** 2083 | * NoAlertOpenErrorException 2084 | * 2085 | * QString alert->text() 2086 | */ 2087 | void QueleniumTest::alertTextNoAlertPresentCase1() 2088 | { 2089 | try { 2090 | 2091 | driver->get(m_testUrl + "/alert/alert.html"); 2092 | 2093 | Alert* alert = driver->switchTo()->alert(); 2094 | alert->text(); 2095 | 2096 | } catch(NoAlertOpenErrorException* e) { 2097 | QVERIFY(e->code() != 0); 2098 | QVERIFY(!e->message().isEmpty()); 2099 | } catch( ... ) { 2100 | QFAIL(QString("Not NoAlertOpenErrorException").toUtf8()); 2101 | } 2102 | } 2103 | 2104 | /** 2105 | * NoAlertOpenErrorException 2106 | * 2107 | * void alert->sendKeys(QString) 2108 | */ 2109 | void QueleniumTest::alertSendKeysNoAlertPresentCase1() 2110 | { 2111 | try { 2112 | 2113 | driver->get(m_testUrl + "/alert/alert.html"); 2114 | 2115 | Alert* alert = driver->switchTo()->alert(); 2116 | alert->sendKeys(""); 2117 | 2118 | } catch(NoAlertOpenErrorException* e) { 2119 | QVERIFY(e->code() != 0); 2120 | QVERIFY(!e->message().isEmpty()); 2121 | } catch( ... ) { 2122 | QFAIL(QString("Not NoAlertOpenErrorException").toUtf8()); 2123 | } 2124 | } 2125 | 2126 | /** 2127 | * ElementNotVisibleException 2128 | * 2129 | * void alert->sendKeys(QString) 2130 | */ 2131 | void QueleniumTest::alertSendKeysElementNotVisibleExceptionCase1() 2132 | { 2133 | try { 2134 | 2135 | driver->get(m_testUrl + "/alert/alert.html"); 2136 | 2137 | WebElement* btn = driver->findElement(By::id("alert_confirm")); 2138 | btn->click(); 2139 | 2140 | Alert* alert = driver->switchTo()->alert(); 2141 | alert->sendKeys("Test Prompt"); 2142 | 2143 | 2144 | } catch(ElementNotVisibleException* e) { 2145 | QVERIFY(e->code() != 0); 2146 | QVERIFY(!e->message().isEmpty()); 2147 | } catch( ... ) { 2148 | QFAIL(QString("Not ElementNotVisibleException").toUtf8()); 2149 | } 2150 | } 2151 | 2152 | /******** SERVER TESTS **********************************************************************************/ 2153 | void QueleniumTest::serverStatusCase() 2154 | { 2155 | Status* status = driver->server()->status(); 2156 | 2157 | //OS Linux x64 3.16.0-45-generic 2158 | QCOMPARE(status->os()->arch(), QString("amd64")); 2159 | QCOMPARE(status->os()->name(), QString("Linux")); 2160 | QCOMPARE(status->os()->version(), QString("3.16.0-45-generic")); 2161 | 2162 | //Selenium Server Standalone 2163 | QCOMPARE(status->build()->version(), QString("2.46.0")); 2164 | 2165 | //Java 2166 | if(status->java()) { 2167 | QCOMPARE(status->java()->version(), QString("1.8.0_45")); 2168 | } 2169 | } 2170 | 2171 | void QueleniumTest::serverSessionsCase() 2172 | { 2173 | Proxy *proxy = new Proxy(Proxy::DIRECT); 2174 | DesiredCapabilities *cap = new DesiredCapabilities(Browser::FIREFOX); 2175 | cap->setProxy(proxy); 2176 | 2177 | int count = 4; 2178 | QList list; 2179 | 2180 | for(int i = 0; i < count; i++) { 2181 | list.push_back(new WebDriver(m_host, m_port, cap, m_testUrl)); 2182 | } 2183 | 2184 | QList listSession = driver->server()->sessions(); 2185 | 2186 | for(int i = 0; i < count; i++) { 2187 | list.at(i)->quit(); 2188 | } 2189 | 2190 | QCOMPARE(listSession.size(), 5); 2191 | 2192 | for(int i = 0; i < listSession.size(); i++) { 2193 | Session* s = listSession.at(i); 2194 | 2195 | QVERIFY(!s->id().isEmpty()); 2196 | 2197 | DesiredCapabilities* c = s->capabilities(); 2198 | 2199 | QVERIFY(c->isTakesScreenshot()); 2200 | QVERIFY(c->isJavascriptEnabled()); 2201 | QVERIFY(!c->isRotatable()); 2202 | QVERIFY(c->isLocationContextEnabled()); 2203 | QCOMPARE(c->browser(), Browser::FIREFOX); 2204 | QCOMPARE(c->platform(), Platform::LINUX); 2205 | QCOMPARE(c->version(), QString("39.0")); 2206 | } 2207 | 2208 | } 2209 | 2210 | QTEST_MAIN(QueleniumTest) 2211 | --------------------------------------------------------------------------------