Sunday, 31 May 2015

Python-Conditionals-and-Control-Flow 15/15

If...elif...else

Code:
def the_flying_circus():
    if 12 and 1 + 1 == 2:    # Start coding here!
        print "Yes, I'm greater than 11!"
        # Don't forget to indent
        # the code inside this block!
        return True
    elif 11 < 12:
        print "We are a circus of less than 12 men!"
        # Keep going here.
        return True
    else:
        print "We don't know how many people we are!"
        # You'll want to add the else statement, too!

Thursday, 28 May 2015

Python datetime format

Problem domain:
  1. Create a variable called now and store the result of datetime.now() in it.
  2. Then, print the value of now.
Solve: 

from datetime import datetime

now = datetime.now()
print now

Output: 
current date

Printing current date year and month code

Format 1:
from datetime import datetime
now = datetime.now()
print now
print now.year
print now.month
print now.day


Format 2: from datetime import datetime
now = datetime.now()


print '%s/%s/%s' % (now.month, now.day, now.year, )


Format 3: from datetime import datetime
now = datetime.now()


print '%s:%s:%s' % (now.hour, now.minute, now.second )
Format 4: from datetime import datetime
now = datetime.now()


print '%s/%s/%s %s:%s:%s' % (now.month,now.day,now.year, now.hour, now.minute, now.second )

Saturday, 16 May 2015

Faced the following problem for send keys in selenium webDriver in Java

Java is throwing the following error while working with selenium
the method sendkeys(charsequence ) in the type webelement is not applicable for the arguments

It has a simple solution. Change your compiler compliance level from 1.4 to 1.7.
Follow these steps in your eclipse:
  1. Right click on your java project and select Build Path -> Click on
    Configure Build Path...
  2. In project properties window, Click/select Java Compiler at the left
    panel
  3. At the right panel, change the Compiler compliance level from 1.4 to 1.7
    (Select which is higher version in your eclipse)
  4. Lastly Click on Apply and OK
Now check your code. it will never show the same error.


Wednesday, 13 May 2015

TestNG file execution Along with jar file.

TestNG file execution Along with jar file.
1. Create a main class 1st

package Testcase;

import com.beust.testng.TestNG;

@SuppressWarnings("deprecation")
public class MainOne {

public static void main(String[] args) {
TestNG testng = new TestNG();
         Class[] classes = new Class[]{houpad.class}; //houpad is the class where i included all the                                                                                             //testNG executable testcases.
         testng.setTestClasses(classes);
         testng.run();

}

}

To export a jar file
1. Run the main class then
2. Right click on the package name> Export> Java> rurnnable JAR file> from the launch configuration select the main class created above.> Hit finish.
3. Now double click on the jar file
4. It will show the execution

http://testng.org/doc/documentation-main.html#running-testng-programmatically

Saturday, 9 August 2014

To learn it, you gotta 'do' it

Question 10/11

Write a do/while loop inside the function we've created for you, getToDaChoppa. The function should log a string of your choice to the console. do it now!

var getToDaChoppa = function(){
  // Write your do/while loop here!
  do{
      getToDaChoppa = false;
      console.log ("Please mention all above");
      }while(getToDaChoppa)
};

getToDaChoppa();

Tuesday, 5 August 2014

Tutorial 3/11
== Introduction to while loops ==
A fellow of infinite loops

Solve:
understand = true;

while(understand){
    console.log("I'm learning while loops!");
    //Change the value of 'understand' here!
    understand = false;
}

Tuesday, 15 July 2014

== Search Text for Your Name tutorial 5/7 ==
Okay! Last loopy step: add another for loop, this time inside the body of your if statement (between the if's {}s).
This loop will make sure each character of your name gets pushed to the final array. The if statement says: "If we find the first letter of the name, start the second for loop!" This loop says: "I'm going to add characters to the array until I hit the length of the user's name." So if your name is 11 letters long, your loop should add 11 characters to hits if it ever sees the first letter of myName in text.
For your second for loop, keep the following in mind:
First, you'll want to set your second loop's iterator to start at the first one, so it picks up where that one left off. If your first loop starts with
for(var i = 0; // rest of loop setup
your second should be something like
for(var j = i; // rest of loop setup
Second, think hard about when your loop should stop. Check the Hint if you get stuck!
Finally, in the body of your loop, have your program use the .push() method of hits. Just like strings and arrays have a .length method, arrays have a .push() method that adds the thing between parentheses to the end of the array. For example,
newArray = [];
newArray.push('hello');
newArray[0];   // equals 'hello'
 
Solve:
 
var text = "Hello world Keya how you doing Keya";
            
var myName ="Keya";
var hits = [];
for(var i=0; i<text.length; i++ )
{
    if (text[i]=== 'K')
    {
        for (var j=i; j< i+ myName.length; j++)
        {
            hits.push(text[j]);
            
        }
    }
} 
 
output: 8