Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var useSearch = function(searchText)
- {
- var tmp1 = element(by.model('$root.searchQuery'));
- tmp1.sendKeys(searchText);
- //tmp1.sendKeys(protractor.Key.ENTER);
- }
- var uploadFile = function()
- {
- var path = require('path');
- var fileToUpload = 'C:/Users/Dame/Desktop/123.png';
- var absolutePath = path.resolve(fileToUpload);
- var input = element(by.css('input[type="file"]'));
- input.sendKeys(absolutePath);
- element(by.css('[ng-click="crop()"]')).click();
- }
- mainPageItem = function(index)
- {
- element.all(by.repeater('slide in slidesTitle() track by $index')).get(index).click().then(function(){
- if(index === 0)
- console.log('\n---recipes---');
- if(index === 1)
- console.log('\n---collections---');
- if(index === 2)
- console.log('\n---profiles---');
- });
- }
- ////////////////////////////////////////////////////////////////////////////////
- var site_functions = function()
- {
- this.getSite = function()
- {
- browser.get('https://www.hoorray-test-platform.com/');
- expect(browser.getTitle()).toEqual('MyGreatRecipes - CREATE YOUR #1 RECIPE COLLECTION!');
- }
- this.logIn = function(uName,pass)
- {
- element(by.css('[ng-click="showLogIn($event)"]')).click();
- element.all(by.repeater('item in moreMenu')).get(0).click();
- $('#email_field').click().sendKeys(uName);
- $('#password_field').click().sendKeys(pass);
- element(by.buttonText('LOG IN')).click();
- browser.waitForAngular();
- browser.driver.isElementPresent(by.css('[ng-click="navigateShoppingList($event)"]')).then(function(result)
- {
- if(result){
- console.log('\n---Logged in!---');
- }
- else{
- console.log('Didnt log in exiting');
- var tmp = new site_functions();
- tmp.takeShot();
- }
- });
- }
- this.useSearch = function(searchText)
- {
- useSearch(searchText);
- }
- this.mainPageItem = function(index)
- {
- mainPageItem(index);
- }
- this.openRecipe = function(index)
- {
- element.all(by.repeater('recipe in group track by recipe.indexKey')).get(index).click().then(function(){
- console.log('Recipe opened!')
- });
- }
- this.browseRecipe = function()
- {
- // element(by.css('[ng-click="onLikeTap()"]')).click()
- }
- this.openCollection = function(index)
- {
- element.all(by.repeater('collection in group track by collection.indexKey')).get(index).click().then(function(){
- console.log('Collection opened!')
- });
- }
- this.openUser = function(index)
- {
- element.all(by.repeater('user in people track by user.indexKey')).get(index).click().then(function(){
- console.log('User opened!')
- });
- }
- this.getNotifications = function()
- {
- element(by.css('[ng-click="navigateNotifications($event)"]')).click();
- }
- this.goToProfile = function()
- {
- element(by.css('[ng-click="showProfileActions($event)"]')).click();
- element.all(by.repeater('item in moreMenu')).get(0).click();
- element(by.css('[ng-click="editProfile($event) && $event.stopPropagation()"]')).isDisplayed().then(function(){
- console.log('\n---profile---');
- });
- }
- this.browseProfile = function(index)
- {
- element.all(by.cssContainingText('.row','Collections')).click();
- }
- this.getMainPageAndRefresh = function()
- {
- browser.get('https://www.hoorray-test-platform.com');
- browser.refresh();
- }
- this.goToTimeline = function()
- {
- element(by.css('[ng-click="goTimeline()"]')).click();
- element.all(by.repeater('item in timeline track by item.indexKey')).get(0).isDisplayed().then(function(){
- console.log('\n---timeline---');
- });
- }
- this.createPostTimeline = function()
- {
- element(by.css('[ng-click="createPost()"]')).click();
- }
- this.openLegal = function(index)
- {
- element(by.css('[ng-click="showMore($event)"]')).click();
- if(index === 2)
- {
- element.all(by.repeater('item in moreMenu')).get(index).click().then(function(){
- element(by.css('[ng-click="isMobile ? back() : close()"]')).click();
- });
- }
- else
- element.all(by.repeater('item in moreMenu')).get(index).click();
- }
- this.createPost = function(recipeName)
- {
- element(by.css('#t_createButton')).click();
- browser.sleep(1000);
- $('#t_createPost').click();
- uploadFile();
- element(by.model('post.text')).sendKeys(recipeName);
- element(by.css('[ng-click="action()"]')).click().then(function(){
- browser.waitForAngular().then(function(){
- console.log('\nPost created!');
- });
- expect($('#t_createButton').isDisplayed()).toBe(true);
- });
- }
- this.createRecipe = function(name,description,step,numStep,ingName,numIngr,addToCollections,share)
- {
- element(by.css('#t_createButton')).click();
- browser.sleep(1000);
- element(by.css('#t_createRecipe')).click();
- uploadFile();
- element(by.model('info.title')).sendKeys(name);
- element(by.model('info.description')).sendKeys(description);
- for(var i = 0; i <= numIngr; i++)
- {
- element.all(by.repeater('ingredient in ingredients')).get(i).element(by.model('ingredient.ingredientOverrideName')).sendKeys(ingName + ' ' + (i+1));
- if(numIngr === i)
- numIngr =0;
- if(numIngr > i)
- element(by.css('[ng-click="addIngredient()"]')).click();
- }
- for(var i = 0; i <= numStep; i++)
- {
- element.all(by.repeater('step in steps')).get(i).element(by.model('step.description')).sendKeys(step + ' ' + (i+1));
- if(numStep === i)
- numStep =0;
- if(numStep > i)
- element(by.css('[ng-click="addStep()"]')).click();
- }
- if(addToCollections){
- $('#t_addToCollections').click();
- element.all(by.repeater('item in collections')).get(1).click();
- element(by.css('[ng-click="closePopup()"]')).click();
- }
- element(by.css('[ng-click="saveRecipeDetails()"]')).click();
- if(!share){
- element(by.css('#t_cancelShare')).click().then(function(){
- console.log('\nRecipe Created')
- });
- }
- if(share)
- {
- element(by.css('[ng-click="action()"]')).click().then(function(){
- console.log('\nRecipe Created');
- });
- }
- }
- this.deleteRecipe = function(recipeName)
- {
- useSearch(recipeName);
- element.all(by.repeater('recipe in group track by recipe.indexKey')).get(0).click();
- element(by.css('[ng-click="deleteRecipe()"]')).click();
- element.all(by.repeater('button in buttons')).get(1).click();
- element.all(by.repeater('button in buttons')).get(0).click();
- browser.refresh();
- //expect(element(by.cssContainingText('#t_recipes','zdameeee')).isPresent()).toBeFalsy();
- }
- this.createCollection = function(title,description)
- {
- element(by.css('#t_createButton')).click();
- browser.sleep(1000);
- element(by.css('#t_createCollection')).click();
- uploadFile();
- element(by.model('model.title')).sendKeys(title);
- element(by.model('model.description')).sendKeys(description);
- element(by.css('[ng-click="save()"]')).click();
- element.all(by.repeater('button in buttons')).get(0).click().then(function(){
- console.log('Collection created');
- });
- }
- this.deleteCollection = function(collectionName)
- {
- mainPageItem(1);
- useSearch(collectionName);
- browser.sleep(5000);
- element.all(by.repeater('collection in group track by collection.indexKey')).get(0).click();
- element(by.css('[ng-click="onRemoveTap()"]')).click();
- element.all(by.repeater('button in buttons')).get(1).click();
- element.all(by.repeater('button in buttons')).get(0).click().then(function(){
- console.log('\nCollection deleted');
- });
- }
- this.logOut = function()
- {
- element(by.css('[ng-click="showProfileActions($event)"]')).click();
- element.all(by.repeater('item in moreMenu')).get(1).click().then(function(){
- browser.driver.isElementPresent(by.css('.home-header-text')).then(function(){
- console.log('\n---Logged out---');
- });
- });
- }
- }
- module.exports = new site_functions();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement