-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexecutor.sh
130 lines (86 loc) · 5.1 KB
/
executor.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#replace jenkins with the username configured to connect with jenkins on the linux VM.
#take parameters from jenkins,8th and 9th argument are testlink specific and can be deleted here and from if condition if not using testlink.
NumberOfNodes=$1
DockerPrefix=$2
ymlName=$3
gitRepo=$4
gitBranch=$5
drivertype=$6
environment=$7
projectname=$8
planname=$9
#if block to verify that arguments passed are not null, delete drivertype if not using it inside framework.Delete projectname and planname if not using testlink
if [ -z "$NumberOfNodes" ] || [ -z "$DockerPrefix" ] || [ -z "$ymlName" ] || [ -z "$gitRepo" ] || [ -z "$gitBranch" ] || [ -z "$drivertype" ] || [ -z "$environment" ] || [ -z "$projectname" ] || [ -z "$planname" ]
then
echo "ERROR :: ARGUMENT MISSING"
echo "Following Arguments are required : "
echo " 1) Number of Nodes to Generate(Node scale)"
echo " 2) Docker prefix(Selenium Grid Cluster naming)"
echo " 3) docker-compose.yml name(See Binding Field for more information)"
echo " 4) git repo url (Remove 'http://' from it)"
echo " 5) git branch name"
echo " 6) Test driver type"
echo " 7) Test Environment"
echo " 8) Test Project Name"
echo " 9) Test Plan Name"
exit 1
fi
#functioning block, to verify that we have free ram to create the containers on the server.
#echo "Arguments mapped.....Starting script................"
#removing prevoius junk reports
#replace jenkins with the username configured to connect with jenkins on the linux VM.
rm -rf /home/jenkins/results/$projectname/*
#Hard check on RAM sufficiency , will be deleted later after implementation of kubernetes.
NodesMemory=750
FreeMemory="$(free -m |awk '/Mem:/{print $4}')"
echo "**************Free RAM on this server is "$FreeMemory "****************************"
echo "**************Number of nodes that can be generated on this server are : "$(( $FreeMemory / $NodesMemory ))"*****************************"
echo "**************Your Execution would require approximately "$(( $(($NumberOfNodes+1)) * $NodesMemory ))" MB of RAM resources *********************************"
if [ $(($FreeMemory / $NodesMemory)) -lt $(( $NumberOfNodes )) ]
then
echo "***********Memory not available, please free memory resources**********"
exit 1
else
echo "*****************Memory Available, creating Hub and Node containers*****************"
#echo "docker-compose -f $ymlName.yml -p $DockerPrefix up -d"
if [ "$drivertype" = "dockerff" ]
then
docker-compose -f ./firefoxFile/$ymlName.yml -p $DockerPrefix up -d
docker-compose -f ./firefoxFile/$ymlName.yml -p $DockerPrefix scale node=$NumberOfNodes
echo "*************Grid Cluster is Up**********************"
fi
if [ "$drivertype" = "dockerchrome" ]
then
docker-compose -f ./chromeFile/$ymlName.yml -p $DockerPrefix up -d
docker-compose -f ./chromeFile/$ymlName.yml -p $DockerPrefix scale node=$NumberOfNodes
echo "************Grid Cluster is Up********************"
fi
fi
#returning grid cluster name, IP and port number(replace 0.0.0.0 with your linux vm IP)
echo "***********Grid Cluster hub name is : "$DockerPrefix"_selenium-hub_1**************"
echo "***********Grid IP is :- http://0.0.0.0:"$(((docker ps|grep $DockerPrefix'_selenium-hub_1') | awk '{print $10}')|grep -Po '0.0.0.0:\K[^-]*')"/" " ************************************"
#Download Git repo , replace gitusername and gitpassword with your username and password
echo "Downloading Git Repo"
docker exec $DockerPrefix'_selenium-hub_1' /bin/bash -c 'sudo chmod 777 -R /home/seluser/.m2/ && cd /home/seluser/AutomationProjects && git clone http://gitusername:gitpassword@'$gitRepo' -b '$gitBranch''
#getting the folder name of the project
foldername=$(docker exec $DockerPrefix'_selenium-hub_1' /bin/bash -c 'cd /home/seluser/AutomationProjects && ls|awk 'NR==1 {print $1}' ')
#echo "folder name is "$foldername
echo "Number of Nodes" $NumberOfNodes
echo "plan name is " $planname
echo "project name is" $projectname
echo "environment is " $environment
echo "drivertype is " $drivertype
echo "urlstr is "$urlstr
#execute mvn test command , you can type your custom command here.
echo "mvn clean test -Ddrivertype="$drivertype" -Denvironment="$environment" -Dprojectname="$projectname" -Dplanname="$planname" -Durlstr="$urlstr" -Djava.awt.headless=true -Dencoding=cp1252 -e"
#go to the project folder and execute the command
docker exec $DockerPrefix'_selenium-hub_1' /bin/bash -c 'cd /home/seluser/AutomationProjects/'$foldername'&&pwd&& export nodecount='$NumberOfNodes' && mvn clean test -Ddrivertype='$drivertype' -Denvironment='$environment' -Dprojectname='$projectname' -Dplanname='$planname' -Durlstr='$urlstr' -Djava.awt.headless=true -Dencoding=cp1252 -e'
#get the reports from containers to the local Linux server/Linux VM
#replace jenkins with the username configured to connect with jenkins on the linux VM.
cd /home/jenkins/results
mkdir -p $projectname
cd $projectname
docker cp $DockerPrefix'_selenium-hub_1':/home/seluser/AutomationProjects/$foldername/target/surefire-reports/testng-results.xml .
docker cp $DockerPrefix'_selenium-hub_1':/home/seluser/AutomationProjects/$foldername/finalReport/ .
#ending the script
#echo "ending script.................."